Skip to main content

zerodds_ast_layout/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! Crate `zerodds-ast-layout`. Safety classification: **SAFE**.
4//!
5//! Wire layout planning over the common AST. Produces alignment, extent,
6//! header framing and offsets per `(encoding, endianness, purpose)`;
7//! codecs execute the plan, this crate never moves sample bytes.
8//!
9//! Every wire rule lives here exactly once. The duplication across
10//! fifteen code emitters that this rebuild removes had its cost in
11//! divergence, most recently in the length-code framing of
12//! variable-length `@mutable` members.
13//!
14//! ## Spec
15//!
16//! - `docs/specs/zerodds-ast-1.0.md` §7 (layout view).
17//! - OMG XTypes 1.3 §7.4 (wire encoding), §7.4.1.2 (PL_CDR1),
18//!   §7.4.2 (Plain CDR2 / Delimited CDR2 / PL_CDR2), §7.6.8 (KeyHash).
19//! - DDSI-RTPS 2.5 §9.6.3.8 (KeyHash), §10 (encapsulation).
20//!
21//! ## Layer position
22//!
23//! Layer 2 — over `zerodds-ast`.
24#![no_std]
25#![forbid(unsafe_code)]
26
27extern crate alloc;
28
29// The observer-facing cache wrapper needs a Mutex, which lives in std;
30// the planning core does not.
31#[cfg(any(feature = "std", test))]
32extern crate std;
33
34pub mod axes;
35pub mod cache;
36pub mod key;
37mod key_maximum;
38pub mod keyhash;
39mod large_sample;
40pub mod plan;
41pub mod xcdr;
42
43pub use axes::{
44    AXES, AxisFlag, DialectLowering, DialectSettings, dialect_help, dialect_names,
45    dialect_settings_from_overrides,
46};
47pub use cache::LayoutCache;
48pub use key::{
49    AggregateDelimiter, ArrayElementFlattening, CollectionDelimiterPolicy,
50    DefaultedDiscriminatorMember, Dialect, ElementPadding, Encoding, Endianness, EnumHolderWidth,
51    EnumeratorValue, FixedDigitCount, KeyHolderAlignment, KeyHolderExtensibility, KeyHolderNesting,
52    KeyHolderOrder, LayoutKey, LengthCodePolicy, MapDelimiter, MapEntryOrder, MapKeyOrdering,
53    MustUnderstandPolicy, MutableUnionFraming, OffsetKey, PidFlagPolicy, PlCdr1FramingValues,
54    PlCdr1HeaderPolicy, PlCdr1Reading, Purpose, SequenceElementDelimiter, ShortPidRange,
55    UnionLabelMatch, WcharFraming, WcharPosition, WcharWidth, WirePosition, WstringCodeUnits,
56    WstringLengthCounts, WstringLengthPolicy, WstringTerminator, WstringUnitOrder,
57    WstringUnitWidth,
58};
59pub use keyhash::{
60    KEY_HASH_LEN, KeyHashForm, holder_keeps_only_keys, key_hash_form, key_holder_plan,
61    key_holder_plan_with, key_members, key_members_with, member_key, union_key_discriminator,
62};
63pub use large_sample::keeps_short_header;
64pub use plan::{Extent, LayoutError, LengthCode, MemberHeader, MemberPlan, Offset, TypeLayout};
65pub use xcdr::{
66    DepCollector, PID_EXTENDED, PID_LIST_END, PID_SHORT_MAX_ID, PID_SHORT_MAX_LEN,
67    PL_CDR1_ALIGNMENT, array_is_delimited, collection_is_delimited, enumeration_bit_bound,
68    enumerator_wire_value, extensibility_of, fixed_wire_digits, length_code, map_key_ordering,
69    member_held_inline_closes_a_cycle, member_must_understand, needs_extended_pid, plan,
70    primitive_layout, sequence_element_carries_length, types_that_close_an_inadmissible_cycle,
71    union_negative_matches_nothing,
72};