Picking the data representation
XCDR2 against XCDR1 for one typed sample, and the difference visible on the wire.
- Example:
rust-xcdr1-representation - Repository: zero-dds-snippets
What it shows
Readingcarries a 4-byteseqimmediately followed by an 8-bytedouble— exactly where the two representations diverge.- XCDR2 (OMG XTypes 1.3) caps 8-byte alignment at 4, so
valuelands at offset 4 and the sample is 19 bytes. XCDR1 (classic CDR) uses natural 8-byte alignment, sovaluelands at offset 8 behind four pad bytes and the sample is 23 bytes. - The representation is selected by the writer's max alignment; in DDS it is negotiated via the
DataRepresentationQoS and signalled by the RTPS encapsulation id (CDR_LE0x0001for XCDR1,D_CDR2_LE0x0009for XCDR2). Readingis@final, which isolates the pure alignment difference — no DHEADER either way.
Build and run
cargo run
Output
sample: Reading { seq: 7, value: 2.5, label: "ok" }
XCDR2 (19 bytes): 07 00 00 00 00 00 00 00 00 00 04 40 03 00 00 00 6f 6b 00
XCDR1 (23 bytes): 07 00 00 00 00 00 00 00 00 00 00 00 00 00 04 40 03 00 00 00 6f 6b 00
Taken verbatim from the example's own README.
See also
Die Data-Representation wählen
XCDR2 gegen XCDR1 an einem typisierten Sample, und der Unterschied sichtbar auf der Leitung.
- Beispiel:
rust-xcdr1-representation - Repository: zero-dds-snippets
Was es zeigt
Readingträgt ein 4-Byte-seqdirekt gefolgt von einem 8-Byte-double— genau dort gehen die beiden Repräsentationen auseinander.- XCDR2 (OMG XTypes 1.3) deckelt das 8-Byte-Alignment auf 4, also landet
valueauf Offset 4 und das Sample ist 19 Byte groß. XCDR1 (klassisches CDR) nutzt natürliches 8-Byte-Alignment, also landetvaluehinter vier Padding-Bytes auf Offset 8 und das Sample ist 23 Byte groß. - Die Repräsentation wählt das maximale Alignment des Writers; in DDS wird sie über die
DataRepresentation-QoS ausgehandelt und über die RTPS-Encapsulation-Id signalisiert (CDR_LE0x0001für XCDR1,D_CDR2_LE0x0009für XCDR2). Readingist@final, was den reinen Alignment-Unterschied isoliert — in keiner Variante ein DHEADER.
Bauen und ausführen
cargo run
Ausgabe
sample: Reading { seq: 7, value: 2.5, label: "ok" }
XCDR2 (19 bytes): 07 00 00 00 00 00 00 00 00 00 04 40 03 00 00 00 6f 6b 00
XCDR1 (23 bytes): 07 00 00 00 00 00 00 00 00 00 00 00 00 00 04 40 03 00 00 00 6f 6b 00
Wörtlich aus dem README des Beispiels übernommen.