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§
sourceconst NAME: &'static str
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§
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<'_>) -> Result<()>
fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
Update this message object with fields read from given stream.
sourcefn 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.
sourcefn 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.
sourcefn special_fields(&self) -> &SpecialFields
fn special_fields(&self) -> &SpecialFields
Special fields (unknown fields and cached size).
sourcefn mut_special_fields(&mut self) -> &mut SpecialFields
fn mut_special_fields(&mut self) -> &mut SpecialFields
Special fields (unknown fields and cached size).
sourcefn 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§
sourcefn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>
fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>
Parse message from stream.
sourcefn 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.
sourcefn 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.
sourcefn 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.
sourcefn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<()>
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.
sourcefn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<()>
fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<()>
Update this message object with fields read from given stream.
sourcefn 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.
sourcefn parse_from_bytes(bytes: &[u8]) -> Result<Self>
fn parse_from_bytes(bytes: &[u8]) -> Result<Self>
Parse message from byte array.
sourcefn 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.
sourcefn check_initialized(&self) -> Result<()>
fn check_initialized(&self) -> Result<()>
Check if all required fields of this object are initialized.
sourcefn 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.
sourcefn 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.
sourcefn 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.
sourcefn 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.
sourcefn unknown_fields(&self) -> &UnknownFields
fn unknown_fields(&self) -> &UnknownFields
Get a reference to unknown fields.
sourcefn mut_unknown_fields(&mut self) -> &mut UnknownFields
fn mut_unknown_fields(&mut self) -> &mut UnknownFields
Get a mutable reference to unknown fields.