pub trait Deserializer<T>:
Send
+ Sync
+ 'static {
// Required method
fn deserialize<'a>(
&'a self,
topic: &'a str,
data: &'a [u8],
) -> impl Future<Output = Result<T, Error>> + Send + 'a;
// Provided methods
fn deserialize_with_headers<'a>(
&'a self,
topic: &'a str,
headers: &'a mut RecordHeaders,
data: &'a [u8],
) -> impl Future<Output = Result<T, Error>> + Send + 'a { ... }
fn deserialize_with_headers_bytes<'a>(
&'a self,
topic: &'a str,
headers: &'a mut RecordHeaders,
data: &'a Bytes,
) -> impl Future<Output = Result<T, Error>> + Send + 'a { ... }
fn configure<'a>(
&'a mut self,
configs: &'a HashMap<String, String>,
is_key: bool,
) -> impl Future<Output = Result<(), Error>> + Send + 'a { ... }
fn close(&mut self) -> impl Future<Output = Result<(), Error>> + Send { ... }
}Expand description
An interface for converting bytes to objects.
This interface can be combined with ClusterResourceListener to receive
cluster metadata once it’s available, as well as Monitorable to enable the
deserializer to register metrics. For the latter, the following tags are
automatically added to all metrics registered: config set to either
key.deserializer or value.deserializer, and class set to the
deserializer class name.
§Type Parameters
T- Type to be deserialized into.
§Translation notes
WARNING: combining with ClusterResourceListener or Monitorable has no effect: no client registers either.
Methods return a Send future, which the consumer stores inline: a deserializer
awaiting a large operation only on a cache miss should Box::pin it alone.
A poll() cancelled mid-record deserializes that record again on the next
poll().
Required Methods§
Sourcefn deserialize<'a>(
&'a self,
topic: &'a str,
data: &'a [u8],
) -> impl Future<Output = Result<T, Error>> + Send + 'a
fn deserialize<'a>( &'a self, topic: &'a str, data: &'a [u8], ) -> impl Future<Output = Result<T, Error>> + Send + 'a
Deserialize a record value from a byte array into a value or object.
§Arguments
topic- topic associated with the datadata- serialized bytes
§Returns
The deserialized typed object.
§Errors
Whatever error the deserializer reports; the consumer returns it from
poll.
§Translation notes
The consumer skips the call for a null key or value, so data and the
result are never None.
Provided Methods§
Sourcefn deserialize_with_headers<'a>(
&'a self,
topic: &'a str,
headers: &'a mut RecordHeaders,
data: &'a [u8],
) -> impl Future<Output = Result<T, Error>> + Send + 'a
fn deserialize_with_headers<'a>( &'a self, topic: &'a str, headers: &'a mut RecordHeaders, data: &'a [u8], ) -> impl Future<Output = Result<T, Error>> + Send + 'a
Deserialize a record value from a byte array into a value or object.
Note that the passed in headers may be empty. The implementation is allowed to modify the passed in headers, as a side effect of deserialization. It is considered best practice to not delete or modify existing headers, but rather only add new ones.
§Arguments
topic- topic associated with the dataheaders- headers associated with the recorddata- serialized bytes
§Returns
The deserialized typed object.
§Errors
As deserialize.
§Translation notes
The default implementation ignores the headers and delegates to
deserialize. The consumer skips the call for a
null key or value.
Sourcefn deserialize_with_headers_bytes<'a>(
&'a self,
topic: &'a str,
headers: &'a mut RecordHeaders,
data: &'a Bytes,
) -> impl Future<Output = Result<T, Error>> + Send + 'a
fn deserialize_with_headers_bytes<'a>( &'a self, topic: &'a str, headers: &'a mut RecordHeaders, data: &'a Bytes, ) -> impl Future<Output = Result<T, Error>> + Send + 'a
Deserialize a record value from a [Bytes] buffer into a value or object.
If this method is overridden, the implementation cannot make any assumptions about the passed in buffer.
Note that the passed in headers may be empty. The implementation is allowed to modify the passed in headers, as a side effect of deserialization. It is considered best practice to not delete or modify existing headers, but rather only add new ones.
§Arguments
topic- topic associated with the dataheaders- headers associated with the recorddata- serialized bytes
§Returns
The deserialized typed object.
§Errors
As deserialize.
§Translation notes
The consumer calls this overload. data is a refcounted slice of the fetched
bytes, so a deserializer may keep it without copying. The default delegates to
deserialize_with_headers with
&data[..], copying nothing. The consumer skips the call for a null key or
value.
Sourcefn configure<'a>(
&'a mut self,
configs: &'a HashMap<String, String>,
is_key: bool,
) -> impl Future<Output = Result<(), Error>> + Send + 'a
fn configure<'a>( &'a mut self, configs: &'a HashMap<String, String>, is_key: bool, ) -> impl Future<Output = Result<(), Error>> + Send + 'a
Sourcefn close(&mut self) -> impl Future<Output = Result<(), Error>> + Send
fn close(&mut self) -> impl Future<Output = Result<(), Error>> + Send
Close this deserializer.
This method must be idempotent as it may be called multiple times.
§Errors
Whatever error the deserializer reports; the consumer still closes the other deserializer, then returns it as the source of its own.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.