pub trait NetlinkSerializable {
fn message_type(&self) -> u16;
fn buffer_len(&self) -> usize;
fn serialize(&self, buffer: &mut [u8]);
}
Required methods
fn message_type(&self) -> u16
fn buffer_len(&self) -> usize
fn buffer_len(&self) -> usize
Return the length of the serialized data.
Most netlink messages are encoded following a
TLV scheme
and this library takes advantage of this by pre-allocating
buffers of the appropriate size when serializing messages,
which is why buffer_len
is needed.
Serialize this types and write the serialized data into the given buffer.
buffer
’s length is exactly InnerMessage::buffer_len()
.
It means that if InnerMessage::buffer_len()
is buggy and does not return the appropriate length,
bad things can happen:
- if
buffer_len()
returns a value smaller than the actual data,emit()
may panics - if
buffer_len()
returns a value bigger than the actual data, the buffer will contain garbage
Panic
This method panics if the buffer is not big enough.