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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// GENERATED FROM kdi/contract.yaml BY kdi/gen.py — DO NOT EDIT.
//
// Regenerate with `make kdi-gen`. A hand edit is caught by
// kdi/tests/test_end_to_end.py::test_generated_rust_is_current, which re-renders this file and
// compares it byte-for-byte; there is no merge path for a local change.
//
// This file is COMMITTED even though the repo otherwise never tracks generated artifacts, because
// a crates.io tarball carries no Python: a consumer who cannot run the generator has to find the
// contract already compiled in.
/// The contract version this crate implements, `major.minor`. The crate's own version is this plus
/// a patch component and nothing else, asserted at COMPILE TIME — so a published crate cannot
/// disagree with the contract it claims to implement.
pub const KDI_VERSION: &str = "0.7";
/// The contract MAJOR. A device announcing a different one must be refused at bind: majors are not
/// compatible, and the traffic that would follow cannot be trusted.
pub const KDI_MAJOR: u16 = 0;
/// The contract MINOR. ADDITIVE by definition — a device on a HIGHER minor binds normally, and a
/// host must never do version arithmetic beyond the major equality test.
pub const KDI_MINOR: u16 = 7;
/// Every frame carries the contract's MINOR in `contract_rev`. Derived here rather
/// than restated, which is the whole point: it was once a literal in three places
/// at once and a contract bump left all three reading the old revision.
pub const CONTRACT_REV: u16 = KDI_MINOR;
/// b"KVDF" little-endian. A RESYNC ANCHOR ONLY — never a validity test.
pub const MAGIC: u32 = 0x4644564B;
/// The only frame `format` this decoder understands. A frame declaring any other value is SKIPPED
/// by its own `frame_words`, never rejected — magic, format and frame_words are frozen at their
/// offsets for every present and future format, and that is what makes the skip safe.
pub const FORMAT: u16 = 2;
/// crc32 over a frame INCLUDING its own trailer. CRC-32/ISO-HDLC; see the
/// `crc_algorithm` invariant for the full parameter set.
pub const CRC_RESIDUE: u32 = 0x2144DF1C;
/// Bytes of FIXED header — the part whose field offsets are compiled in. The whole header,
/// descriptors and lane ids included, is `hdr_words * 2` and is only knowable from the wire.
pub const HDR_BYTES: usize = 0x20;
/// Byte offset of the first section descriptor, immediately after the fixed header.
pub const DESCRIPTORS_AT: usize = 0x20;
/// A decoder takes the real stride from `desc_words` on the wire; this is the floor
/// below which a frame is rejected.
pub const DESC_WORDS_MIN: u16 = 8;
/// Bytes of CRC trailer every frame ends with. Included in `frame_words`, so the body ends this
/// many bytes before the frame does.
pub const CRC_BYTES: usize = 4;
/// `dflags[2:1]` -> bits per element. Index 0 is 16 so `dflags == 0` is the common case.
pub const ELEM_BITS: = ;
// Byte offsets within the fixed header, from `streams.*.header`.
/// Byte offset of `magic` (u32) in the fixed header.
pub const OFF_MAGIC: usize = 0x00;
/// Byte offset of `format` (u16) in the fixed header.
pub const OFF_FORMAT: usize = 0x04;
/// Byte offset of `flags` (u16) in the fixed header.
pub const OFF_FLAGS: usize = 0x06;
/// Byte offset of `timestamp` (u64) in the fixed header.
pub const OFF_TIMESTAMP: usize = 0x08;
/// Byte offset of `frame_words` (u32, words16) in the fixed header.
pub const OFF_FRAME_WORDS: usize = 0x10;
/// Byte offset of `layout` (u16) in the fixed header. Opaque section-arrangement id; a cache key,
/// never a branch.
pub const OFF_LAYOUT: usize = 0x14;
/// Byte offset of `hdr_words` (u16, words16) in the fixed header.
pub const OFF_HDR_WORDS: usize = 0x16;
/// Byte offset of `n_sections` (u16) in the fixed header.
pub const OFF_N_SECTIONS: usize = 0x18;
/// Byte offset of `run_id` (u16) in the fixed header.
pub const OFF_RUN_ID: usize = 0x1A;
/// Byte offset of `contract_rev` (u16) in the fixed header.
pub const OFF_CONTRACT_REV: usize = 0x1C;
/// Byte offset of `desc_words` (u16, words16) in the fixed header.
pub const OFF_DESC_WORDS: usize = 0x1E;
// Byte offsets within one section descriptor, from `streams.*.descriptor.fields`.
/// Byte offset of `kind` (u8) in one section descriptor.
pub const DOFF_KIND: usize = 0x00;
/// Byte offset of `dflags` (u8) in one section descriptor.
pub const DOFF_DFLAGS: usize = 0x01;
/// Byte offset of `n_lanes` (u16) in one section descriptor.
pub const DOFF_N_LANES: usize = 0x02;
/// Byte offset of `words_per_lane` (u16) in one section descriptor.
pub const DOFF_WORDS_PER_LANE: usize = 0x04;
/// Byte offset of `section_words` (u16) in one section descriptor.
pub const DOFF_SECTION_WORDS: usize = 0x06;
/// Byte offset of `tick_num` (u32) in one section descriptor.
pub const DOFF_TICK_NUM: usize = 0x08;
/// Byte offset of `tick_den` (u16) in one section descriptor.
pub const DOFF_TICK_DEN: usize = 0x0C;
/// Byte offset of `pad` (u16) in one section descriptor.
pub const DOFF_PAD: usize = 0x0E;
// Header flag bits, from the `flags` field's declared bit assignment.
/// The frame starts a contiguous segment of ITS OWN stream. Its timestamp need not be 0 and there
/// may be several per `run_id`, which is the device-wide epoch — so this is where a timestamp gap
/// stops meaning loss, and nothing else marks that seam.
pub const FLAG_FIRST_OF_RUN: u16 = 1 << 0;
/// The device dropped data before this frame. The frame itself is intact; what is lost is the
/// contiguity with the one before it.
pub const FLAG_WORDS_DROPPED: u16 = 1 << 1;
/// The sampling cadence changed at this frame. Re-read the per-section `tick_num`/`tick_den` rather
/// than carrying the previous rational forward.
pub const FLAG_RATE_EVENT: u16 = 1 << 2;
/// Every DEFINED flag bit. A header with any other bit set is rejected rather than masked
/// (`reserved_reject`), so a `flags` word that survives parsing has only these in it.
pub const FLAGS_DEFINED: u16 = FLAG_FIRST_OF_RUN | FLAG_WORDS_DROPPED | FLAG_RATE_EVENT;
/// A section kind. Append-only and FROZEN: a redefined kind is the one mis-parse nothing on
/// the wire can catch. 0x80-0xff are reserved for private use.
/// A frame carrying one of these MUST be rejected, with exactly this token. The published
/// vector set carries a negative case for every variant.