Trait protobuf::Message

source ·
pub trait Message: Default + Clone + Send + Sync + Sized + PartialEq + 'static {
    const NAME: &'static str;
Show 26 methods // Required methods fn is_initialized(&self) -> bool; fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>; fn write_to_with_cached_sizes( &self, os: &mut CodedOutputStream<'_> ) -> Result<()>; fn compute_size(&self) -> u64; fn special_fields(&self) -> &SpecialFields; fn mut_special_fields(&mut self) -> &mut SpecialFields; fn new() -> Self; fn default_instance() -> &'static Self; // Provided methods fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self> { ... } fn cached_size(&self) -> u32 { ... } fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()> { ... } fn write_length_delimited_to( &self, os: &mut CodedOutputStream<'_> ) -> Result<()> { ... } fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<()> { ... } fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<()> { ... } fn parse_from_reader(reader: &mut dyn Read) -> Result<Self> { ... } fn parse_from_bytes(bytes: &[u8]) -> Result<Self> { ... } fn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self> { ... } fn check_initialized(&self) -> Result<()> { ... } fn write_to_writer(&self, w: &mut dyn Write) -> Result<()> { ... } fn write_to_vec(&self, v: &mut Vec<u8>) -> Result<()> { ... } fn write_to_bytes(&self) -> Result<Vec<u8>> { ... } fn write_length_delimited_to_writer(&self, w: &mut dyn Write) -> Result<()> { ... } fn write_length_delimited_to_bytes(&self) -> Result<Vec<u8>> { ... } fn unknown_fields(&self) -> &UnknownFields { ... } fn mut_unknown_fields(&mut self) -> &mut UnknownFields { ... } fn clear(&mut self) { ... }
}
Expand description

Trait which is implemented by all generated message.

Note, by default all generated messages also implement MessageFull trait which provides access to reflection and features which depend on reflection (text format and JSON serialization).

Required Associated Constants§

source

const NAME: &'static str

Message name as specified in .proto file.

Message name can be accessed using MessageFull::descriptor, but when lite runtime is requested, this field can be used.

Required Methods§

source

fn is_initialized(&self) -> bool

True iff all required fields are initialized. Always returns true for protobuf 3.

source

fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>

Update this message object with fields read from given stream.

source

