pub trait MessageSerde:
Message
+ Any
+ Serialize
+ Deserialize {
// Required methods
fn message_name(&self) -> &'static str;
fn package_name(&self) -> &'static str;
fn type_url(&self) -> &'static str;
fn new_instance(
&self,
data: Vec<u8>,
) -> Result<Box<dyn MessageSerde>, DecodeError>;
fn try_encoded(&self) -> Result<Vec<u8>, EncodeError>;
}Expand description
Trait to support serialization and deserialization of prost messages.
Required Methods§
Sourcefn message_name(&self) -> &'static str
fn message_name(&self) -> &'static str
message name as in proto file
Sourcefn package_name(&self) -> &'static str
fn package_name(&self) -> &'static str
package name as in proto file
Sourcefn type_url(&self) -> &'static str
fn type_url(&self) -> &'static str
the message proto type url e.g. type.googleapis.com/my.package.MyMessage
Sourcefn new_instance(
&self,
data: Vec<u8>,
) -> Result<Box<dyn MessageSerde>, DecodeError>
fn new_instance( &self, data: Vec<u8>, ) -> Result<Box<dyn MessageSerde>, DecodeError>
Creates a new instance of this message using the protobuf encoded data
Sourcefn try_encoded(&self) -> Result<Vec<u8>, EncodeError>
fn try_encoded(&self) -> Result<Vec<u8>, EncodeError>
Returns the encoded protobuf message as bytes
Implementations§
Source§impl dyn MessageSerde
The implementation here is a direct copy of the impl dyn of std::any::Any!
impl dyn MessageSerde
The implementation here is a direct copy of the impl dyn of std::any::Any!
Sourcepub fn is<T>(&self) -> boolwhere
T: MessageSerde,
pub fn is<T>(&self) -> boolwhere
T: MessageSerde,
Returns true if the inner type is the same as T.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: MessageSerde,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: MessageSerde,
Returns some reference to the inner value if it is of type T, or
None if it isn’t.
Sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: MessageSerde,
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: MessageSerde,
Returns some mutable reference to the boxed value if it is of type T,
or None if it isn’t.
Sourcepub unsafe fn downcast_ref_unchecked<T>(&self) -> &Twhere
T: MessageSerde,
pub unsafe fn downcast_ref_unchecked<T>(&self) -> &Twhere
T: MessageSerde,
Returns a reference to the inner value as type dyn T.
§Safety
The contained value must be of type T. Calling this method
with the incorrect type is undefined behavior.
Sourcepub unsafe fn downcast_mut_unchecked<T>(&mut self) -> &mut Twhere
T: MessageSerde,
pub unsafe fn downcast_mut_unchecked<T>(&mut self) -> &mut Twhere
T: MessageSerde,
Returns a mutable reference to the inner value as type dyn T.
§Safety
The contained value must be of type T. Calling this method
with the incorrect type is undefined behavior.