Skip to main content

ReflectMessage

Trait ReflectMessage 

Source
pub trait ReflectMessage {
    // Required method
    fn descriptor(&self) -> MessageDescriptor;

    // Provided method
    fn transcode_to_dynamic(&self) -> DynamicMessage
       where Self: Message + Sized { ... }
}
Expand description

Implemented by every type that has a descriptor in some crate::DescriptorPool — generated typed messages via #[derive(ReflectMessage)] and runtime-typed crate::DynamicMessage.

Note: this trait deliberately does not require buffa::Message as a super-trait so that crate::DynamicMessage (which has no static DefaultInstance) can implement it. Where wire-encoding via Self::encode_to_vec is needed, individual methods name Self: ::buffa::Message as a where-clause.

Required Methods§

Source

fn descriptor(&self) -> MessageDescriptor

Resolve the MessageDescriptor for Self.

The pool the descriptor lives in is set up by the #[derive(ReflectMessage)] macro, either:

  • the user-supplied descriptor_pool expression, or
  • a lazily-decoded pool keyed off the embedded file_descriptor_set_bytes.

Provided Methods§

Source

fn transcode_to_dynamic(&self) -> DynamicMessage
where Self: Message + Sized,

Available on crate feature dynamic only.

Round-trip self through wire bytes into a crate::DynamicMessage.

The default implementation pays one wire round-trip; the impl for crate::DynamicMessage short-circuits to self.clone().

§Panics

Panics if self.encode_to_vec() produces bytes that fail to decode against self.descriptor() — this would indicate a bug in the generated descriptor() wiring or in self’s Message impl.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ReflectMessage for DynamicMessage

Available on crate feature dynamic only.