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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//! XMLSchema (`xs:`) built-in type mappings.
//!
//! Maps W3C XML Schema 1.0 primitive types to Rust types as required by
//! OMSC-SPC-001 Rev L and OMSC-SPC-008 Rev K.
//!
//! ## Type mapping rationale
//!
//! | XSD type | Rust alias | Spec requirement |
//! |--------------------|---------------------|--------------------------------|
//! | `xs:boolean` | `bool` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:long` | `i64` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:int` | `i32` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:short` | `i16` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:byte` | `i8` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:unsignedLong` | `u64` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:unsignedInt` | `u32` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:unsignedShort` | `u16` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:unsignedByte` | `u8` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:double` | `f64` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:float` | `f32` | OMSC-SPC-008 Table 9.1-1 |
//! | `xs:integer` | `i64` | **CERT CAL-016024** |
//! | `xs:duration` | `i64` (nanoseconds) | **CERT CAL-016027** |
//! | `xs:dateTime` | `DateTime` (chrono UTC) | **CERT CAL-016028** |
//! | `xs:time` | `i64` (ns since 00:00Z) | **CERT CAL-016029** |
//! | `xs:string` | `String` | OMSC-SPC-008 Table 9.1-2 |
//! | `xs:hexBinary` | `Vec<u8>` | OMSC-SPC-008 Table 9.1-3 |
//!
//! ## `String` vs `&str`
//!
//! Unlike the original draft (`type String<'a> = &'a str`), string fields
//! are mapped to owned `String` values. CAL Messages must own their data
//! so that they can be serialised and passed across thread boundaries
//! (`Send + Sync`). Use `&str` only for temporary, read-only access.
//!
//! ## `xs:integer` (arbitrary-precision)
//!
//! XSD `xs:integer` is theoretically unbounded, but CERT CAL-016024 mandates
//! that the CAL represent it as a **signed 64-bit integer** to provide a
//! performant API. CAL Clients must not rely on values outside `i64::MIN ..= i64::MAX`.
// ── Simple primitive types (OMSC-SPC-008 Table 9.1-1) ───────────────────────
/// `xs:boolean` — two-valued logic.
pub type Boolean = bool;
/// `xs:long` — signed 64-bit integer.
pub type Long = i64;
/// `xs:int` — signed 32-bit integer.
pub type Int = i32;
/// `xs:short` — signed 16-bit integer.
pub type Short = i16;
/// `xs:byte` — signed 8-bit integer.
pub type Byte = i8;
/// `xs:unsignedLong` — unsigned 64-bit integer.
pub type UnsignedLong = u64;
/// `xs:unsignedInt` — unsigned 32-bit integer.
pub type UnsignedInt = u32;
/// `xs:unsignedShort` — unsigned 16-bit integer.
pub type UnsignedShort = u16;
/// `xs:unsignedByte` — unsigned 8-bit integer.
pub type UnsignedByte = u8;
/// `xs:double` — IEEE 754 double-precision 64-bit floating point.
pub type Double = f64;
/// `xs:float` — IEEE 754 single-precision 32-bit floating point.
pub type Float = f32;
/// `xs:integer` — arbitrary-precision integer.
///
/// Represented as a signed 64-bit integer per **CERT CAL-016024**.
/// Values outside `i64::MIN ..= i64::MAX` are not supported by the CAL API.
pub type Integer = i64;
// ── Time types (OMSC-SPC-001 §5.2.2) ────────────────────────────────────────
/// `xs:duration` — duration in **nanoseconds** (signed).
///
/// **CERT CAL-016027**: represented as a signed 64-bit integer.
/// Positive values indicate forward durations; negative indicate backward.
pub type Duration = i64;
/// `xs:dateTime` — UTC instant wrapping [`chrono::DateTime<chrono::Utc>`].
///
/// **CERT CAL-016028**: serialised as a signed 64-bit integer of nanoseconds
/// since the POSIX epoch (1970-01-01T00:00:00Z). Negative values represent
/// instants before the epoch. Use [`DateTime::from`] / [`Into<i64>`] to
/// convert to/from the raw nanosecond representation.
;
/// `xs:time` — nanoseconds since 00:00:00.000000000Z of the current day.
///
/// **CERT CAL-016029**: represented as a signed 64-bit integer.
/// Values are always in the range `0 ..= 86_400_000_000_000` (one day in ns).
pub type Time = i64;
// ── String types (OMSC-SPC-008 Table 9.1-2) ─────────────────────────────────
/// `xs:string` — an owned Unicode string.
///
/// Using an owned `String` (not `&str`) ensures CAL Messages are `Send + Sync`
/// and can be freely passed across thread boundaries.
pub type XsString = String;
/// `xs:string` accessor — same as [`XsString`]; provided for symmetry with
/// the C++ `StringAccessor` class.
pub type StringAccessor = String;
// ── Binary types (OMSC-SPC-008 Table 9.1-3) ─────────────────────────────────
/// `xs:hexBinary` — a binary blob represented as an owned byte vector.
pub type HexBinary = ;
// ════════════════════════════════════════════════════════════════════════════
// Unit tests
// ════════════════════════════════════════════════════════════════════════════