pub trait RosMessage:
Sized
+ Serialize
+ Deserialize {
const TYPE_NAME: &'static str;
const TYPE_HASH: &'static str;
const SERIALIZATION_FORMAT_ID: SerializationFormatId = nros_serdes::format::SerializationFormatId::Cdr;
const STAMP_OFFSET: Option<usize> = None;
const MAX_SERIALIZED_BOUND: Option<usize> = None;
}Expand description
Trait for ROS message types
Identifies a ROS message type by its DDS type name and RIHS hash.
All message types implement Serialize and Deserialize.
Required Associated Constants§
Provided Associated Constants§
Sourceconst SERIALIZATION_FORMAT_ID: SerializationFormatId = nros_serdes::format::SerializationFormatId::Cdr
const SERIALIZATION_FORMAT_ID: SerializationFormatId = nros_serdes::format::SerializationFormatId::Cdr
RFC-0088 — the serialization format this message’s bytes are in.
Defaulted, on purpose. A required associated type here would force a
line onto every hand-written message in every user crate, which is the
decision phase-380 W4 already made and reverted once: tightening the
message contract to serve a build assertion broke
examples/linux/rust/custom-msg, the documented hand-written-message
pattern. A defaulted const costs existing implementors nothing and still
answers at compile time, which is all the assertion needs.
It lives on RosMessage rather than nros_serdes::schema::Message
because only this trait is universal: MessageForRmw requires a schema
only under cfg(rmw_needs_type_descriptors) (Cyclone), so a check keyed
on the schema would be absent under zenoh and XRCE — and absent under
uORB, which is the one backend the check exists for.
Codegen emits an override only for a non-CDR format.
Sourceconst STAMP_OFFSET: Option<usize> = None
const STAMP_OFFSET: Option<usize> = None
RFC-0052 / phase-296 W3a — byte offset of header.stamp.sec within
this type’s serialized CDR payload (encapsulation header included),
or None when the type has no leading std_msgs/Header /
builtin_interfaces/Time. Codegen-const, never runtime
introspection: CDR here is little-endian with a 4-byte encapsulation
header and Time { i32 sec; u32 nanosec } is 4-byte aligned, so a
Header-leading (or Time-leading) type carries sec at byte 4 and
nanosec at byte 8. On-target max_age monitors peek these two
words from the raw receive buffer before deserialization.
Sourceconst MAX_SERIALIZED_BOUND: Option<usize> = None
const MAX_SERIALIZED_BOUND: Option<usize> = None
Issue 1179 / phase-498 W3 – the largest serialized size of this type,
over XCDR1 and XCDR2, or None when no bound exists (an unbounded
member) or nobody stated one.
Codegen emits nros_serdes::size::max_serialized_bound::<Self>(), the
same const fn over the schema in the same generated file. It is
computed, never a copied number, so it cannot drift from the schema.
It lives HERE, not only on nros_serdes::schema::Message, for the
reason SERIALIZATION_FORMAT_ID
does: RosMessage is the one universal trait. MessageForRmw requires
a schema only on a backend declaring type-descriptors (Cyclone), so
on zenoh and XRCE a registration site could not read the bound, and
every default receive buffer there took the image-wide size whatever
its type. Defaulted, so a hand-written message
(examples/linux/rust/custom-msg) still compiles and keeps exactly
that default; it may state its own bound by overriding this.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".