pub trait Message: PartialEq + Default + Debug + Any {
// Required methods
fn compute_size(&self) -> usize;
fn serialize<W: PbBufferWriter>(&self, w: &mut W) -> Result<()>;
fn deserialize<B: PbBufferReader>(&mut self, r: &mut B) -> Result<()>;
// Provided methods
fn descriptor(&self) -> Option<MessageDescriptor> { ... }
fn compute_grpc_slices_size(&self) -> usize { ... }
fn serialize_to_vec(&self) -> Vec<u8> { ... }
fn serialize_to_writer<W: Write>(&self, writer: &mut W) -> Result<()> { ... }
fn deserialize_from_slice(slice: &[u8]) -> Result<Self> { ... }
}
Expand description
Trait implemented by all the messages defined in proto files and base datatypes like string, bytes, etc. The exact details of this trait is implemented for messages and base types can be found at - https://developers.google.com/protocol-buffers/docs/encoding
Required Methods§
sourcefn compute_size(&self) -> usize
fn compute_size(&self) -> usize
Computes the number of bytes a message will take when serialized. This does not include number of bytes required for tag+wire_format or the bytes used to represent length of the message in case of LengthDelimited messages/types.
sourcefn serialize<W: PbBufferWriter>(&self, w: &mut W) -> Result<()>
fn serialize<W: PbBufferWriter>(&self, w: &mut W) -> Result<()>
Serializes the message to the writer.
sourcefn deserialize<B: PbBufferReader>(&mut self, r: &mut B) -> Result<()>
fn deserialize<B: PbBufferReader>(&mut self, r: &mut B) -> Result<()>
Reads the message from the blob reader, copying as necessary.
Provided Methods§
sourcefn descriptor(&self) -> Option<MessageDescriptor>
fn descriptor(&self) -> Option<MessageDescriptor>
Returns the MessageDescriptor
for this message, if this is not a primitive type.
sourcefn compute_grpc_slices_size(&self) -> usize
fn compute_grpc_slices_size(&self) -> usize
Computes the number of bytes in all grpc slices. This information is used to optimize memory allocations in zero-copy encoding.
sourcefn serialize_to_vec(&self) -> Vec<u8>
fn serialize_to_vec(&self) -> Vec<u8>
Helper method for serializing a message to a Vec
sourcefn deserialize_from_slice(slice: &[u8]) -> Result<Self>
fn deserialize_from_slice(slice: &[u8]) -> Result<Self>
Helper method for deserializing a message from a u8 slice.
This will error if there are any Lazy fields in the message.