Skip to main content

Module codec

Module codec 

Source
Expand description

Reflective XCDR codec: CDR bytes ⟷ DynamicData, driven by a runtime DynamicType.

The DDS CDR codec is mature + interop-hardened (the 4-vendor × 3-extensibility matrix) but monomorphicDdsType::decode per generated Rust type. This module is the missing reflective path: it walks a runtime DynamicType and reuses the SAME hardened wire framing from zerodds_cdr::struct_enc (decode_appendable / read_all_mutable_members + encode_appendable / encode_mutable_member) and the BufferReader / BufferWriter primitives. No DHEADER/EMHEADER/alignment logic is reimplemented — only the type-driven member walk lives here.

Supported (both directions, byte-exact round-trip tested):

  • primitives, enum, string, wstring (via the hardened zerodds_cdr::WString);
  • struct FINAL / APPENDABLE / MUTABLE; nested struct;
  • union FINAL / APPENDABLE / MUTABLE (PL_CDR2: discriminator = EMHEADER member id 0, selected branch = its own EMHEADER member), with the discriminator encoded at its REAL kind (bool/char/int8/16/32/64/enum — not int32);
  • sequences + arrays of scalar AND composite (struct/union) elements, incl. the XCDR2 collection DHEADER for non-primitive elements. Composite element types are carried via crate::dynamic::collection (a resolved element DynamicType); scalar elements are rebuilt from the shallow descriptor.
  • alias (typedef) members whose target is a scalar (composite typedefs are resolved to their underlying type at IDL-lowering time).

Residual (honest NotSupported, never silent-wrong):

  • long double / Float128 — blocked on stable Rust f128;
  • bitmask / bitset are lowered to their underlying wire integer at IDL-lowering time (so they decode correctly as integers); the codec keeps no dedicated kind for them.

Enums§

CodecError
Reflective-codec error.

Functions§

decode_dynamic
Decode bytes (a CDR payload WITHOUT the encapsulation header) into a DynamicData of ty. xcdr2 selects XCDR2 vs XCDR1 framing; big_endian the byte order — both come from the sample’s encapsulation id on the wire.
encode_dynamic
Encode data to a CDR payload (WITHOUT the encapsulation header), the mirror of decode_dynamic: encode_dynamic(decode_dynamic(ty, b, x, e)?, x, e)? == b.