pub trait Message: Default + Clone + Send + Sync + Sized + PartialEq + 'static {
const NAME: &'static str;
Show 26 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;
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
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
fn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
True iff all required fields are initialized.
Always returns true
for protobuf 3.
fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
Update this message object with fields read from given stream.
fn write_to_with_cached_sizes(
&self,
os: &mut CodedOutputStream<'_>
) -> Result<()>
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.
fn compute_size(&self) -> u64
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.
fn special_fields(&self) -> &SpecialFields
fn special_fields(&self) -> &SpecialFields
Special fields (unknown fields and cached size).
fn mut_special_fields(&mut self) -> &mut SpecialFields
fn mut_special_fields(&mut self) -> &mut SpecialFields
Special fields (unknown fields and cached size).
fn default_instance() -> &'static Self
fn default_instance() -> &'static Self
Return a pointer to default immutable message with static lifetime.
let m: &MyMessage = MyMessage::default_instance();
Provided Methods
fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>
fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>
Parse message from stream.
fn cached_size(&self) -> u32
fn cached_size(&self) -> u32
Get size previously computed by compute_size
.
Note if message size exceeds u32, the cached size is stored truncated.
fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>
fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>
Write the message to the stream.
Results in error if message is not fully initialized.
fn write_length_delimited_to(
&self,
os: &mut CodedOutputStream<'_>
) -> Result<()>
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.
Write the message to the vec, prepend the message with message length encoded as varint.
Update this message object with fields read from given stream.
fn parse_from_reader(reader: &mut dyn Read) -> Result<Self>
fn parse_from_reader(reader: &mut dyn Read) -> Result<Self>
Parse message from reader. Parse stops on EOF or when error encountered.
fn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self>
fn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self>
Parse message from Bytes
object.
Resulting message may share references to the passed bytes object.
fn check_initialized(&self) -> Result<()>
fn check_initialized(&self) -> Result<()>
Check if all required fields of this object are initialized.
fn write_to_writer(&self, w: &mut dyn Write) -> Result<()>
fn write_to_writer(&self, w: &mut dyn Write) -> Result<()>
Write the message to the writer.
fn write_to_bytes(&self) -> Result<Vec<u8>>
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.
fn write_length_delimited_to_writer(&self, w: &mut dyn Write) -> Result<()>
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.
fn write_length_delimited_to_bytes(&self) -> Result<Vec<u8>>
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.
fn unknown_fields(&self) -> &UnknownFields
fn unknown_fields(&self) -> &UnknownFields
Get a reference to unknown fields.
fn mut_unknown_fields(&mut self) -> &mut UnknownFields
fn mut_unknown_fields(&mut self) -> &mut UnknownFields
Get a mutable reference to unknown fields.