Skip to main content

Module codec

Module codec 

Source
Expand description

The SOH wire codec: encode and decode.

Functions§

decode
Decode input into a Message with flat fields (no dictionary-driven group structure).
decode_with_groups
Decode input into a Message with repeating groups structured per spec (FR-004, and header/trailer groups per US9, feature 005, FR-026). Header, body, and trailer are each decoded through the same group-aware machinery (decode_section_with_groups) — a section with no declared groups (today, header/trailer always; body when spec has none for it either) decodes exactly as flat fields, since spec.group_of(tag) simply never matches. Structure is best-effort/greedy — count/order validation is a separate dictionary concern (see truefix-dict).
encode
Encode msg to SOH-delimited wire bytes.
encode_with_order
As encode, but when field_order is Some, the message body’s top-level fields are emitted in that tag order instead of insertion order (US9, feature 005, FR-027) — fields present in field_order come first (in that order), then any body field not listed in it (e.g. a UDF), in its original insertion-relative order, matching QFJ’s own FieldOrderComparator “unspecified fields last” semantics. Repeating-group entries are unaffected (each entry’s own field order is unconditionally preserved) — field_order only reorders the message body’s direct top-level members.
restructure_groups
Re-group an already-decoded, flat FieldMap against spec — the in-memory counterpart to decode_with_groups’s wire-level grouping (feature 011, FR-008). Needed because a FIXT 1.1 application dictionary is only resolvable after this crate’s decode step already ran (its selection depends on session state — the negotiated ApplVerID — that this crate has no visibility into; see truefix-session’s post-decode restructuring call site): map is first flattened back to a plain token stream (recursively, so a Member::Group entry from some other already-applied spec is flattened too, not left half-structured) and then re-grouped via [decode_section_with_groups] — the exact same boundary-detection algorithm decode_with_groups itself uses, so the two paths can never diverge (Constitution Principle IV). A tag spec doesn’t recognize as a group ends up a plain field, exactly like decode_with_groups. Calling this on an already-correctly-structured map (relative to spec) is a safe, idempotent no-op (flattening then immediately re-grouping the same content the same way).