pub struct CdrEncapsulationHeader {
pub representation_id: RepresentationIdentifier,
pub options: u16,
}Expand description
CDR Encapsulation Header (4 bytes)
Per RTPS v2.5 and DDS X-Types 1.3, all CDR-encoded data is prefixed with a 4-byte encapsulation header:
+--------+--------+--------+--------+
| Rep ID (2 bytes)| Options (2 bytes)|
+--------+--------+--------+--------+§Example
use ros2_types::cdr::{CdrEncapsulationHeader, RepresentationIdentifier};
// Default header (CDR Little Endian)
let header = CdrEncapsulationHeader::default();
assert_eq!(header.to_bytes(), [0x00, 0x01, 0x00, 0x00]);
// Parse header from bytes
let header = CdrEncapsulationHeader::from_bytes(&[0x00, 0x01, 0x00, 0x00]).unwrap();
assert!(header.representation_id.is_little_endian());Fields§
§representation_id: RepresentationIdentifierRepresentation identifier (encoding format + endianness)
options: u16Options field (typically 0x0000, reserved for future use)
Implementations§
Source§impl CdrEncapsulationHeader
impl CdrEncapsulationHeader
Sourcepub const fn new(representation_id: RepresentationIdentifier) -> Self
pub const fn new(representation_id: RepresentationIdentifier) -> Self
Create a new encapsulation header
Sourcepub const fn with_options(
representation_id: RepresentationIdentifier,
options: u16,
) -> Self
pub const fn with_options( representation_id: RepresentationIdentifier, options: u16, ) -> Self
Create a header with custom options
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Parse from bytes
§Errors
Returns Error::CdrError if:
- The slice is shorter than 4 bytes
- The representation identifier is unknown
Trait Implementations§
Source§impl Clone for CdrEncapsulationHeader
impl Clone for CdrEncapsulationHeader
Source§fn clone(&self) -> CdrEncapsulationHeader
fn clone(&self) -> CdrEncapsulationHeader
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CdrEncapsulationHeader
impl Debug for CdrEncapsulationHeader
Source§impl Default for CdrEncapsulationHeader
impl Default for CdrEncapsulationHeader
Source§impl PartialEq for CdrEncapsulationHeader
impl PartialEq for CdrEncapsulationHeader
impl Copy for CdrEncapsulationHeader
impl Eq for CdrEncapsulationHeader
impl StructuralPartialEq for CdrEncapsulationHeader
Auto Trait Implementations§
impl Freeze for CdrEncapsulationHeader
impl RefUnwindSafe for CdrEncapsulationHeader
impl Send for CdrEncapsulationHeader
impl Sync for CdrEncapsulationHeader
impl Unpin for CdrEncapsulationHeader
impl UnsafeUnpin for CdrEncapsulationHeader
impl UnwindSafe for CdrEncapsulationHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more