pub enum ElementPadding {
Aligned,
Packed,
}Expand description
Whether the elements of a collection carry alignment padding.
XTypes 1.3 §7.4.1 defines the padding: ALIGN(N) is
MIN(N, XCDR.version.maxalign), and a structure’s members each
begin on a multiple of their own alignment counted from the
encapsulation. An element of an array or a sequence is a value like
any other, so §7.4.1 pads in front of one exactly as it does in
front of a member — which is what makes a Cell { long a; short b; }
array take a stride of eight rather than of six.
§The measured departure
tests/interop-results/array-1d-struct-final/hdds/plain-cdr1.le.bin
is 01000000 0200 03000000 0400 77 for
@final struct Cell { long a; short b; } in Cell items[2]; with
octet tail: the second element’s long a starts at offset six,
where §7.4.1’s ALIGN(4) puts it at eight. Every recorded row of
sequence-struct-final says the same — many’s second Cell puts
a at offset 26 — and so does every array and sequence row of that
column.
Struct members are still padded, which is why this is about
elements and not about alignment in general.
tests/interop-results/struct-final/hdds/plain-cdr1.le.bin is
79 29 ed ff 00000000 18 2d 44 54 fb 21 09 40 fe ff: four octets
of fill ahead of the double, because XCDR1’s maxalign is eight.
annotation-must-understand-unannotated pads the same way after an
@optional flag. So the axis has two values and not one, and
Self::Packed means “no padding between the elements”.
§What Packed means for the octets inside an element
A fresh alignment origin at the element’s own first octet. Every
recorded row that reaches the question agrees with the plainer
reading — “no alignment at all inside an element” — because no
recorded row has an element whose own members need padding between
them: the corpus’s collection elements are long/short pairs,
strings and wstrings, and the first of those is already packed.
The origin form is the one that keeps a member’s offset a function of
its own type, and it is what crate::plan() and the writer both
implement.
Variants§
Aligned
XTypes 1.3 §7.4.1: an element begins at the next multiple of its alignment, counted from the encapsulation. The default.
Packed
Every element begins at the octet after the previous element ends, and alignment inside an element is counted from there.
Implementations§
Source§impl ElementPadding
impl ElementPadding
Sourcepub const fn is_default(self) -> bool
pub const fn is_default(self) -> bool
Whether this is the default.
Sourcepub fn parse(value: &str) -> Option<Self>
pub fn parse(value: &str) -> Option<Self>
Parse a configuration value.
An unknown value returns None rather than falling back to the
default: a typo in a wire-affecting setting must be loud.
Sourcepub const fn pads_after(self, _size: u32, _align: u8) -> bool
pub const fn pads_after(self, _size: u32, _align: u8) -> bool
Whether a value of size octets is followed by padding up to the
next align, under this policy.
One expression for both the planner’s array stride and the writer’s origin, so the two cannot answer differently about the same element.