wpilog-parser 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -6
- package/dist/catalog-CYDrFwrh.mjs +1071 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +71 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +1 -1069
- package/package.json +16 -17
- package/skills/{wpilog-parser → analyze-wpilog}/SKILL.md +9 -19
package/dist/index.mjs
CHANGED
|
@@ -1,1043 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/byte-offset.ts
|
|
3
|
-
var ByteOffset = class {
|
|
4
|
-
constructor(offset = 0) {
|
|
5
|
-
this.offset = offset;
|
|
6
|
-
}
|
|
7
|
-
get() {
|
|
8
|
-
return this.offset;
|
|
9
|
-
}
|
|
10
|
-
advance(bytes) {
|
|
11
|
-
this.offset += bytes;
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
advance8() {
|
|
15
|
-
return this.advance(1);
|
|
16
|
-
}
|
|
17
|
-
advance16() {
|
|
18
|
-
return this.advance(2);
|
|
19
|
-
}
|
|
20
|
-
advance32() {
|
|
21
|
-
return this.advance(4);
|
|
22
|
-
}
|
|
23
|
-
advance64() {
|
|
24
|
-
return this.advance(8);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/types.ts
|
|
29
|
-
/** Control record types in the WPILOG format. */
|
|
30
|
-
let ControlRecordType = /* @__PURE__ */ function(ControlRecordType) {
|
|
31
|
-
ControlRecordType[ControlRecordType["Start"] = 0] = "Start";
|
|
32
|
-
ControlRecordType[ControlRecordType["Finish"] = 1] = "Finish";
|
|
33
|
-
ControlRecordType[ControlRecordType["SetMetadata"] = 2] = "SetMetadata";
|
|
34
|
-
return ControlRecordType;
|
|
35
|
-
}({});
|
|
36
|
-
/** Discriminated union tag for decoded record types. */
|
|
37
|
-
let RecordType = /* @__PURE__ */ function(RecordType) {
|
|
38
|
-
RecordType["Control"] = "control";
|
|
39
|
-
RecordType["Boolean"] = "boolean";
|
|
40
|
-
RecordType["Int64"] = "int64";
|
|
41
|
-
RecordType["Float"] = "float";
|
|
42
|
-
RecordType["Double"] = "double";
|
|
43
|
-
RecordType["String"] = "string";
|
|
44
|
-
RecordType["BooleanArray"] = "boolean[]";
|
|
45
|
-
RecordType["Int64Array"] = "int64[]";
|
|
46
|
-
RecordType["FloatArray"] = "float[]";
|
|
47
|
-
RecordType["DoubleArray"] = "double[]";
|
|
48
|
-
RecordType["StringArray"] = "string[]";
|
|
49
|
-
RecordType["Struct"] = "struct";
|
|
50
|
-
RecordType["StructArray"] = "struct[]";
|
|
51
|
-
RecordType["Raw"] = "raw";
|
|
52
|
-
return RecordType;
|
|
53
|
-
}({});
|
|
54
|
-
/** Type guard that narrows a {@link DecodedRecord} to a {@link DataRecord}. */
|
|
55
|
-
function isDataRecord(record) {
|
|
56
|
-
return record.type !== "control";
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/read-records.ts
|
|
60
|
-
const TEXT_ENCODER = new TextEncoder();
|
|
61
|
-
const TEXT_DECODER$1 = new TextDecoder();
|
|
62
|
-
const MAGIC = TEXT_ENCODER.encode("WPILOG");
|
|
63
|
-
function readControlRecordPayload(payload) {
|
|
64
|
-
const offset = new ByteOffset();
|
|
65
|
-
const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
66
|
-
const type = view.getUint8(offset.get());
|
|
67
|
-
offset.advance8();
|
|
68
|
-
switch (type) {
|
|
69
|
-
case 0: {
|
|
70
|
-
const entryId = view.getUint32(offset.get(), true);
|
|
71
|
-
offset.advance32();
|
|
72
|
-
const entryNameLength = view.getUint32(offset.get(), true);
|
|
73
|
-
offset.advance32();
|
|
74
|
-
const entryName = TEXT_DECODER$1.decode(payload.subarray(offset.get(), offset.get() + entryNameLength));
|
|
75
|
-
offset.advance(entryNameLength);
|
|
76
|
-
const entryTypeLength = view.getUint32(offset.get(), true);
|
|
77
|
-
offset.advance32();
|
|
78
|
-
const entryType = TEXT_DECODER$1.decode(payload.subarray(offset.get(), offset.get() + entryTypeLength));
|
|
79
|
-
offset.advance(entryTypeLength);
|
|
80
|
-
const entryMetadataLength = view.getUint32(offset.get(), true);
|
|
81
|
-
offset.advance32();
|
|
82
|
-
const entryMetadata = TEXT_DECODER$1.decode(payload.subarray(offset.get(), offset.get() + entryMetadataLength));
|
|
83
|
-
offset.advance(entryMetadataLength);
|
|
84
|
-
return {
|
|
85
|
-
controlRecordType: type,
|
|
86
|
-
entryId,
|
|
87
|
-
entryName,
|
|
88
|
-
entryType,
|
|
89
|
-
entryMetadata
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
case 1: {
|
|
93
|
-
const entryId = view.getUint32(offset.get(), true);
|
|
94
|
-
offset.advance32();
|
|
95
|
-
return {
|
|
96
|
-
controlRecordType: type,
|
|
97
|
-
entryId
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
case 2: {
|
|
101
|
-
const entryId = view.getUint32(offset.get(), true);
|
|
102
|
-
offset.advance32();
|
|
103
|
-
const entryMetadataLength = view.getUint32(offset.get(), true);
|
|
104
|
-
offset.advance32();
|
|
105
|
-
const entryMetadata = TEXT_DECODER$1.decode(payload.subarray(offset.get(), offset.get() + entryMetadataLength));
|
|
106
|
-
offset.advance(entryMetadataLength);
|
|
107
|
-
return {
|
|
108
|
-
controlRecordType: type,
|
|
109
|
-
entryId,
|
|
110
|
-
entryMetadata
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
default: throw new RangeError(`Invalid control record type ${type}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function toUint8Array(input) {
|
|
117
|
-
if (input instanceof Uint8Array) return input;
|
|
118
|
-
return new Uint8Array(input);
|
|
119
|
-
}
|
|
120
|
-
function readVarInt(view, offset, length) {
|
|
121
|
-
switch (length) {
|
|
122
|
-
case 1: return view.getUint8(offset);
|
|
123
|
-
case 2: return view.getUint16(offset, true);
|
|
124
|
-
case 3: return view.getUint8(offset + 2) << 16 | view.getUint8(offset + 1) << 8 | view.getUint8(offset);
|
|
125
|
-
case 4: return view.getUint32(offset, true);
|
|
126
|
-
default: throw new RangeError(`Invalid varint length ${length}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function readTimestamp(view, offset, length) {
|
|
130
|
-
switch (length) {
|
|
131
|
-
case 1: return BigInt(view.getUint8(offset));
|
|
132
|
-
case 2: return BigInt(view.getUint16(offset, true));
|
|
133
|
-
case 3: {
|
|
134
|
-
const b0 = BigInt(view.getUint8(offset));
|
|
135
|
-
const b1 = BigInt(view.getUint8(offset + 1));
|
|
136
|
-
return BigInt(view.getUint8(offset + 2)) << 16n | b1 << 8n | b0;
|
|
137
|
-
}
|
|
138
|
-
case 4: return BigInt(view.getUint32(offset, true));
|
|
139
|
-
case 5: {
|
|
140
|
-
const b0 = BigInt(view.getUint8(offset));
|
|
141
|
-
const b1 = BigInt(view.getUint8(offset + 1));
|
|
142
|
-
const b2 = BigInt(view.getUint8(offset + 2));
|
|
143
|
-
const b3 = BigInt(view.getUint8(offset + 3));
|
|
144
|
-
return BigInt(view.getUint8(offset + 4)) << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
|
|
145
|
-
}
|
|
146
|
-
case 6: {
|
|
147
|
-
const b0 = BigInt(view.getUint8(offset));
|
|
148
|
-
const b1 = BigInt(view.getUint8(offset + 1));
|
|
149
|
-
const b2 = BigInt(view.getUint8(offset + 2));
|
|
150
|
-
const b3 = BigInt(view.getUint8(offset + 3));
|
|
151
|
-
const b4 = BigInt(view.getUint8(offset + 4));
|
|
152
|
-
return BigInt(view.getUint8(offset + 5)) << 40n | b4 << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
|
|
153
|
-
}
|
|
154
|
-
case 7: {
|
|
155
|
-
const b0 = BigInt(view.getUint8(offset));
|
|
156
|
-
const b1 = BigInt(view.getUint8(offset + 1));
|
|
157
|
-
const b2 = BigInt(view.getUint8(offset + 2));
|
|
158
|
-
const b3 = BigInt(view.getUint8(offset + 3));
|
|
159
|
-
const b4 = BigInt(view.getUint8(offset + 4));
|
|
160
|
-
const b5 = BigInt(view.getUint8(offset + 5));
|
|
161
|
-
return BigInt(view.getUint8(offset + 6)) << 48n | b5 << 40n | b4 << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
|
|
162
|
-
}
|
|
163
|
-
case 8: return view.getBigUint64(offset, true);
|
|
164
|
-
default: throw new RangeError(`Invalid timestamp length ${length}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Read raw WPILOG records from an in-memory buffer.
|
|
169
|
-
*
|
|
170
|
-
* Yields a header record first, then control and data records in order.
|
|
171
|
-
* Data record payloads are not decoded — use {@link decodeRecords} for that.
|
|
172
|
-
*/
|
|
173
|
-
function* readRecords(input) {
|
|
174
|
-
const bytes = toUint8Array(input);
|
|
175
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
176
|
-
const total = bytes.byteLength;
|
|
177
|
-
if (total < 12) throw new Error("Not a WPILOG file (truncated header)");
|
|
178
|
-
for (let i = 0; i < MAGIC.byteLength; i++) if (bytes[i] !== MAGIC[i]) throw new Error("Not a WPILOG file (invalid magic bytes)");
|
|
179
|
-
const versionMinor = view.getUint8(6);
|
|
180
|
-
const versionMajor = view.getUint8(7);
|
|
181
|
-
const extraHeaderLength = view.getUint32(8, true);
|
|
182
|
-
let offset = 12;
|
|
183
|
-
if (offset + extraHeaderLength > total) throw new Error("Not a WPILOG file (truncated extra header)");
|
|
184
|
-
const extraHeader = TEXT_DECODER$1.decode(bytes.subarray(offset, offset + extraHeaderLength));
|
|
185
|
-
offset += extraHeaderLength;
|
|
186
|
-
yield {
|
|
187
|
-
kind: "header",
|
|
188
|
-
header: {
|
|
189
|
-
version: {
|
|
190
|
-
major: versionMajor,
|
|
191
|
-
minor: versionMinor
|
|
192
|
-
},
|
|
193
|
-
extraHeader
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
while (offset < total) {
|
|
197
|
-
const bitfield = view.getUint8(offset);
|
|
198
|
-
offset += 1;
|
|
199
|
-
const entryIdLength = 1 + (bitfield & 3);
|
|
200
|
-
const payloadSizeLength = 1 + (bitfield >> 2 & 3);
|
|
201
|
-
const timestampLength = 1 + (bitfield >> 4 & 7);
|
|
202
|
-
if (offset + entryIdLength + payloadSizeLength + timestampLength > total) return;
|
|
203
|
-
const entryId = readVarInt(view, offset, entryIdLength);
|
|
204
|
-
offset += entryIdLength;
|
|
205
|
-
const payloadSize = readVarInt(view, offset, payloadSizeLength);
|
|
206
|
-
offset += payloadSizeLength;
|
|
207
|
-
const timestamp = readTimestamp(view, offset, timestampLength);
|
|
208
|
-
offset += timestampLength;
|
|
209
|
-
if (offset + payloadSize > total) return;
|
|
210
|
-
const payload = bytes.subarray(offset, offset + payloadSize);
|
|
211
|
-
offset += payloadSize;
|
|
212
|
-
if (entryId === 0) yield {
|
|
213
|
-
kind: "control",
|
|
214
|
-
entryId,
|
|
215
|
-
timestamp,
|
|
216
|
-
payload: readControlRecordPayload(payload)
|
|
217
|
-
};
|
|
218
|
-
else yield {
|
|
219
|
-
kind: "data",
|
|
220
|
-
record: {
|
|
221
|
-
entryId,
|
|
222
|
-
timestamp,
|
|
223
|
-
payload
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region src/struct/types.ts
|
|
230
|
-
let KnownStructTypeName = /* @__PURE__ */ function(KnownStructTypeName) {
|
|
231
|
-
KnownStructTypeName["Boolean"] = "bool";
|
|
232
|
-
KnownStructTypeName["Character"] = "char";
|
|
233
|
-
KnownStructTypeName["Int8"] = "int8";
|
|
234
|
-
KnownStructTypeName["Int16"] = "int16";
|
|
235
|
-
KnownStructTypeName["Int32"] = "int32";
|
|
236
|
-
KnownStructTypeName["Int64"] = "int64";
|
|
237
|
-
KnownStructTypeName["Uint8"] = "uint8";
|
|
238
|
-
KnownStructTypeName["Uint16"] = "uint16";
|
|
239
|
-
KnownStructTypeName["Uint32"] = "uint32";
|
|
240
|
-
KnownStructTypeName["Uint64"] = "uint64";
|
|
241
|
-
KnownStructTypeName["Float32"] = "float32";
|
|
242
|
-
/** Equivalent to {@link KnownStructTypeName.Float32} */
|
|
243
|
-
KnownStructTypeName["Float"] = "float";
|
|
244
|
-
KnownStructTypeName["Float64"] = "float64";
|
|
245
|
-
/** Equivalent to {@link KnownStructTypeName.Float64} */
|
|
246
|
-
KnownStructTypeName["Double"] = "double";
|
|
247
|
-
return KnownStructTypeName;
|
|
248
|
-
}({});
|
|
249
|
-
//#endregion
|
|
250
|
-
//#region src/struct/struct-dependency-graph.ts
|
|
251
|
-
const EMPTY_SET = /* @__PURE__ */ new Set();
|
|
252
|
-
var StructDependencyGraph = class {
|
|
253
|
-
allDependencies = new Map(Object.values(KnownStructTypeName).map((type) => [type, EMPTY_SET]));
|
|
254
|
-
registerSchema(name, innerStructNames) {
|
|
255
|
-
const existing = this.allDependencies.get(name);
|
|
256
|
-
if (existing) for (const innerStructName of innerStructNames) existing.add(innerStructName);
|
|
257
|
-
else this.allDependencies.set(name, new Set(innerStructNames));
|
|
258
|
-
if (this.hasCycle(name)) throw new RangeError(`Cycle detected in the dependency graph for ${name}`);
|
|
259
|
-
}
|
|
260
|
-
hasCycle(current, path = /* @__PURE__ */ new Set()) {
|
|
261
|
-
if (path.has(current)) return true;
|
|
262
|
-
path.add(current);
|
|
263
|
-
const directDependencies = this.allDependencies.get(current);
|
|
264
|
-
if (directDependencies) {
|
|
265
|
-
for (const dep of directDependencies) if (this.hasCycle(dep, path)) return true;
|
|
266
|
-
}
|
|
267
|
-
path.delete(current);
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
getDependencies(name) {
|
|
271
|
-
const result = /* @__PURE__ */ new Set();
|
|
272
|
-
const queue = [name];
|
|
273
|
-
while (queue.length > 0) {
|
|
274
|
-
const current = queue.pop();
|
|
275
|
-
if (result.has(current)) continue;
|
|
276
|
-
result.add(current);
|
|
277
|
-
const dependencies = this.allDependencies.get(current);
|
|
278
|
-
if (dependencies) queue.push(...dependencies);
|
|
279
|
-
}
|
|
280
|
-
return result;
|
|
281
|
-
}
|
|
282
|
-
getDecodableStructs() {
|
|
283
|
-
const result = [];
|
|
284
|
-
for (const structName of this.allDependencies.keys()) {
|
|
285
|
-
const dependencies = this.getDependencies(structName);
|
|
286
|
-
let allResolved = true;
|
|
287
|
-
for (const dep of dependencies) if (!this.allDependencies.has(dep)) {
|
|
288
|
-
allResolved = false;
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
if (allResolved) result.push(structName);
|
|
292
|
-
}
|
|
293
|
-
return result;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
//#endregion
|
|
297
|
-
//#region src/struct/struct-decode-queue.ts
|
|
298
|
-
var StructDecodeQueue = class {
|
|
299
|
-
graph = new StructDependencyGraph();
|
|
300
|
-
queuedRecords = /* @__PURE__ */ new Map();
|
|
301
|
-
constructor(onStructDefined) {
|
|
302
|
-
this.onStructDefined = onStructDefined;
|
|
303
|
-
}
|
|
304
|
-
queueStructRecord(structName, record) {
|
|
305
|
-
const existing = this.queuedRecords.get(structName);
|
|
306
|
-
if (existing) existing.push(record);
|
|
307
|
-
else this.queuedRecords.set(structName, [record]);
|
|
308
|
-
}
|
|
309
|
-
registerSchema(structName, innerStructNames) {
|
|
310
|
-
this.graph.registerSchema(structName, innerStructNames);
|
|
311
|
-
this.checkDecodableStructs();
|
|
312
|
-
}
|
|
313
|
-
checkDecodableStructs() {
|
|
314
|
-
for (const structName of this.graph.getDecodableStructs()) {
|
|
315
|
-
const records = this.queuedRecords.get(structName);
|
|
316
|
-
if (records) {
|
|
317
|
-
this.onStructDefined(structName, records);
|
|
318
|
-
this.queuedRecords.delete(structName);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
//#endregion
|
|
324
|
-
//#region src/struct/lexer.ts
|
|
325
|
-
const Comma = createToken({
|
|
326
|
-
name: "Comma",
|
|
327
|
-
pattern: ","
|
|
328
|
-
});
|
|
329
|
-
const Semicolon = createToken({
|
|
330
|
-
name: "Semicolon",
|
|
331
|
-
pattern: ";"
|
|
332
|
-
});
|
|
333
|
-
const Colon = createToken({
|
|
334
|
-
name: "Colon",
|
|
335
|
-
pattern: ":"
|
|
336
|
-
});
|
|
337
|
-
const Equals = createToken({
|
|
338
|
-
name: "Equals",
|
|
339
|
-
pattern: "="
|
|
340
|
-
});
|
|
341
|
-
const WhiteSpace = createToken({
|
|
342
|
-
name: "WhiteSpace",
|
|
343
|
-
pattern: /\s+/
|
|
344
|
-
});
|
|
345
|
-
const Integer = createToken({
|
|
346
|
-
name: "Integer",
|
|
347
|
-
pattern: /0|[1-9]\d*/
|
|
348
|
-
});
|
|
349
|
-
const LeftSquareBrace = createToken({
|
|
350
|
-
name: "LeftSquareBrace",
|
|
351
|
-
pattern: "["
|
|
352
|
-
});
|
|
353
|
-
const RightSquareBrace = createToken({
|
|
354
|
-
name: "RightSquareBrace",
|
|
355
|
-
pattern: "]"
|
|
356
|
-
});
|
|
357
|
-
const EnumKeyword = createToken({
|
|
358
|
-
name: "EnumKeyword",
|
|
359
|
-
pattern: "enum"
|
|
360
|
-
});
|
|
361
|
-
const LeftCurlyBrace = createToken({
|
|
362
|
-
name: "LeftCurlyBrace",
|
|
363
|
-
pattern: "{"
|
|
364
|
-
});
|
|
365
|
-
const RightCurlyBrace = createToken({
|
|
366
|
-
name: "RightCurlyBrace",
|
|
367
|
-
pattern: "}"
|
|
368
|
-
});
|
|
369
|
-
const Identifier = createToken({
|
|
370
|
-
name: "Identifier",
|
|
371
|
-
pattern: /\w+/
|
|
372
|
-
});
|
|
373
|
-
const allTokens = [
|
|
374
|
-
WhiteSpace,
|
|
375
|
-
Semicolon,
|
|
376
|
-
Equals,
|
|
377
|
-
Comma,
|
|
378
|
-
Colon,
|
|
379
|
-
Integer,
|
|
380
|
-
LeftSquareBrace,
|
|
381
|
-
RightSquareBrace,
|
|
382
|
-
EnumKeyword,
|
|
383
|
-
LeftCurlyBrace,
|
|
384
|
-
RightCurlyBrace,
|
|
385
|
-
Identifier
|
|
386
|
-
];
|
|
387
|
-
const lexer = new Lexer(allTokens);
|
|
388
|
-
//#endregion
|
|
389
|
-
//#region src/struct/parser.ts
|
|
390
|
-
var StructParser = class extends CstParser {
|
|
391
|
-
structSpecification = this.RULE("structSpecification", () => {
|
|
392
|
-
this.MANY_SEP({
|
|
393
|
-
SEP: Semicolon,
|
|
394
|
-
DEF: () => this.OPTION(() => this.SUBRULE(this.declaration))
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
declaration = this.RULE("declaration", () => {
|
|
398
|
-
this.OPTION(() => this.SUBRULE(this.enumSpecification));
|
|
399
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
400
|
-
this.CONSUME(Identifier);
|
|
401
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
402
|
-
this.CONSUME1(Identifier);
|
|
403
|
-
this.OPTION1(() => this.OR({ DEF: [{ ALT: () => this.SUBRULE(this.bitFieldDeclaration) }, { ALT: () => this.SUBRULE(this.standardDeclarationArray) }] }));
|
|
404
|
-
});
|
|
405
|
-
standardDeclarationArray = this.RULE("standardDeclarationArray", () => {
|
|
406
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
407
|
-
this.SUBRULE(this.arraySize);
|
|
408
|
-
});
|
|
409
|
-
bitFieldDeclaration = this.RULE("bitFieldDeclaration", () => {
|
|
410
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
411
|
-
this.CONSUME(Colon);
|
|
412
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
413
|
-
this.CONSUME(Integer);
|
|
414
|
-
});
|
|
415
|
-
arraySize = this.RULE("arraySize", () => {
|
|
416
|
-
this.CONSUME(LeftSquareBrace);
|
|
417
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
418
|
-
this.CONSUME(Integer);
|
|
419
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
420
|
-
this.CONSUME(RightSquareBrace);
|
|
421
|
-
});
|
|
422
|
-
enumSpecification = this.RULE("enumSpecification", () => {
|
|
423
|
-
this.OPTION(() => this.CONSUME(EnumKeyword));
|
|
424
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
425
|
-
this.CONSUME(LeftCurlyBrace);
|
|
426
|
-
this.MANY_SEP({
|
|
427
|
-
SEP: Comma,
|
|
428
|
-
DEF: () => this.SUBRULE(this.enumMember)
|
|
429
|
-
});
|
|
430
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
431
|
-
this.CONSUME(RightCurlyBrace);
|
|
432
|
-
});
|
|
433
|
-
enumMember = this.RULE("enumMember", () => {
|
|
434
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
435
|
-
this.CONSUME(Identifier);
|
|
436
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
437
|
-
this.CONSUME(Equals);
|
|
438
|
-
this.SUBRULE2(this.optionalWhitespace);
|
|
439
|
-
this.CONSUME(Integer);
|
|
440
|
-
this.SUBRULE3(this.optionalWhitespace);
|
|
441
|
-
});
|
|
442
|
-
optionalWhitespace = this.RULE("optionalWhitespace", () => {
|
|
443
|
-
this.OPTION(() => this.CONSUME(WhiteSpace));
|
|
444
|
-
});
|
|
445
|
-
constructor() {
|
|
446
|
-
super(allTokens);
|
|
447
|
-
this.performSelfAnalysis();
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
const parser = new StructParser();
|
|
451
|
-
parser.getBaseCstVisitorConstructor();
|
|
452
|
-
const BaseStructVisitorWithDefaults = parser.getBaseCstVisitorConstructorWithDefaults();
|
|
453
|
-
//#endregion
|
|
454
|
-
//#region src/struct/struct-ast-visitor.ts
|
|
455
|
-
var StructAstVisitor = class extends BaseStructVisitorWithDefaults {
|
|
456
|
-
constructor() {
|
|
457
|
-
super();
|
|
458
|
-
this.validateVisitor();
|
|
459
|
-
}
|
|
460
|
-
structSpecification(children) {
|
|
461
|
-
return children.declaration?.map((declaration) => this.declaration(declaration.children)) ?? [];
|
|
462
|
-
}
|
|
463
|
-
declaration(children) {
|
|
464
|
-
const [typeName, name] = children.Identifier;
|
|
465
|
-
const enumSpecification = children.enumSpecification ? this.enumSpecification(children.enumSpecification[0].children, typeName.image) : void 0;
|
|
466
|
-
const arraySize = children.standardDeclarationArray ? this.standardDeclarationArray(children.standardDeclarationArray[0].children) : void 0;
|
|
467
|
-
const bitWidth = children.bitFieldDeclaration ? this.bitFieldDeclaration(children.bitFieldDeclaration[0].children, typeName.image) : void 0;
|
|
468
|
-
return {
|
|
469
|
-
name: name.image,
|
|
470
|
-
value: typeName.image,
|
|
471
|
-
enumSpecification,
|
|
472
|
-
arraySize,
|
|
473
|
-
bitWidth
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
enumSpecification(children, dataType) {
|
|
477
|
-
switch (dataType) {
|
|
478
|
-
case "int8":
|
|
479
|
-
case "uint8":
|
|
480
|
-
case "int16":
|
|
481
|
-
case "uint16":
|
|
482
|
-
case "int32":
|
|
483
|
-
case "uint32":
|
|
484
|
-
case "int64":
|
|
485
|
-
case "uint64": break;
|
|
486
|
-
default: throw new RangeError("Enums must be integers");
|
|
487
|
-
}
|
|
488
|
-
const entries = children.enumMember?.map((member) => this.enumMember(member.children));
|
|
489
|
-
return new Map(entries);
|
|
490
|
-
}
|
|
491
|
-
enumMember(children) {
|
|
492
|
-
const [name] = children.Identifier;
|
|
493
|
-
const [value] = children.Integer;
|
|
494
|
-
return [name.image, BigInt(value.image)];
|
|
495
|
-
}
|
|
496
|
-
bitFieldDeclaration(children, dataType) {
|
|
497
|
-
const [value] = children.Integer;
|
|
498
|
-
const parsed = Number(value.image);
|
|
499
|
-
switch (dataType) {
|
|
500
|
-
case "bool":
|
|
501
|
-
if (parsed !== 1) throw new RangeError("Boolean bit-field members must be 1 bit");
|
|
502
|
-
break;
|
|
503
|
-
case "int8":
|
|
504
|
-
case "uint8":
|
|
505
|
-
if (parsed > 8) throw new RangeError("8-bit bit-field members must be less than 8 bits");
|
|
506
|
-
break;
|
|
507
|
-
case "int16":
|
|
508
|
-
case "uint16":
|
|
509
|
-
if (parsed > 16) throw new RangeError("16-bit bit-field members must be less than 16 bits");
|
|
510
|
-
break;
|
|
511
|
-
case "int32":
|
|
512
|
-
case "uint32":
|
|
513
|
-
if (parsed > 32) throw new RangeError("32-bit bit-field members must be less than 32 bits");
|
|
514
|
-
break;
|
|
515
|
-
case "int64":
|
|
516
|
-
case "uint64":
|
|
517
|
-
if (parsed > 64) throw new RangeError("64-bit bit-field members must be less than 64 bits");
|
|
518
|
-
break;
|
|
519
|
-
default: throw new RangeError("Bit-field members must be integers or booleans");
|
|
520
|
-
}
|
|
521
|
-
return parsed;
|
|
522
|
-
}
|
|
523
|
-
standardDeclarationArray(children) {
|
|
524
|
-
return this.arraySize(children.arraySize[0].children);
|
|
525
|
-
}
|
|
526
|
-
arraySize(children) {
|
|
527
|
-
const [value] = children.Integer;
|
|
528
|
-
return Number(value.image);
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region src/struct/parse-struct.ts
|
|
533
|
-
const structAstVisitor = new StructAstVisitor();
|
|
534
|
-
const cache = /* @__PURE__ */ new Map();
|
|
535
|
-
/** Parse a WPILib struct specification string into declarations. */
|
|
536
|
-
function parseStructSpecification(declaration) {
|
|
537
|
-
const existing = cache.get(declaration);
|
|
538
|
-
if (existing) return existing;
|
|
539
|
-
const lexingResult = lexer.tokenize(declaration);
|
|
540
|
-
if (lexingResult.errors.length > 0) throw new AggregateError(lexingResult.errors, "Failed to lex struct specification");
|
|
541
|
-
parser.input = lexingResult.tokens;
|
|
542
|
-
const cstNode = parser.structSpecification();
|
|
543
|
-
if (parser.errors.length > 0) throw new AggregateError(parser.errors, "Failed to parse struct specification");
|
|
544
|
-
const created = structAstVisitor.structSpecification(cstNode.children);
|
|
545
|
-
cache.set(declaration, created);
|
|
546
|
-
return created;
|
|
547
|
-
}
|
|
548
|
-
//#endregion
|
|
549
|
-
//#region src/struct/struct-registry.ts
|
|
550
|
-
var StructRegistry = class StructRegistry {
|
|
551
|
-
static TEXT_DECODER = new TextDecoder("utf-8");
|
|
552
|
-
definitions = /* @__PURE__ */ new Map();
|
|
553
|
-
byteLengths = /* @__PURE__ */ new Map();
|
|
554
|
-
constructor(structDecodeQueue) {
|
|
555
|
-
this.structDecodeQueue = structDecodeQueue;
|
|
556
|
-
}
|
|
557
|
-
register(name, definition) {
|
|
558
|
-
const specification = parseStructSpecification(definition);
|
|
559
|
-
this.definitions.set(name, specification);
|
|
560
|
-
this.structDecodeQueue.registerSchema(name, specification.map((member) => member.value));
|
|
561
|
-
}
|
|
562
|
-
getDefinition(name) {
|
|
563
|
-
const definition = this.definitions.get(name);
|
|
564
|
-
if (!definition) throw new RangeError(`Unknown struct definition: ${name}`);
|
|
565
|
-
return definition;
|
|
566
|
-
}
|
|
567
|
-
decodeArray(structName, payload) {
|
|
568
|
-
const structNameWithoutSuffix = structName.slice(0, -2);
|
|
569
|
-
const structByteLengthOrBlocker = this.getByteLength(structNameWithoutSuffix);
|
|
570
|
-
if (typeof structByteLengthOrBlocker === "string") return structByteLengthOrBlocker;
|
|
571
|
-
const elements = payload.byteLength / structByteLengthOrBlocker;
|
|
572
|
-
const offset = new ByteOffset();
|
|
573
|
-
const result = [];
|
|
574
|
-
for (let i = 0; i < elements; i++) {
|
|
575
|
-
const decoded = this.decode(structNameWithoutSuffix, payload, offset);
|
|
576
|
-
if (typeof decoded === "string") throw new TypeError(`Expected struct ${structNameWithoutSuffix} to be defined if the byte length calculation succeeded`);
|
|
577
|
-
result.push(decoded);
|
|
578
|
-
}
|
|
579
|
-
return result;
|
|
580
|
-
}
|
|
581
|
-
decode(structName, payload, offset = new ByteOffset()) {
|
|
582
|
-
if (!this.definitions.has(structName)) return structName;
|
|
583
|
-
const specification = this.getDefinition(structName);
|
|
584
|
-
const result = /* @__PURE__ */ new Map();
|
|
585
|
-
const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
586
|
-
for (const member of specification) {
|
|
587
|
-
if (member.bitWidth) throw new Error("Bit-field members are not implemented");
|
|
588
|
-
switch (member.value) {
|
|
589
|
-
case "bool":
|
|
590
|
-
if (member.arraySize !== void 0) {
|
|
591
|
-
const array = [];
|
|
592
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
593
|
-
array.push(Boolean(view.getUint8(offset.get())));
|
|
594
|
-
offset.advance8();
|
|
595
|
-
}
|
|
596
|
-
result.set(member.name, array);
|
|
597
|
-
} else {
|
|
598
|
-
result.set(member.name, Boolean(view.getUint8(offset.get())));
|
|
599
|
-
offset.advance8();
|
|
600
|
-
}
|
|
601
|
-
break;
|
|
602
|
-
case "int8":
|
|
603
|
-
if (member.arraySize !== void 0) {
|
|
604
|
-
const array = [];
|
|
605
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
606
|
-
array.push(view.getInt8(offset.get()));
|
|
607
|
-
offset.advance8();
|
|
608
|
-
}
|
|
609
|
-
result.set(member.name, array);
|
|
610
|
-
} else {
|
|
611
|
-
result.set(member.name, view.getInt8(offset.get()));
|
|
612
|
-
offset.advance8();
|
|
613
|
-
}
|
|
614
|
-
break;
|
|
615
|
-
case "int16":
|
|
616
|
-
if (member.arraySize !== void 0) {
|
|
617
|
-
const array = [];
|
|
618
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
619
|
-
array.push(view.getInt16(offset.get(), true));
|
|
620
|
-
offset.advance16();
|
|
621
|
-
}
|
|
622
|
-
result.set(member.name, array);
|
|
623
|
-
} else {
|
|
624
|
-
result.set(member.name, view.getInt16(offset.get(), true));
|
|
625
|
-
offset.advance16();
|
|
626
|
-
}
|
|
627
|
-
break;
|
|
628
|
-
case "int32":
|
|
629
|
-
if (member.arraySize !== void 0) {
|
|
630
|
-
const array = [];
|
|
631
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
632
|
-
array.push(view.getInt32(offset.get(), true));
|
|
633
|
-
offset.advance32();
|
|
634
|
-
}
|
|
635
|
-
result.set(member.name, array);
|
|
636
|
-
} else {
|
|
637
|
-
result.set(member.name, view.getInt32(offset.get(), true));
|
|
638
|
-
offset.advance32();
|
|
639
|
-
}
|
|
640
|
-
break;
|
|
641
|
-
case "int64":
|
|
642
|
-
if (member.arraySize !== void 0) {
|
|
643
|
-
const array = [];
|
|
644
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
645
|
-
array.push(view.getBigInt64(offset.get(), true));
|
|
646
|
-
offset.advance64();
|
|
647
|
-
}
|
|
648
|
-
result.set(member.name, array);
|
|
649
|
-
} else {
|
|
650
|
-
result.set(member.name, view.getBigInt64(offset.get(), true));
|
|
651
|
-
offset.advance64();
|
|
652
|
-
}
|
|
653
|
-
break;
|
|
654
|
-
case "uint8":
|
|
655
|
-
if (member.arraySize !== void 0) {
|
|
656
|
-
const array = [];
|
|
657
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
658
|
-
array.push(view.getUint8(offset.get()));
|
|
659
|
-
offset.advance8();
|
|
660
|
-
}
|
|
661
|
-
result.set(member.name, array);
|
|
662
|
-
} else {
|
|
663
|
-
result.set(member.name, view.getUint8(offset.get()));
|
|
664
|
-
offset.advance8();
|
|
665
|
-
}
|
|
666
|
-
break;
|
|
667
|
-
case "uint16":
|
|
668
|
-
if (member.arraySize !== void 0) {
|
|
669
|
-
const array = [];
|
|
670
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
671
|
-
array.push(view.getUint16(offset.get(), true));
|
|
672
|
-
offset.advance16();
|
|
673
|
-
}
|
|
674
|
-
result.set(member.name, array);
|
|
675
|
-
} else {
|
|
676
|
-
result.set(member.name, view.getUint16(offset.get(), true));
|
|
677
|
-
offset.advance16();
|
|
678
|
-
}
|
|
679
|
-
break;
|
|
680
|
-
case "uint32":
|
|
681
|
-
if (member.arraySize !== void 0) {
|
|
682
|
-
const array = [];
|
|
683
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
684
|
-
array.push(view.getUint32(offset.get(), true));
|
|
685
|
-
offset.advance32();
|
|
686
|
-
}
|
|
687
|
-
result.set(member.name, array);
|
|
688
|
-
} else {
|
|
689
|
-
result.set(member.name, view.getUint32(offset.get(), true));
|
|
690
|
-
offset.advance32();
|
|
691
|
-
}
|
|
692
|
-
break;
|
|
693
|
-
case "uint64":
|
|
694
|
-
if (member.arraySize !== void 0) {
|
|
695
|
-
const array = [];
|
|
696
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
697
|
-
array.push(view.getBigUint64(offset.get(), true));
|
|
698
|
-
offset.advance64();
|
|
699
|
-
}
|
|
700
|
-
result.set(member.name, array);
|
|
701
|
-
} else {
|
|
702
|
-
result.set(member.name, view.getBigUint64(offset.get(), true));
|
|
703
|
-
offset.advance64();
|
|
704
|
-
}
|
|
705
|
-
break;
|
|
706
|
-
case "float32":
|
|
707
|
-
case "float":
|
|
708
|
-
if (member.arraySize !== void 0) {
|
|
709
|
-
const array = [];
|
|
710
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
711
|
-
array.push(view.getFloat32(offset.get(), true));
|
|
712
|
-
offset.advance32();
|
|
713
|
-
}
|
|
714
|
-
result.set(member.name, array);
|
|
715
|
-
} else {
|
|
716
|
-
result.set(member.name, view.getFloat32(offset.get(), true));
|
|
717
|
-
offset.advance32();
|
|
718
|
-
}
|
|
719
|
-
break;
|
|
720
|
-
case "float64":
|
|
721
|
-
case "double":
|
|
722
|
-
if (member.arraySize !== void 0) {
|
|
723
|
-
const array = [];
|
|
724
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
725
|
-
array.push(view.getFloat64(offset.get(), true));
|
|
726
|
-
offset.advance64();
|
|
727
|
-
}
|
|
728
|
-
result.set(member.name, array);
|
|
729
|
-
} else {
|
|
730
|
-
result.set(member.name, view.getFloat64(offset.get(), true));
|
|
731
|
-
offset.advance64();
|
|
732
|
-
}
|
|
733
|
-
break;
|
|
734
|
-
case "char":
|
|
735
|
-
if (member.arraySize !== void 0) result.set(member.name, StructRegistry.TEXT_DECODER.decode(payload.subarray(offset.get(), offset.advance(member.arraySize).get())));
|
|
736
|
-
else result.set(member.name, StructRegistry.TEXT_DECODER.decode(payload.subarray(offset.get(), offset.advance8().get())));
|
|
737
|
-
break;
|
|
738
|
-
default: if (member.arraySize !== void 0) {
|
|
739
|
-
const array = [];
|
|
740
|
-
for (let i = 0; i < member.arraySize; i++) {
|
|
741
|
-
const decoded = this.decode(member.value, payload, offset);
|
|
742
|
-
if (typeof decoded === "string") return decoded;
|
|
743
|
-
array.push(decoded);
|
|
744
|
-
}
|
|
745
|
-
result.set(member.name, array);
|
|
746
|
-
} else {
|
|
747
|
-
const decoded = this.decode(member.value, payload, offset);
|
|
748
|
-
if (typeof decoded === "string") return decoded;
|
|
749
|
-
result.set(member.name, decoded);
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
return result;
|
|
754
|
-
}
|
|
755
|
-
getByteLength(name) {
|
|
756
|
-
const existing = this.byteLengths.get(name);
|
|
757
|
-
if (existing !== void 0) return existing;
|
|
758
|
-
const definition = this.getDefinition(name);
|
|
759
|
-
let totalByteLength = 0;
|
|
760
|
-
for (const member of definition) {
|
|
761
|
-
const memberByteLengthOrBlocker = this.calculateByteLength(member);
|
|
762
|
-
if (typeof memberByteLengthOrBlocker === "string") return memberByteLengthOrBlocker;
|
|
763
|
-
totalByteLength += memberByteLengthOrBlocker;
|
|
764
|
-
}
|
|
765
|
-
this.byteLengths.set(name, totalByteLength);
|
|
766
|
-
return totalByteLength;
|
|
767
|
-
}
|
|
768
|
-
calculateByteLength(member) {
|
|
769
|
-
if (member.bitWidth) throw new Error("Bit-field members are not implemented");
|
|
770
|
-
let byteLengthForOne = 0;
|
|
771
|
-
switch (member.value) {
|
|
772
|
-
case "bool":
|
|
773
|
-
case "char":
|
|
774
|
-
case "int8":
|
|
775
|
-
case "uint8":
|
|
776
|
-
byteLengthForOne = 1;
|
|
777
|
-
break;
|
|
778
|
-
case "int16":
|
|
779
|
-
case "uint16":
|
|
780
|
-
byteLengthForOne = 2;
|
|
781
|
-
break;
|
|
782
|
-
case "int32":
|
|
783
|
-
case "uint32":
|
|
784
|
-
byteLengthForOne = 4;
|
|
785
|
-
break;
|
|
786
|
-
case "int64":
|
|
787
|
-
case "uint64":
|
|
788
|
-
byteLengthForOne = 8;
|
|
789
|
-
break;
|
|
790
|
-
case "float32":
|
|
791
|
-
case "float":
|
|
792
|
-
byteLengthForOne = 4;
|
|
793
|
-
break;
|
|
794
|
-
case "float64":
|
|
795
|
-
case "double":
|
|
796
|
-
byteLengthForOne = 8;
|
|
797
|
-
break;
|
|
798
|
-
default: {
|
|
799
|
-
const structByteLengthOrName = this.getByteLength(member.value);
|
|
800
|
-
if (typeof structByteLengthOrName === "string") return structByteLengthOrName;
|
|
801
|
-
byteLengthForOne = structByteLengthOrName;
|
|
802
|
-
break;
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
if (member.arraySize !== void 0) return member.arraySize * byteLengthForOne;
|
|
806
|
-
return byteLengthForOne;
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
//#endregion
|
|
810
|
-
//#region src/decode-records.ts
|
|
811
|
-
const TEXT_DECODER = new TextDecoder();
|
|
812
|
-
const STRUCT_PREFIX = "struct:";
|
|
813
|
-
const STRUCT_ARRAY_SUFFIX = "[]";
|
|
814
|
-
function byteToBoolean(byte) {
|
|
815
|
-
switch (byte) {
|
|
816
|
-
case 0: return false;
|
|
817
|
-
case 1: return true;
|
|
818
|
-
default: throw new RangeError(`Invalid boolean value ${byte}`);
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
function normalizeEntryName(rawName) {
|
|
822
|
-
if (rawName.startsWith("/")) return rawName;
|
|
823
|
-
return `/${rawName}`;
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* Decode raw WPILOG records into typed values.
|
|
827
|
-
*
|
|
828
|
-
* Accepts the output of {@link readRecords} and yields fully decoded records,
|
|
829
|
-
* including struct decoding with dependency resolution.
|
|
830
|
-
*
|
|
831
|
-
* By default, data records that reference an entry ID with no preceding Start
|
|
832
|
-
* control record are silently skipped. Pass `{ strict: true }` to throw instead.
|
|
833
|
-
*/
|
|
834
|
-
function* decodeRecords(records, options = { strict: false }) {
|
|
835
|
-
const asyncDecodedStructs = [];
|
|
836
|
-
const structDecodeQueue = new StructDecodeQueue((structName, queuedRecords) => {
|
|
837
|
-
for (const raw of queuedRecords) {
|
|
838
|
-
const ctx = context.get(raw.entryId);
|
|
839
|
-
if (!ctx) continue;
|
|
840
|
-
const entryType = ctx.entryType;
|
|
841
|
-
const name = normalizeEntryName(ctx.entryName);
|
|
842
|
-
const metadata = ctx.entryMetadata;
|
|
843
|
-
if (entryType.endsWith(STRUCT_ARRAY_SUFFIX)) {
|
|
844
|
-
const normalizedName = entryType.slice(7);
|
|
845
|
-
const decoded = structRegistry.decodeArray(normalizedName, raw.payload);
|
|
846
|
-
if (typeof decoded !== "string") asyncDecodedStructs.push({
|
|
847
|
-
entryId: raw.entryId,
|
|
848
|
-
timestamp: raw.timestamp,
|
|
849
|
-
name,
|
|
850
|
-
metadata,
|
|
851
|
-
type: "struct[]",
|
|
852
|
-
structName: normalizedName,
|
|
853
|
-
payload: decoded
|
|
854
|
-
});
|
|
855
|
-
} else {
|
|
856
|
-
const normalizedName = entryType.slice(7);
|
|
857
|
-
const decoded = structRegistry.decode(normalizedName, raw.payload);
|
|
858
|
-
if (typeof decoded !== "string") asyncDecodedStructs.push({
|
|
859
|
-
entryId: raw.entryId,
|
|
860
|
-
timestamp: raw.timestamp,
|
|
861
|
-
name,
|
|
862
|
-
metadata,
|
|
863
|
-
type: "struct",
|
|
864
|
-
structName: normalizedName,
|
|
865
|
-
payload: decoded
|
|
866
|
-
});
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
});
|
|
870
|
-
const structRegistry = new StructRegistry(structDecodeQueue);
|
|
871
|
-
const context = /* @__PURE__ */ new Map();
|
|
872
|
-
for (const readRecord of records) {
|
|
873
|
-
if (readRecord.kind === "header") continue;
|
|
874
|
-
if (readRecord.kind === "control") {
|
|
875
|
-
const controlPayload = readRecord.payload;
|
|
876
|
-
switch (controlPayload.controlRecordType) {
|
|
877
|
-
case 0:
|
|
878
|
-
context.set(controlPayload.entryId, controlPayload);
|
|
879
|
-
break;
|
|
880
|
-
case 1:
|
|
881
|
-
context.delete(controlPayload.entryId);
|
|
882
|
-
break;
|
|
883
|
-
}
|
|
884
|
-
yield {
|
|
885
|
-
entryId: readRecord.entryId,
|
|
886
|
-
timestamp: readRecord.timestamp,
|
|
887
|
-
type: "control",
|
|
888
|
-
payload: controlPayload
|
|
889
|
-
};
|
|
890
|
-
continue;
|
|
891
|
-
}
|
|
892
|
-
const raw = readRecord.record;
|
|
893
|
-
const recordContext = context.get(raw.entryId);
|
|
894
|
-
if (recordContext === void 0) {
|
|
895
|
-
if (options.strict) throw new RangeError(`No type registered for entry ID ${raw.entryId}`);
|
|
896
|
-
continue;
|
|
897
|
-
}
|
|
898
|
-
const name = normalizeEntryName(recordContext.entryName);
|
|
899
|
-
const metadata = recordContext.entryMetadata;
|
|
900
|
-
const view = new DataView(raw.payload.buffer, raw.payload.byteOffset, raw.payload.byteLength);
|
|
901
|
-
const decoded = decodePayload(raw, recordContext.entryType, name, metadata, view, structRegistry, structDecodeQueue);
|
|
902
|
-
if (decoded) yield decoded;
|
|
903
|
-
yield* asyncDecodedStructs;
|
|
904
|
-
asyncDecodedStructs.length = 0;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
function decodePayload(raw, entryType, name, metadata, view, structRegistry, structDecodeQueue) {
|
|
908
|
-
const base = {
|
|
909
|
-
entryId: raw.entryId,
|
|
910
|
-
timestamp: raw.timestamp,
|
|
911
|
-
name,
|
|
912
|
-
metadata
|
|
913
|
-
};
|
|
914
|
-
switch (entryType) {
|
|
915
|
-
case "boolean": return {
|
|
916
|
-
...base,
|
|
917
|
-
type: "boolean",
|
|
918
|
-
payload: byteToBoolean(view.getUint8(0))
|
|
919
|
-
};
|
|
920
|
-
case "int64": return {
|
|
921
|
-
...base,
|
|
922
|
-
type: "int64",
|
|
923
|
-
payload: view.getBigInt64(0, true)
|
|
924
|
-
};
|
|
925
|
-
case "float": return {
|
|
926
|
-
...base,
|
|
927
|
-
type: "float",
|
|
928
|
-
payload: view.getFloat32(0, true)
|
|
929
|
-
};
|
|
930
|
-
case "double": return {
|
|
931
|
-
...base,
|
|
932
|
-
type: "double",
|
|
933
|
-
payload: view.getFloat64(0, true)
|
|
934
|
-
};
|
|
935
|
-
case "string": return {
|
|
936
|
-
...base,
|
|
937
|
-
type: "string",
|
|
938
|
-
payload: TEXT_DECODER.decode(raw.payload)
|
|
939
|
-
};
|
|
940
|
-
case "boolean[]": {
|
|
941
|
-
const payload = [];
|
|
942
|
-
for (let i = 0; i < raw.payload.byteLength; i++) payload.push(byteToBoolean(view.getUint8(i)));
|
|
943
|
-
return {
|
|
944
|
-
...base,
|
|
945
|
-
type: "boolean[]",
|
|
946
|
-
payload
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
|
-
case "int64[]": {
|
|
950
|
-
const payload = [];
|
|
951
|
-
for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getBigUint64(i, true));
|
|
952
|
-
return {
|
|
953
|
-
...base,
|
|
954
|
-
type: "int64[]",
|
|
955
|
-
payload
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
case "float[]": {
|
|
959
|
-
const payload = [];
|
|
960
|
-
for (let i = 0; i < raw.payload.byteLength; i += 4) payload.push(view.getFloat32(i, true));
|
|
961
|
-
return {
|
|
962
|
-
...base,
|
|
963
|
-
type: "float[]",
|
|
964
|
-
payload
|
|
965
|
-
};
|
|
966
|
-
}
|
|
967
|
-
case "double[]": {
|
|
968
|
-
const payload = [];
|
|
969
|
-
for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getFloat64(i, true));
|
|
970
|
-
return {
|
|
971
|
-
...base,
|
|
972
|
-
type: "double[]",
|
|
973
|
-
payload
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
case "string[]": {
|
|
977
|
-
const payload = [];
|
|
978
|
-
const offset = new ByteOffset();
|
|
979
|
-
const arrayLength = view.getUint32(offset.get(), true);
|
|
980
|
-
offset.advance32();
|
|
981
|
-
for (let i = 0; i < arrayLength; i++) {
|
|
982
|
-
const stringLength = view.getUint32(offset.get(), true);
|
|
983
|
-
offset.advance32();
|
|
984
|
-
const string = TEXT_DECODER.decode(raw.payload.subarray(offset.get(), offset.get() + stringLength));
|
|
985
|
-
offset.advance(stringLength);
|
|
986
|
-
payload.push(string);
|
|
987
|
-
}
|
|
988
|
-
return {
|
|
989
|
-
...base,
|
|
990
|
-
type: "string[]",
|
|
991
|
-
payload
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
case "structschema": {
|
|
995
|
-
const structName = name.slice(16);
|
|
996
|
-
const payload = TEXT_DECODER.decode(raw.payload);
|
|
997
|
-
structRegistry.register(structName, payload);
|
|
998
|
-
return {
|
|
999
|
-
...base,
|
|
1000
|
-
type: "string",
|
|
1001
|
-
payload
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
default:
|
|
1005
|
-
if (entryType.startsWith(STRUCT_PREFIX)) {
|
|
1006
|
-
if (entryType.endsWith(STRUCT_ARRAY_SUFFIX)) {
|
|
1007
|
-
const normalizedStructName = entryType.slice(7);
|
|
1008
|
-
const decoded = structRegistry.decodeArray(normalizedStructName, raw.payload);
|
|
1009
|
-
if (typeof decoded === "string") {
|
|
1010
|
-
structDecodeQueue.queueStructRecord(decoded, raw);
|
|
1011
|
-
return;
|
|
1012
|
-
}
|
|
1013
|
-
return {
|
|
1014
|
-
...base,
|
|
1015
|
-
type: "struct[]",
|
|
1016
|
-
structName: normalizedStructName,
|
|
1017
|
-
payload: decoded
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
const normalizedStructName = entryType.slice(7);
|
|
1021
|
-
const decoded = structRegistry.decode(normalizedStructName, raw.payload);
|
|
1022
|
-
if (typeof decoded === "string") {
|
|
1023
|
-
structDecodeQueue.queueStructRecord(decoded, raw);
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
return {
|
|
1027
|
-
...base,
|
|
1028
|
-
type: "struct",
|
|
1029
|
-
structName: normalizedStructName,
|
|
1030
|
-
payload: decoded
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
|
-
return {
|
|
1034
|
-
...base,
|
|
1035
|
-
type: "raw",
|
|
1036
|
-
payload: raw.payload
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
//#endregion
|
|
1
|
+
import { a as readRecords, c as isDataRecord, i as KnownStructTypeName, n as decodeRecords, o as ControlRecordType, r as parseStructSpecification, s as RecordType, t as catalogEntries } from "./catalog-CYDrFwrh.mjs";
|
|
1041
2
|
//#region src/struct-payload-to-json.ts
|
|
1042
3
|
/** Convert a {@link StructPayload} Map to a plain JSON-compatible object. */
|
|
1043
4
|
function structPayloadToJson(payload) {
|
|
@@ -1048,33 +9,4 @@ function structPayloadToJson(payload) {
|
|
|
1048
9
|
return result;
|
|
1049
10
|
}
|
|
1050
11
|
//#endregion
|
|
1051
|
-
//#region src/catalog.ts
|
|
1052
|
-
/**
|
|
1053
|
-
* Collect all entry definitions from a WPILOG record stream.
|
|
1054
|
-
*
|
|
1055
|
-
* Iterates through records, collecting Start control records.
|
|
1056
|
-
* Data record bytes are still read from the stream but not decoded,
|
|
1057
|
-
* making this much cheaper than full decoding via {@link decodeRecords}.
|
|
1058
|
-
*/
|
|
1059
|
-
function* catalogEntries(records) {
|
|
1060
|
-
const entries = /* @__PURE__ */ new Map();
|
|
1061
|
-
for (const record of records) {
|
|
1062
|
-
if (record.kind !== "control") continue;
|
|
1063
|
-
if (record.payload.controlRecordType === 0) {
|
|
1064
|
-
const entry = {
|
|
1065
|
-
entryId: record.payload.entryId,
|
|
1066
|
-
name: normalizeEntryName(record.payload.entryName),
|
|
1067
|
-
type: record.payload.entryType,
|
|
1068
|
-
metadata: record.payload.entryMetadata
|
|
1069
|
-
};
|
|
1070
|
-
entries.set(record.payload.entryId, entry);
|
|
1071
|
-
yield entry;
|
|
1072
|
-
}
|
|
1073
|
-
if (record.payload.controlRecordType === 2) {
|
|
1074
|
-
const existing = entries.get(record.payload.entryId);
|
|
1075
|
-
if (existing) existing.metadata = record.payload.entryMetadata;
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
//#endregion
|
|
1080
12
|
export { ControlRecordType, KnownStructTypeName, RecordType, catalogEntries, decodeRecords, isDataRecord, parseStructSpecification, readRecords, structPayloadToJson };
|