fn write_to_with_cached_sizes( &self, os: &mut CodedOutputStream<'_> ) -> Result<()>

Write message to the stream.

Sizes of this messages and nested messages must be cached by calling compute_size prior to this call.

source

fn compute_size(&self) -> u64

Compute and cache size of this message and all nested messages.

Note if the computation overflows u32, the cached size is stored truncated.

source

fn special_fields(&self) -> &SpecialFields

Special fields (unknown fields and cached size).

source

fn mut_special_fields(&mut self) -> &mut SpecialFields

Special fields (unknown fields and cached size).

source

fn new() -> Self

Create an empty message object.

let m = MyMessage::new();
source

fn default_instance() -> &'static Self

Return a pointer to default immutable message with static lifetime.

let m: &MyMessage = MyMessage::default_instance();

Provided Methods§

source

fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>

Parse message from stream.

source

fn cached_size(&self) -> u32

Get size previously computed by compute_size.

Note if message size exceeds u32, the cached size is stored truncated.

source

fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>

Write the message to the stream.

Results in error if message is not fully initialized.

source

fn write_length_delimited_to( &self, os: &mut CodedOutputStream<'_> ) -> Result<()>

Write the message to the stream prepending the message with message length encoded as varint.

source

fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<()>

Write the message to the vec, prepend the message with message length encoded as varint.

source

fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<()>

Update this message object with fields read from given stream.

source

fn parse_from_reader(reader: &mut dyn Read) -> Result<Self>

Parse message from reader. Parse stops on EOF or when error encountered.

source

fn parse_from_bytes(bytes: &[u8]) -> Result<Self>

Parse message from byte array.

source

fn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self>

Parse message from Bytes object. Resulting message may share references to the passed bytes object.

source

fn check_initialized(&self) -> Result<()>

Check if all required fields of this object are initialized.

source

fn write_to_writer(&self, w: &mut dyn Write) -> Result<()>

Write the message to the writer.

source

fn write_to_vec(&self, v: &mut Vec<u8>) -> Result<()>

Write the message to bytes vec.

source

fn write_to_bytes(&self) -> Result<Vec<u8>>

Write the message to bytes vec.

Note: You can use Message::parse_from_bytes to do the reverse.

source

fn write_length_delimited_to_writer(&self, w: &mut dyn Write) -> Result<()>

Write the message to the writer, prepend the message with message length encoded as varint.

source

fn write_length_delimited_to_bytes(&self) -> Result<Vec<u8>>

Write the message to the bytes vec, prepend the message with message length encoded as varint.

source

fn unknown_fields(&self) -> &UnknownFields

Get a reference to unknown fields.

source

fn mut_unknown_fields(&mut self) -> &mut UnknownFields

Get a mutable reference to unknown fields.

source

fn clear(&mut self)

Reset all fields.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Message for ExtensionRange

source§

const NAME: &'static str = "ExtensionRange"

source§

impl Message for ReservedRange

source§

const NAME: &'static str = "ReservedRange"

source§

impl Message for EnumReservedRange

source§

const NAME: &'static str = "EnumReservedRange"

source§

impl Message for Annotation

source§

const NAME: &'static str = "Annotation"

source§

impl Message for Location

source§

const NAME: &'static str = "Location"

source§

impl Message for DescriptorProto

source§

const NAME: &'static str = "DescriptorProto"

source§

impl Message for EnumDescriptorProto

source§

const NAME: &'static str = "EnumDescriptorProto"

source§

impl Message for EnumOptions

source§

const NAME: &'static str = "EnumOptions"

source§

impl Message for EnumValueDescriptorProto

source§

const NAME: &'static str = "EnumValueDescriptorProto"

source§

impl Message for EnumValueOptions

source§

const NAME: &'static str = "EnumValueOptions"

source§

impl Message for ExtensionRangeOptions

source§

const NAME: &'static str = "ExtensionRangeOptions"

source§

impl Message for FieldDescriptorProto

source§

const NAME: &'static str = "FieldDescriptorProto"

source§

impl Message for FieldOptions

source§

const NAME: &'static str = "FieldOptions"

source§

impl Message for FileDescriptorProto

source§

const NAME: &'static str = "FileDescriptorProto"

source§

impl Message for FileDescriptorSet

source§

const NAME: &'static str = "FileDescriptorSet"

source§

impl Message for FileOptions

source§

const NAME: &'static str = "FileOptions"

source§

impl Message for GeneratedCodeInfo

source§

const NAME: &'static str = "GeneratedCodeInfo"

source§

impl Message for MessageOptions

source§

const NAME: &'static str = "MessageOptions"

source§

impl Message for MethodDescriptorProto

source§

const NAME: &'static str = "MethodDescriptorProto"

source§

impl Message for MethodOptions

source§

const NAME: &'static str = "MethodOptions"

source§

impl Message for OneofDescriptorProto

source§

const NAME: &'static str = "OneofDescriptorProto"

source§

impl Message for OneofOptions

source§

const NAME: &'static str = "OneofOptions"

source§

impl Message for ServiceDescriptorProto

source§

const NAME: &'static str = "ServiceDescriptorProto"

source§

impl Message for ServiceOptions

source§

const NAME: &'static str = "ServiceOptions"

source§

impl Message for SourceCodeInfo

source§

const NAME: &'static str = "SourceCodeInfo"

source§

impl Message for UninterpretedOption

source§

const NAME: &'static str = "UninterpretedOption"

source§

impl Message for NamePart

source§

const NAME: &'static str = "NamePart"

source§

impl Message for File

source§

const NAME: &'static str = "File"

source§

impl Message for CodeGeneratorRequest

source§

const NAME: &'static str = "CodeGeneratorRequest"

source§

impl Message for CodeGeneratorResponse

source§

const NAME: &'static str = "CodeGeneratorResponse"

source§

impl Message for Version

source§

const NAME: &'static str = "Version"

source§

impl Message for Any

source§

const NAME: &'static str = "Any"

source§

impl Message for Api

source§

const NAME: &'static str = "Api"

source§

impl Message for Method

source§

const NAME: &'static str = "Method"

source§

impl Message for Mixin

source§

const NAME: &'static str = "Mixin"

source§

impl Message for Duration

source§

const NAME: &'static str = "Duration"

source§

impl Message for Empty

source§

const NAME: &'static str = "Empty"

source§

impl Message for FieldMask

source§

const NAME: &'static str = "FieldMask"

source§

impl Message for SourceContext

source§

const NAME: &'static str = "SourceContext"

source§

impl Message for ListValue

source§

const NAME: &'static str = "ListValue"

source§

impl Message for Struct

source§

const NAME: &'static str = "Struct"

source§

impl Message for Value

source§

const NAME: &'static str = "Value"

source§

impl Message for Timestamp

source§

const NAME: &'static str = "Timestamp"

source§

impl Message for Enum

source§

const NAME: &'static str = "Enum"

source§

impl Message for EnumValue

source§

const NAME: &'static str = "EnumValue"

source§

impl Message for Field

source§

const NAME: &'static str = "Field"

source§

impl Message for Option

source§

const NAME: &'static str = "Option"

source§

impl Message for Type

source§

const NAME: &'static str = "Type"

source§

impl Message for BoolValue

source§

const NAME: &'static str = "BoolValue"

source§

impl Message for BytesValue

source§

const NAME: &'static str = "BytesValue"

source§

impl Message for DoubleValue

source§

const NAME: &'static str = "DoubleValue"

source§

impl Message for FloatValue

source§

const NAME: &'static str = "FloatValue"

source§

impl Message for Int32Value

source§

const NAME: &'static str = "Int32Value"

source§

impl Message for Int64Value

source§

const NAME: &'static str = "Int64Value"

source§

impl Message for StringValue

source§

const NAME: &'static str = "StringValue"

source§

impl Message for UInt32Value

source§

const NAME: &'static str = "UInt32Value"

source§

impl Message for UInt64Value

source§

const NAME: &'static str = "UInt64Value"