1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! Wire layout of `HLAextendableVariantRecord` (IEEE 1516.2-2025 4.14.10.3), the variant record encoding
//! that lets FOM modules add alternatives to an existing data type (4.14.8, annex C): the length of the
//! alternative travels with it, so a receiver can skip an alternative it does not know, and adding one
//! never moves the neighbours of the record. The dynamic container, the
//! `hla_extendable_variant_record!` macro and the FOM-driven codec all use the functions of this module.
//!
//! Layout, offsets counted from the start of the outermost value (each record starts at a multiple of 8,
//! so these are the offsets the clause counts from the start of the record):
//!
//! | Part | Rule |
//! | --- | --- |
//! | record | octet boundary [`OCTET_BOUNDARY`]: the alternatives count as 8, whatever they are |
//! | discriminant | at offset 0, its own encoding |
//! | padding | to a multiple of [`LENGTH_BOUNDARY`] (4), equation (3) |
//! | encoded_length | `HLAinteger32BE`: octets of the alternative without padding; 0 when no alternative applies |
//! | padding | to a multiple of [`ALTERNATIVE_BOUNDARY`] (8), equation (4) |
//! | alternative | its own encoding, exactly encoded_length octets; nothing after it |
//!
//! The padding before the alternative is written whatever the length, also when no alternative applies:
//! equation (4) computes it from the sizes of the discriminant and of the length field only, not from
//! the presence of an alternative. The words "if required" around it allow another reading, padding
//! only when an alternative follows (a receiver could apply that rule too, from the length); the two
//! differ only for a discriminant of more than four octets (64 bits) and a length of 0, since after a
//! smaller discriminant the length field ends at offset 8. MicroRTI 0.1.2 followed that other reading.
//!
//! When decoding, a length of 0 followed by fewer octets than that padding takes the 0.1.2 form: the
//! padded form cannot be complete there. When more octets follow, they are read as padding: they could
//! also be the next component of a 0.1.2 value, and nothing tells the two apart, padding content being
//! ignored.
//!
//! Alternatives whose octet boundary exceeds 8 cannot use this encoding (4.14.10.3).
use crate;
use crate;
/// Octet boundary of every `HLAextendableVariantRecord`, independent of its alternatives (4.14.10.3).
pub const OCTET_BOUNDARY: usize = 8;
/// Octet boundary of the encoded_length field, an `HLAinteger32BE`.
pub const LENGTH_BOUNDARY: usize = 4;
/// Octet boundary at which the alternative starts, and the largest one an alternative may have.
pub const ALTERNATIVE_BOUNDARY: usize = 8;
/// Aligns the writer for a record. The caller encodes the discriminant next.
/// Writes the encoded_length field after the discriminant and the padding that follows it. The caller
/// then encodes the alternative, which must take exactly `alternative_len` octets.
///
/// A length above `i32::MAX`, which the `HLAinteger32BE` field cannot hold, records
/// [`EncoderError::AlternativeTooLong`].
/// Aligns the reader for a record. The caller decodes the discriminant next.
/// Reads the encoded_length field after the discriminant, skips the padding that follows it and delimits
/// the alternative. A negative length is [`DecoderError::InvalidValue`].
///
/// A length of 0 followed by fewer octets than the padding is read without padding (the form MicroRTI
/// 0.1.2 wrote); see the module documentation.
/// The octets of one alternative, as delimited by the length field.