Skip to main content

TypeSupport

Trait TypeSupport 

Source
pub trait TypeSupport:
    'static
    + Send
    + Sync {
    // Required methods
    fn to_bytes(&self) -> Result<Vec<u8>>;
    fn from_bytes(bytes: &[u8]) -> Result<Self>
       where Self: Sized;
    fn type_name() -> &'static str;

    // Provided methods
    fn type_support() -> *const c_void { ... }
    fn type_hash() -> Result<String> { ... }
}
Expand description

Trait for types that have type support information.

This allows the runtime to understand the structure of messages for serialization and deserialization.

§Serialization

The to_bytes and from_bytes methods provide CDR serialization:

  • For RCL (DDS-based): Uses rmw_serialize/rmw_deserialize internally
  • For native Zenoh: Uses serde with cdr-encoding crate

Required Methods§

Source

fn to_bytes(&self) -> Result<Vec<u8>>

Serialize this message to CDR-encoded bytes.

§Implementation
  • rcl feature: Uses RMW serialization functions
  • zenoh feature: Uses serde + cdr-encoding crate
§Errors

Returns Error::CdrError if serialization fails.

Source

fn from_bytes(bytes: &[u8]) -> Result<Self>
where Self: Sized,

Deserialize a message from CDR-encoded bytes.

§Implementation
  • rcl feature: Uses RMW deserialization functions
  • zenoh feature: Uses serde + cdr-encoding crate
§Errors

Returns Error::CdrError if deserialization fails.

Source

fn type_name() -> &'static str

Returns the type name in DDS format.

Example: "std_msgs::msg::dds_::String_"

This is used for Zenoh key expressions and type matching.

Provided Methods§

Source

fn type_support() -> *const c_void

Returns an opaque pointer to the type support structure.

The actual type of this pointer depends on the implementation (e.g., rosidl_message_type_support_t in RCL).

Source

fn type_hash() -> Result<String>

Returns the RIHS01 type hash for this message type.

§Implementation
  • For RCL: Returns empty string (hash is handled by rosidl typesupport)
  • For Zenoh: Computes hash from TypeDescription

The hash format is: RIHS01_<64_character_hex_sha256>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§