pub trait Message: Debug + Clear + Any + Send + Sync {
Show 28 methods
// Required methods
fn descriptor(&self) -> &'static MessageDescriptor;
fn is_initialized(&self) -> bool;
fn merge_from(
&mut self,
is: &mut CodedInputStream<'_>
) -> ProtobufResult<()>;
fn write_to_with_cached_sizes(
&self,
os: &mut CodedOutputStream<'_>
) -> ProtobufResult<()>;
fn compute_size(&self) -> u32;
fn get_cached_size(&self) -> u32;
fn get_unknown_fields<'s>(&'s self) -> &'s UnknownFields;
fn mut_unknown_fields<'s>(&'s mut self) -> &'s mut UnknownFields;
fn as_any(&self) -> &dyn Any;
fn new() -> Self
where Self: Sized;
fn default_instance() -> &'static Self
where Self: Sized;
// Provided methods
fn parse_from(is: &mut CodedInputStream<'_>) -> ProtobufResult<Self>
where Self: Sized { ... }
fn write_to(&self, os: &mut CodedOutputStream<'_>) -> ProtobufResult<()> { ... }
fn write_length_delimited_to(
&self,
os: &mut CodedOutputStream<'_>
) -> ProtobufResult<()> { ... }
fn write_length_delimited_to_vec(
&self,
vec: &mut Vec<u8>
) -> ProtobufResult<()> { ... }
fn merge_from_bytes(&mut self, bytes: &[u8]) -> ProtobufResult<()> { ... }
fn parse_from_reader(reader: &mut dyn Read) -> ProtobufResult<Self>
where Self: Sized { ... }
fn parse_from_bytes(bytes: &[u8]) -> ProtobufResult<Self>
where Self: Sized { ... }
fn check_initialized(&self) -> ProtobufResult<()> { ... }
fn write_to_writer(&self, w: &mut dyn Write) -> ProtobufResult<()> { ... }
fn write_to_vec(&self, v: &mut Vec<u8>) -> ProtobufResult<()> { ... }
fn write_to_bytes(&self) -> ProtobufResult<Vec<u8>> { ... }
fn write_length_delimited_to_writer(
&self,
w: &mut dyn Write
) -> ProtobufResult<()> { ... }
fn write_length_delimited_to_bytes(&self) -> ProtobufResult<Vec<u8>> { ... }
fn type_id(&self) -> TypeId { ... }
fn as_any_mut(&mut self) -> &mut dyn Any { ... }
fn into_any(self: Box<Self>) -> Box<dyn Any> { ... }
fn descriptor_static() -> &'static MessageDescriptor
where Self: Sized { ... }
}
Expand description
Trait implemented for all generated structs for protobuf messages.
Also, generated messages implement Clone + Default + PartialEq
Required Methods§
sourcefn descriptor(&self) -> &'static MessageDescriptor
fn descriptor(&self) -> &'static MessageDescriptor
Message descriptor for this message, used for reflection.
sourcefn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
True iff all required fields are initialized.
Always returns true
for protobuf 3.
sourcefn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> ProtobufResult<()>
fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> ProtobufResult<()>
Update this message object with fields read from given stream.
sourcefn write_to_with_cached_sizes(
&self,
os: &mut CodedOutputStream<'_>
) -> ProtobufResult<()>
fn write_to_with_cached_sizes( &self, os: &mut CodedOutputStream<'_> ) -> ProtobufResult<()>
Write message to the stream.
Sizes of this messages and nested messages must be cached
by calling compute_size
prior to this call.
sourcefn compute_size(&self) -> u32
fn compute_size(&self) -> u32
Compute and cache size of this message and all nested messages
sourcefn get_cached_size(&self) -> u32
fn get_cached_size(&self) -> u32
Get size previously computed by compute_size
.
sourcefn get_unknown_fields<'s>(&'s self) -> &'s UnknownFields
fn get_unknown_fields<'s>(&'s self) -> &'s UnknownFields
Get a reference to unknown fields.
sourcefn mut_unknown_fields<'s>(&'s mut self) -> &'s mut UnknownFields
fn mut_unknown_fields<'s>(&'s mut self) -> &'s mut UnknownFields
Get a mutable reference to unknown fields.
sourcefn default_instance() -> &'static Selfwhere
Self: Sized,
fn default_instance() -> &'static Selfwhere Self: Sized,
Return a pointer to default immutable message with static lifetime.
let m: &MyMessage = MyMessage::default_instance();
Provided Methods§
sourcefn parse_from(is: &mut CodedInputStream<'_>) -> ProtobufResult<Self>where
Self: Sized,
fn parse_from(is: &mut CodedInputStream<'_>) -> ProtobufResult<Self>where Self: Sized,
Parse message from stream.
sourcefn write_to(&self, os: &mut CodedOutputStream<'_>) -> ProtobufResult<()>
fn write_to(&self, os: &mut CodedOutputStream<'_>) -> ProtobufResult<()>
Write the message to the stream.
Results in error if message is not fully initialized.
sourcefn write_length_delimited_to(
&self,
os: &mut CodedOutputStream<'_>
) -> ProtobufResult<()>
fn write_length_delimited_to( &self, os: &mut CodedOutputStream<'_> ) -> ProtobufResult<()>
Write the message to the stream prepending the message with message length encoded as varint.
sourcefn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> ProtobufResult<()>
fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> ProtobufResult<()>
Write the message to the vec, prepend the message with message length encoded as varint.
sourcefn merge_from_bytes(&mut self, bytes: &[u8]) -> ProtobufResult<()>
fn merge_from_bytes(&mut self, bytes: &[u8]) -> ProtobufResult<()>
Update this message object with fields read from given stream.
sourcefn parse_from_reader(reader: &mut dyn Read) -> ProtobufResult<Self>where
Self: Sized,
fn parse_from_reader(reader: &mut dyn Read) -> ProtobufResult<Self>where Self: Sized,
Parse message from reader. Parse stops on EOF or when error encountered.
sourcefn parse_from_bytes(bytes: &[u8]) -> ProtobufResult<Self>where
Self: Sized,
fn parse_from_bytes(bytes: &[u8]) -> ProtobufResult<Self>where Self: Sized,
Parse message from byte array.
sourcefn check_initialized(&self) -> ProtobufResult<()>
fn check_initialized(&self) -> ProtobufResult<()>
Check if all required fields of this object are initialized.
sourcefn write_to_writer(&self, w: &mut dyn Write) -> ProtobufResult<()>
fn write_to_writer(&self, w: &mut dyn Write) -> ProtobufResult<()>
Write the message to the writer.
sourcefn write_to_vec(&self, v: &mut Vec<u8>) -> ProtobufResult<()>
fn write_to_vec(&self, v: &mut Vec<u8>) -> ProtobufResult<()>
Write the message to bytes vec.
sourcefn write_to_bytes(&self) -> ProtobufResult<Vec<u8>>
fn write_to_bytes(&self) -> ProtobufResult<Vec<u8>>
Write the message to bytes vec.
sourcefn write_length_delimited_to_writer(
&self,
w: &mut dyn Write
) -> ProtobufResult<()>
fn write_length_delimited_to_writer( &self, w: &mut dyn Write ) -> ProtobufResult<()>
Write the message to the writer, prepend the message with message length encoded as varint.
sourcefn write_length_delimited_to_bytes(&self) -> ProtobufResult<Vec<u8>>
fn write_length_delimited_to_bytes(&self) -> ProtobufResult<Vec<u8>>
Write the message to the bytes vec, prepend the message with message length encoded as varint.
sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
View self as mutable Any
.
sourcefn descriptor_static() -> &'static MessageDescriptorwhere
Self: Sized,
fn descriptor_static() -> &'static MessageDescriptorwhere Self: Sized,
Get message descriptor for message type.
let descriptor = MyMessage::descriptor_static();
assert_eq!("MyMessage", descriptor.name());