Trait protobuf_native::MessageLite

source ·
pub trait MessageLite: MessageLite {
    // Provided methods
    fn new(&self) -> Pin<Box<dyn MessageLite>> { ... }
    fn clear(self: Pin<&mut Self>) { ... }
    fn is_initialized(&self) -> bool { ... }
    fn merge_from_coded_stream(
        self: Pin<&mut Self>,
        input: Pin<&mut CodedInputStream<'_>>
    ) -> Result<(), OperationFailedError> { ... }
    fn serialize_to_coded_stream(
        &self,
        output: Pin<&mut CodedOutputStream<'_>>
    ) -> Result<(), OperationFailedError> { ... }
    fn serialize_to_zero_copy_stream(
        &self,
        output: Pin<&mut dyn ZeroCopyOutputStream>
    ) -> Result<(), OperationFailedError> { ... }
    fn serialize_to_writer(
        &self,
        output: &mut dyn Write
    ) -> Result<(), OperationFailedError> { ... }
    fn serialize(&self) -> Result<Vec<u8>, OperationFailedError> { ... }
    fn byte_size(&self) -> usize { ... }
}
Expand description

Interface to light weight protocol messages.

This interface is implemented by all protocol message objects. Non-lite messages additionally implement the Message interface, which is a subclass of MessageLite. Use MessageLite instead when you only need the subset of features which it supports – namely, nothing that uses descriptors or reflection. You can instruct the protocol compiler to generate classes which implement only MessageLite, not the full Message interface, by adding the following line to the .proto file:

option optimize_for = LITE_RUNTIME;

This is particularly useful on resource-constrained systems where the full protocol buffers runtime library is too big.

Note that on non-constrained systems (e.g. servers) when you need to link in lots of protocol definitions, a better way to reduce total code footprint is to use optimize_for = CODE_SIZE. This will make the generated code smaller while still supporting all the same features (at the expense of speed). optimize_for = LITE_RUNTIME is best when you only have a small number of message types linked into your binary, in which case the size of the protocol buffers runtime itself is the biggest problem.

Users must not derive from this class. Only the protocol compiler and the internal library are allowed to create subclasses.

Provided Methods§

source

fn new(&self) -> Pin<Box<dyn MessageLite>>

Constructs a new instance of the same type.

source

fn clear(self: Pin<&mut Self>)

Clears all fields of the message and set them to their default values.

This method avoids freeing memory, assuming that any memory allocated to hold parts of the message will be needed again to hold the next message. If you actually want to free the memory used by a MessageLite, you must drop it.

source

fn is_initialized(&self) -> bool

Quickly checks if all required fields have been set.

source

fn merge_from_coded_stream( self: Pin<&mut Self>, input: Pin<&mut CodedInputStream<'_>> ) -> Result<(), OperationFailedError>

Reads a protocol buffer from the stream and merges it into this message.

Singular fields read from the what is already in the message and repeated fields are appended to those already present.

It is the responsibility of the caller to call input->LastTagWas() (for groups) or input->ConsumedEntireMessage() (for non-groups) after this returns to verify that the message’s end was delimited correctly.

source

fn serialize_to_coded_stream( &self, output: Pin<&mut CodedOutputStream<'_>> ) -> Result<(), OperationFailedError>

Writes a protocol buffer of this message to the given output.

All required fields must be set.

source

fn serialize_to_zero_copy_stream( &self, output: Pin<&mut dyn ZeroCopyOutputStream> ) -> Result<(), OperationFailedError>

Writes the message to the given zero-copy output stream.

All required fields must be set.

source

fn serialize_to_writer( &self, output: &mut dyn Write ) -> Result<(), OperationFailedError>

Writes the message to the given Write implementor.

All required fields must be set.

source

fn serialize(&self) -> Result<Vec<u8>, OperationFailedError>

Serializes the message to a byte vector.

All required fields must be set.

source

fn byte_size(&self) -> usize

Computes the serialized size of the message.

This recursively calls byte_size on all embedded messages. The computation is generally linear in the number of the fields defined for the proto.

Implementors§