Trait netlink_proto::NetlinkMessageCodec
source · pub trait NetlinkMessageCodec {
// Required methods
fn decode<T>(src: &mut BytesMut) -> Result<Option<NetlinkMessage<T>>>
where T: NetlinkDeserializable + Debug;
fn encode<T>(msg: NetlinkMessage<T>, buf: &mut BytesMut) -> Result<()>
where T: NetlinkSerializable + Debug;
}
Expand description
Protocol to serialize and deserialize messages to and from datagrams
This is separate from tokio_util::codec::{Decoder, Encoder}
as the
implementations rely on the buffer containing full datagrams; they won’t
work well with simple bytestreams.
Officially there should be exactly one implementation of this, but the audit subsystem ignores way too many rules of the protocol, so they need a separate implementation.
Although one could make a tighter binding between NetlinkMessageCodec
and
the message types (NetlinkDeserializable+NetlinkSerializable) it can handle,
this would put quite some overhead on subsystems that followed the spec - so
we simply default to the proper implementation (in Connection
) and the
audit
code needs to overwrite it.
Required Methods§
sourcefn decode<T>(src: &mut BytesMut) -> Result<Option<NetlinkMessage<T>>>where
T: NetlinkDeserializable + Debug,
fn decode<T>(src: &mut BytesMut) -> Result<Option<NetlinkMessage<T>>>where
T: NetlinkDeserializable + Debug,
Decode message of given type from datagram payload
There might be more than one message; this needs to be called until it
either returns Ok(None)
or an error.
sourcefn encode<T>(msg: NetlinkMessage<T>, buf: &mut BytesMut) -> Result<()>where
T: NetlinkSerializable + Debug,
fn encode<T>(msg: NetlinkMessage<T>, buf: &mut BytesMut) -> Result<()>where
T: NetlinkSerializable + Debug,
Encode message to (datagram) buffer