pub trait Serialize: ByteSize {
// Required method
fn write_to(&self, writer: &mut BytesMut);
// Provided method
fn write_to_end(&self, writer: &mut BytesMut) { ... }
}
Expand description
The Serialize
trait allows an item to be serialized into a binary
representation of itself, which may then be used send it off over
the network. This trait requires the ByteSize trait to also be
present in order to pre-allocate the necessary amount of space for
the serialized data.
Serialize
only provides one method: Serialize::write_to. This
method is used to serialize the data and write it into the given
buffer. This buffer may already contain data unrelated to this item
and may have more space available for more items to follow. However,
it is always at least the size provided by ByteSize.
Required Methods§
Provided Methods§
Sourcefn write_to_end(&self, writer: &mut BytesMut)
fn write_to_end(&self, writer: &mut BytesMut)
Convenience around [self.write_to] which already reserves the necessary space.