Trait prost_wkt::MessageSerde
source · 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
impl dyn MessageSerde
The implementation here is a direct copy of the impl dyn
of std::any::Any
!
sourcepub fn is<T: MessageSerde>(&self) -> bool
pub fn is<T: MessageSerde>(&self) -> bool
Returns true
if the inner type is the same as T
.
sourcepub fn downcast_ref<T: MessageSerde>(&self) -> Option<&T>
pub fn downcast_ref<T: MessageSerde>(&self) -> Option<&T>
Returns some reference to the inner value if it is of type T
, or
None
if it isn’t.
sourcepub fn downcast_mut<T: MessageSerde>(&mut self) -> Option<&mut T>
pub fn downcast_mut<T: MessageSerde>(&mut self) -> Option<&mut T>
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: MessageSerde>(&self) -> &T
pub unsafe fn downcast_ref_unchecked<T: MessageSerde>(&self) -> &T
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: MessageSerde>(&mut self) -> &mut T
pub unsafe fn downcast_mut_unchecked<T: MessageSerde>(&mut self) -> &mut T
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.