pub trait Protocol: 'static {
type Frame: Framing;
type Sizer: ProtocolWriter<Final = usize>;
type Serializer: ProtocolWriter<Final = <<Self::Frame as Framing>::EncBuf as BufMutExt>::Final>;
type Deserializer: ProtocolReader;
const PROTOCOL_ID: ProtocolID;
// Required methods
fn serializer<SZ, SER>(
sz: SZ,
ser: SER,
) -> <Self::Serializer as ProtocolWriter>::Final
where SZ: FnOnce(&mut Self::Sizer),
SER: FnOnce(&mut Self::Serializer);
fn deserializer(buf: <Self::Frame as Framing>::DecBuf) -> Self::Deserializer;
fn into_buffer(_: Self::Deserializer) -> <Self::Frame as Framing>::DecBuf;
}
Expand description
An instance of Protocol glues a Framing implementation to a serializer (ProtocolWriter) and deserializer (ProtocolReader). It constructs, as needed, a serializer to construct a frame with a given protocol, or a deserializer from a frame into a stream of deserialized objects.
Required Associated Constants§
const PROTOCOL_ID: ProtocolID
Required Associated Types§
Sourcetype Sizer: ProtocolWriter<Final = usize>
type Sizer: ProtocolWriter<Final = usize>
Compute the size of a frame for a given protocol. This can be exact or too large, but must not be too small.
Sourcetype Serializer: ProtocolWriter<Final = <<Self::Frame as Framing>::EncBuf as BufMutExt>::Final>
type Serializer: ProtocolWriter<Final = <<Self::Frame as Framing>::EncBuf as BufMutExt>::Final>
Serialize into a buffer. The buffer is allocated with the size computed by Sizer, so it must be large enough.
Sourcetype Deserializer: ProtocolReader
type Deserializer: ProtocolReader
Set up a deserializer from a frame’s buffer.
Required Methods§
fn serializer<SZ, SER>( sz: SZ, ser: SER, ) -> <Self::Serializer as ProtocolWriter>::Final
fn deserializer(buf: <Self::Frame as Framing>::DecBuf) -> Self::Deserializer
fn into_buffer(_: Self::Deserializer) -> <Self::Frame as Framing>::DecBuf
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.