pub trait Decoder {
type Result;
type Error: Error;
// Required method
fn decode(&self, bytes: &[u8]) -> Result<Self::Result, Self::Error>;
}Expand description
Represents a way of decoding a payload of an incoming message (which is received as a sequence of bytes) into an arbitrary result type.
It is important to know that both the original bytes (Vec<u8>) and the
decoded Result will be owned by the same
Envelope. Given that Rust doesn’t allow
self-referential structs, we have to keep in mind that the result type may
not contain references to the original bytes.
Also, since the envelope is not easily destructed, only a reference to the decoded payload is exposed.
For cases, where references to the original bytes are needed in the decoded
result, or where the decoded result must be owned by the external logic, the
byte slice may be accessed on the envelope for
manual decoding, and the provided NoopDecoder may be used as a dud.