Picking the data representation

XCDR2 against XCDR1 for one typed sample, and the difference visible on the wire.

What it shows

  • Reading carries a 4-byte seq immediately followed by an 8-byte double — exactly where the two representations diverge.
  • XCDR2 (OMG XTypes 1.3) caps 8-byte alignment at 4, so value lands at offset 4 and the sample is 19 bytes. XCDR1 (classic CDR) uses natural 8-byte alignment, so value lands 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 DataRepresentation QoS and signalled by the RTPS encapsulation id (CDR_LE 0x0001 for XCDR1, D_CDR2_LE 0x0009 for XCDR2).
  • Reading is @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.

Was es zeigt

  • Reading trägt ein 4-Byte-seq direkt 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 value auf Offset 4 und das Sample ist 19 Byte groß. XCDR1 (klassisches CDR) nutzt natürliches 8-Byte-Alignment, also landet value hinter 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_LE 0x0001 für XCDR1, D_CDR2_LE 0x0009 für XCDR2).
  • Reading ist @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.

Verwandt