Skip to main content

Module encode

Module encode 

Source
Expand description

Encoder bodies, built from the layout plan. Spec §5, §6.2.

One walk, emitted through a CodecTarget. Which member is written, in what order, under which header and with which length code is decided here and once; how that is spelled is the backend’s.

The counterpart of crate::encode, which does the same for Rust against the Rust CST directly and has not been brought over. Every framing decision is read from zerodds-ast-layout and none is re-derived: the plan is where the length-code policy and the XCDR2 alignment rule live, and a second derivation would be a second place to get them wrong.

What the emitted code does not delegate is the wire rule itself. Alignment, the string length convention, the UTF-16 count, the BCD packing, the enumerator’s signed holder and the DHEADER, EMHEADER and PID framing are the target runtime’s — runtime/c, runtime/java and the rest each implement them from the clause rather than calling the Rust one. That is what makes a column a second reading of the specification: where two disagree, one of them has misread it.

§What this walk assumes of every target

  • A routine per type. Rust’s emitter names a writer method on the element type; C has no methods, so every type gets its own routine and collections call it by name. A target that would rather emit a method says so in CodecTarget::routine.
  • Forward declarations are the target’s business. C needs them ahead of the bodies so a recursive type does not depend on visit order; a target with no such thing answers None and the loop emits only bodies.
  • A switch is an if-chain. The union’s branch is selected by comparing the discriminator against each case’s labels, which every target can hold and which sidesteps the languages whose switch will not take a 64-bit label.

Structs§

CodecOptions
The one framing question the layout plan does not answer.

Functions§

codec
Build the encoder for every type in the model, under one plan.
codec_excluding
codec without the types in excluded, and with what the types in also_reaching reach.
codec_from
The encoder for the types one root reaches, and no others.
codec_from_many
The encoder for the types several roots reach, each function once.
codec_from_many_excluding
codec_from_many without the types in excluded, whose codecs are written by hand elsewhere (DDS-RPC 1.0 §7.5.1.1.1’s common types come with the runtime in a shape of their own).
codec_name
The encoder function name for a type.
key_holder
The key holder for a keyed type, and nothing for one with no @key.