wpilog-parser 3.2.2 → 4.1.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.
@@ -201,18 +201,14 @@ function readVarInt(view, offset, length) {
201
201
  }
202
202
  function readTimestamp(view, offset, length) {
203
203
  switch (length) {
204
- case 1: return BigInt(view.getUint8(offset));
205
- case 2: return BigInt(view.getUint16(offset, true));
206
- case 3: return BigInt(view.getUint16(offset, true) + view.getUint8(offset + 2) * 2 ** 16);
207
- case 4: return BigInt(view.getUint32(offset, true));
208
- case 5: return BigInt(view.getUint32(offset, true) + view.getUint8(offset + 4) * 2 ** 32);
209
- case 6: return BigInt(view.getUint32(offset, true) + view.getUint16(offset + 4, true) * 2 ** 32);
210
- case 7: {
211
- const low = view.getUint32(offset, true);
212
- const high = view.getUint16(offset + 4, true) + view.getUint8(offset + 6) * 2 ** 16;
213
- return BigInt(high) << 32n | BigInt(low);
214
- }
215
- case 8: return view.getBigUint64(offset, true);
204
+ case 1: return view.getUint8(offset);
205
+ case 2: return view.getUint16(offset, true);
206
+ case 3: return view.getUint16(offset, true) + view.getUint8(offset + 2) * 2 ** 16;
207
+ case 4: return view.getUint32(offset, true);
208
+ case 5: return view.getUint32(offset, true) + view.getUint8(offset + 4) * 2 ** 32;
209
+ case 6: return view.getUint32(offset, true) + view.getUint16(offset + 4, true) * 2 ** 32;
210
+ case 7: return view.getUint32(offset, true) + (view.getUint16(offset + 4, true) + view.getUint8(offset + 6) * 2 ** 16) * 2 ** 32;
211
+ case 8: return view.getUint32(offset, true) + view.getUint32(offset + 4, true) * 2 ** 32;
216
212
  default: throw new RangeError(`Invalid timestamp length ${length}`);
217
213
  }
218
214
  }
@@ -222,9 +218,10 @@ var RecordCursor = class {
222
218
  view;
223
219
  header;
224
220
  entryId = 0;
225
- timestamp = 0n;
221
+ timestamp = 0;
226
222
  payloadOffset = 0;
227
223
  payloadSize = 0;
224
+ /** Byte offset of the next record. */
228
225
  offset;
229
226
  constructor(input) {
230
227
  const source = openDataLog(input);
@@ -267,15 +264,13 @@ var RecordCursor = class {
267
264
  return this.bytes.subarray(this.payloadOffset, this.payloadOffset + this.payloadSize);
268
265
  }
269
266
  };
270
- /**
271
- * Read raw WPILOG records from an in-memory buffer.
272
- *
273
- * Yields a header record first, then control and data records in order.
274
- * Data record payloads are not decoded. Prefer `parseDataLog` when raw records
275
- * or an intermediate transformation are not needed.
276
- */
277
- function* readRecords(input) {
267
+ /** Expose a parser's position on its generator without adding work to the per-record loop. */
268
+ function withBytesRead(records, getBytesRead) {
269
+ return Object.defineProperty(records, "bytesRead", { get: getBytesRead });
270
+ }
271
+ function* readRawRecords(input, progress) {
278
272
  const { bytes, view, header, recordsOffset } = openDataLog(input);
273
+ progress.offset = recordsOffset;
279
274
  const total = bytes.byteLength;
280
275
  let offset = recordsOffset;
281
276
  yield {
@@ -287,16 +282,23 @@ function* readRecords(input) {
287
282
  const entryIdLength = 1 + (bitfield & 3);
288
283
  const payloadSizeLength = 1 + (bitfield >> 2 & 3);
289
284
  const timestampLength = 1 + (bitfield >> 4 & 7);
290
- if (offset + entryIdLength + payloadSizeLength + timestampLength > total) return;
285
+ if (offset + entryIdLength + payloadSizeLength + timestampLength > total) {
286
+ progress.offset = total;
287
+ return;
288
+ }
291
289
  const entryId = readVarInt(view, offset, entryIdLength);
292
290
  offset += entryIdLength;
293
291
  const payloadSize = readVarInt(view, offset, payloadSizeLength);
294
292
  offset += payloadSizeLength;
295
293
  const timestamp = readTimestamp(view, offset, timestampLength);
296
294
  offset += timestampLength;
297
- if (offset + payloadSize > total) return;
295
+ if (offset + payloadSize > total) {
296
+ progress.offset = total;
297
+ return;
298
+ }
298
299
  const payload = bytes.subarray(offset, offset + payloadSize);
299
300
  offset += payloadSize;
301
+ progress.offset = offset;
300
302
  if (entryId === 0) yield {
301
303
  kind: "control",
302
304
  entryId,
@@ -313,6 +315,17 @@ function* readRecords(input) {
313
315
  };
314
316
  }
315
317
  }
318
+ /**
319
+ * Read raw WPILOG records from an in-memory buffer.
320
+ *
321
+ * Yields a header record first, then control and data records in order.
322
+ * Data record payloads are not decoded. Prefer `parseDataLog` when raw records
323
+ * or an intermediate transformation are not needed.
324
+ */
325
+ function readRecords(input) {
326
+ const progress = { offset: 0 };
327
+ return withBytesRead(readRawRecords(input, progress), () => progress.offset);
328
+ }
316
329
  // src/struct/diagnostics.ts
317
330
  /** Preserve the published WPILOG diagnostics at the protocol boundary. */
318
331
  function withStructDiagnostics(action) {
@@ -395,12 +408,10 @@ const STRUCT_SCHEMA_NAME_PREFIX = "/.schema/struct:";
395
408
  * Build a non-struct data record as one flat object literal.
396
409
  * Struct records are built inline with the same field order plus `structName`.
397
410
  */
398
- function dataRecord(entryId, timestamp, name, metadata, type, payload) {
411
+ function dataRecord(entry, timestamp, type, payload) {
399
412
  return {
400
- entryId,
413
+ entry,
401
414
  timestamp,
402
- name,
403
- metadata,
404
415
  type,
405
416
  payload
406
417
  };
@@ -418,8 +429,8 @@ function normalizeEntryName(rawName) {
418
429
  }
419
430
  var RecordDecoder = class {
420
431
  delayedRecords = [];
421
- context = /* @__PURE__ */ new Map();
422
- recordContexts = /* @__PURE__ */ new WeakMap();
432
+ entries = /* @__PURE__ */ new Map();
433
+ recordEntries = /* @__PURE__ */ new WeakMap();
423
434
  structDecodeQueue;
424
435
  structRegistry;
425
436
  options;
@@ -427,17 +438,14 @@ var RecordDecoder = class {
427
438
  this.options = options;
428
439
  this.structDecodeQueue = new StructDecodeQueue((_structName, queuedRecords) => {
429
440
  for (const raw of queuedRecords) {
430
- const context = this.recordContexts.get(raw);
431
- if (!context) continue;
432
- const { entryType, name, metadata } = context;
433
- const structName = entryType.slice(7);
434
- if (entryType.endsWith(STRUCT_ARRAY_SUFFIX)) {
441
+ const entry = this.recordEntries.get(raw);
442
+ if (!entry) continue;
443
+ const structName = entry.type.slice(7);
444
+ if (entry.type.endsWith(STRUCT_ARRAY_SUFFIX)) {
435
445
  const payload = this.structRegistry.decodeArray(structName, raw.payload);
436
446
  if (typeof payload !== "string") this.delayedRecords.push({
437
- entryId: raw.entryId,
447
+ entry,
438
448
  timestamp: raw.timestamp,
439
- name,
440
- metadata,
441
449
  type: RecordType.StructArray,
442
450
  structName,
443
451
  payload
@@ -445,10 +453,8 @@ var RecordDecoder = class {
445
453
  } else {
446
454
  const payload = this.structRegistry.decode(structName, raw.payload);
447
455
  if (typeof payload !== "string") this.delayedRecords.push({
448
- entryId: raw.entryId,
456
+ entry,
449
457
  timestamp: raw.timestamp,
450
- name,
451
- metadata,
452
458
  type: RecordType.Struct,
453
459
  structName,
454
460
  payload
@@ -461,18 +467,19 @@ var RecordDecoder = class {
461
467
  decodeControl(entryId, timestamp, payload) {
462
468
  switch (payload.controlRecordType) {
463
469
  case ControlRecordType.Start:
464
- this.context.set(payload.entryId, {
470
+ this.entries.set(payload.entryId, {
471
+ entryId: payload.entryId,
465
472
  name: normalizeEntryName(payload.entryName),
466
- entryType: payload.entryType,
473
+ type: payload.entryType,
467
474
  metadata: payload.entryMetadata
468
475
  });
469
476
  break;
470
477
  case ControlRecordType.Finish:
471
- this.context.delete(payload.entryId);
478
+ this.entries.delete(payload.entryId);
472
479
  break;
473
480
  case ControlRecordType.SetMetadata: {
474
- const existing = this.context.get(payload.entryId);
475
- if (existing) this.context.set(payload.entryId, {
481
+ const existing = this.entries.get(payload.entryId);
482
+ if (existing) this.entries.set(payload.entryId, {
476
483
  ...existing,
477
484
  metadata: payload.entryMetadata
478
485
  });
@@ -487,17 +494,16 @@ var RecordDecoder = class {
487
494
  };
488
495
  }
489
496
  decodeData(entryId, timestamp, bytes, view, payloadOffset, payloadSize) {
490
- const context = this.context.get(entryId);
491
- if (!context) {
497
+ const entry = this.entries.get(entryId);
498
+ if (!entry) {
492
499
  if (this.options.strict) throw diagnostics.WPILOG_R0006({ entryId });
493
500
  return;
494
501
  }
495
- const { name, metadata } = context;
496
- switch (context.entryType) {
497
- case "boolean": return dataRecord(entryId, timestamp, name, metadata, RecordType.Boolean, byteToBoolean(view.getUint8(payloadOffset)));
498
- case "int64": return dataRecord(entryId, timestamp, name, metadata, RecordType.Int64, view.getBigInt64(payloadOffset, true));
499
- case "float": return dataRecord(entryId, timestamp, name, metadata, RecordType.Float, view.getFloat32(payloadOffset, true));
500
- case "double": return dataRecord(entryId, timestamp, name, metadata, RecordType.Double, view.getFloat64(payloadOffset, true));
502
+ switch (entry.type) {
503
+ case "boolean": return dataRecord(entry, timestamp, RecordType.Boolean, byteToBoolean(view.getUint8(payloadOffset)));
504
+ case "int64": return dataRecord(entry, timestamp, RecordType.Int64, view.getBigInt64(payloadOffset, true));
505
+ case "float": return dataRecord(entry, timestamp, RecordType.Float, view.getFloat32(payloadOffset, true));
506
+ case "double": return dataRecord(entry, timestamp, RecordType.Double, view.getFloat64(payloadOffset, true));
501
507
  }
502
508
  const payload = payloadOffset === 0 && payloadSize === bytes.byteLength ? bytes : bytes.subarray(payloadOffset, payloadOffset + payloadSize);
503
509
  const raw = {
@@ -505,9 +511,8 @@ var RecordDecoder = class {
505
511
  timestamp,
506
512
  payload
507
513
  };
508
- const payloadView = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
509
- const decoded = decodeNonScalarPayload(raw, context.entryType, context.name, context.metadata, payloadView, this.structRegistry, this.structDecodeQueue);
510
- if (!decoded) this.recordContexts.set(raw, context);
514
+ const decoded = decodeNonScalarPayload(raw, entry, new DataView(payload.buffer, payload.byteOffset, payload.byteLength), this.structRegistry, this.structDecodeQueue);
515
+ if (!decoded) this.recordEntries.set(raw, entry);
511
516
  return decoded;
512
517
  }
513
518
  };
@@ -545,8 +550,13 @@ function* decodeRecords(records, options = { strict: false }) {
545
550
  * intermediate records produced by composing {@link readRecords} and
546
551
  * {@link decodeRecords} while preserving the same output and strict-mode behavior.
547
552
  */
548
- function* parseDataLog(input, options = { strict: false }) {
553
+ function parseDataLog(input, options = { strict: false }) {
554
+ const state = {};
555
+ return withBytesRead(decodeCursorRecords(input, options, state), () => state.cursor?.offset ?? 0);
556
+ }
557
+ function* decodeCursorRecords(input, options, state) {
549
558
  const cursor = new RecordCursor(input);
559
+ state.cursor = cursor;
550
560
  const decoder = new RecordDecoder(options);
551
561
  while (cursor.next()) {
552
562
  if (cursor.entryId === 0) {
@@ -565,29 +575,30 @@ function* parseDataLog(input, options = { strict: false }) {
565
575
  * Decode non-scalar payloads that require a byte slice or payload-local view.
566
576
  * Fixed-width scalar types return from {@link RecordDecoder#decodeData} before this function so their payloads can be read directly from the input buffer.
567
577
  */
568
- function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegistry, structDecodeQueue) {
569
- const { entryId, timestamp } = raw;
578
+ function decodeNonScalarPayload(raw, entry, view, structRegistry, structDecodeQueue) {
579
+ const { timestamp } = raw;
580
+ const { type: entryType, name } = entry;
570
581
  switch (entryType) {
571
- case "string": return dataRecord(entryId, timestamp, name, metadata, RecordType.String, TEXT_DECODER.decode(raw.payload));
582
+ case "string": return dataRecord(entry, timestamp, RecordType.String, TEXT_DECODER.decode(raw.payload));
572
583
  case "boolean[]": {
573
584
  const payload = [];
574
585
  for (let i = 0; i < raw.payload.byteLength; i++) payload.push(byteToBoolean(view.getUint8(i)));
575
- return dataRecord(entryId, timestamp, name, metadata, RecordType.BooleanArray, payload);
586
+ return dataRecord(entry, timestamp, RecordType.BooleanArray, payload);
576
587
  }
577
588
  case "int64[]": {
578
589
  const payload = [];
579
590
  for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getBigUint64(i, true));
580
- return dataRecord(entryId, timestamp, name, metadata, RecordType.Int64Array, payload);
591
+ return dataRecord(entry, timestamp, RecordType.Int64Array, payload);
581
592
  }
582
593
  case "float[]": {
583
594
  const payload = [];
584
595
  for (let i = 0; i < raw.payload.byteLength; i += 4) payload.push(view.getFloat32(i, true));
585
- return dataRecord(entryId, timestamp, name, metadata, RecordType.FloatArray, payload);
596
+ return dataRecord(entry, timestamp, RecordType.FloatArray, payload);
586
597
  }
587
598
  case "double[]": {
588
599
  const payload = [];
589
600
  for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getFloat64(i, true));
590
- return dataRecord(entryId, timestamp, name, metadata, RecordType.DoubleArray, payload);
601
+ return dataRecord(entry, timestamp, RecordType.DoubleArray, payload);
591
602
  }
592
603
  case "string[]": {
593
604
  const payload = [];
@@ -601,13 +612,13 @@ function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegi
601
612
  offset.advance(stringLength);
602
613
  payload.push(string);
603
614
  }
604
- return dataRecord(entryId, timestamp, name, metadata, RecordType.StringArray, payload);
615
+ return dataRecord(entry, timestamp, RecordType.StringArray, payload);
605
616
  }
606
617
  case "structschema": {
607
618
  const structName = name.slice(name.indexOf(STRUCT_SCHEMA_NAME_PREFIX) + 16);
608
619
  const payload = TEXT_DECODER.decode(raw.payload);
609
620
  structRegistry.register(structName, payload);
610
- return dataRecord(entryId, timestamp, name, metadata, RecordType.String, payload);
621
+ return dataRecord(entry, timestamp, RecordType.String, payload);
611
622
  }
612
623
  default:
613
624
  if (entryType.startsWith(STRUCT_PREFIX)) {
@@ -619,10 +630,8 @@ function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegi
619
630
  return;
620
631
  }
621
632
  return {
622
- entryId,
633
+ entry,
623
634
  timestamp,
624
- name,
625
- metadata,
626
635
  type: RecordType.StructArray,
627
636
  structName,
628
637
  payload: decoded
@@ -634,16 +643,14 @@ function decodeNonScalarPayload(raw, entryType, name, metadata, view, structRegi
634
643
  return;
635
644
  }
636
645
  return {
637
- entryId,
646
+ entry,
638
647
  timestamp,
639
- name,
640
- metadata,
641
648
  type: RecordType.Struct,
642
649
  structName,
643
650
  payload: decoded
644
651
  };
645
652
  }
646
- return dataRecord(entryId, timestamp, name, metadata, RecordType.Raw, new Uint8Array(raw.payload));
653
+ return dataRecord(entry, timestamp, RecordType.Raw, new Uint8Array(raw.payload));
647
654
  }
648
655
  }
649
656
  // src/catalog.ts
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as readRecords, l as diagnostics, t as catalogEntries } from "./catalog-Dz8xPVYl.mjs";
2
+ import { a as readRecords, l as diagnostics, t as catalogEntries } from "./catalog-DPm4EBaR.mjs";
3
3
  import { Diagnostic, formatDiagnostic } from "nostics";
4
4
  import { RootCommand, script } from "@bomb.sh/tab";
5
5
  import { boolean, command, commandsInfo, positional, run } from "@drizzle-team/brocli";
@@ -7,7 +7,7 @@ import oscStatus from "osc-status";
7
7
  import { readFile } from "node:fs/promises";
8
8
  import { encode } from "@toon-format/toon";
9
9
  // package.json
10
- var version = "3.2.2";
10
+ var version = "4.1.0";
11
11
  var description = "Read WPILib wpilog data log files in TypeScript & JavaScript";
12
12
  // src/cli/catalog.ts
13
13
  async function catalogFile(filePath) {
package/dist/index.d.mts CHANGED
@@ -35,11 +35,18 @@ type SetMetadataControlRecord = {
35
35
  };
36
36
  /** A control record payload (start, finish, or set metadata). */
37
37
  type ControlRecordPayload = StartControlRecord | FinishControlRecord | SetMetadataControlRecord;
38
+ /** An entry definition, from its Start control record and any later SetMetadata control records. */
39
+ type CatalogEntry = {
40
+ entryId: number;
41
+ name: string;
42
+ type: string;
43
+ metadata: string;
44
+ };
38
45
  /** A raw (undecoded) data log record from the binary format. */
39
46
  type RawRecord = {
40
47
  entryId: number;
41
48
  /** Timestamp in microseconds. */
42
- timestamp: bigint;
49
+ timestamp: number;
43
50
  payload: Uint8Array;
44
51
  };
45
52
  /** Discriminated union tag for decoded record types. */
@@ -62,7 +69,7 @@ export declare const RecordType: {
62
69
  export type RecordType = (typeof RecordType)[keyof typeof RecordType];
63
70
  /** A decoded data record (excludes control records). */
64
71
  type DataRecord = Extract<DecodedRecord, {
65
- name: string;
72
+ entry: CatalogEntry;
66
73
  }>;
67
74
  /** A decoded control record. */
68
75
  type ControlRecord = Extract<DecodedRecord, {
@@ -72,15 +79,18 @@ type ControlRecord = Extract<DecodedRecord, {
72
79
  export declare function isDataRecord(record: DecodedRecord): record is DataRecord;
73
80
  /** A decoded data log record. */
74
81
  type DecodedRecord = {
75
- entryId: number;
76
82
  /** Timestamp in microseconds. */
77
- timestamp: bigint;
83
+ timestamp: number;
78
84
  } & ({
85
+ entryId: number;
79
86
  type: typeof RecordType.Control;
80
87
  payload: ControlRecordPayload;
81
88
  } | ({
82
- name: string;
83
- metadata: string;
89
+ /**
90
+ * The entry this record belongs to.
91
+ * Records from the same entry share one object until a SetMetadata control record replaces it.
92
+ */
93
+ entry: CatalogEntry;
84
94
  } & ({
85
95
  type: typeof RecordType.Raw;
86
96
  payload: Uint8Array;
@@ -130,7 +140,7 @@ type ReadRecord = {
130
140
  } | {
131
141
  kind: 'control';
132
142
  entryId: number;
133
- timestamp: bigint;
143
+ timestamp: number;
134
144
  payload: ControlRecordPayload;
135
145
  } | {
136
146
  kind: 'data';
@@ -138,6 +148,14 @@ type ReadRecord = {
138
148
  };
139
149
  /** Accepted input types for {@link readRecords} and `parseDataLog`. */
140
150
  type DataLogInput = Uint8Array | ArrayBuffer;
151
+ /** A generator of records that also reports how far it has read through the input. */
152
+ type DataLogGenerator<T> = Generator<T> & {
153
+ /**
154
+ * Number of input bytes consumed so far, including the file header. This is `0` until the first record is read.
155
+ * Divide by the input's `byteLength` to estimate progress; it equals `byteLength` once parsing finishes.
156
+ */
157
+ readonly bytesRead: number;
158
+ };
141
159
  /**
142
160
  * Read raw WPILOG records from an in-memory buffer.
143
161
  *
@@ -145,7 +163,7 @@ type DataLogInput = Uint8Array | ArrayBuffer;
145
163
  * Data record payloads are not decoded. Prefer `parseDataLog` when raw records
146
164
  * or an intermediate transformation are not needed.
147
165
  */
148
- export declare function readRecords(input: DataLogInput): Generator<ReadRecord>;
166
+ export declare function readRecords(input: DataLogInput): DataLogGenerator<ReadRecord>;
149
167
  /** Options for {@link decodeRecords} and {@link parseDataLog}. */
150
168
  type DecodeRecordsOptions = {
151
169
  /**
@@ -172,14 +190,7 @@ export declare function decodeRecords(records: Iterable<ReadRecord>, options?: D
172
190
  * intermediate records produced by composing {@link readRecords} and
173
191
  * {@link decodeRecords} while preserving the same output and strict-mode behavior.
174
192
  */
175
- export declare function parseDataLog(input: DataLogInput, options?: DecodeRecordsOptions): Generator<DecodedRecord>;
176
- /** An entry definition from the WPILOG catalog. */
177
- type CatalogEntry = {
178
- entryId: number;
179
- name: string;
180
- type: string;
181
- metadata: string;
182
- };
193
+ export declare function parseDataLog(input: DataLogInput, options?: DecodeRecordsOptions): DataLogGenerator<DecodedRecord>;
183
194
  /**
184
195
  * Collect all entry definitions from a WPILOG record stream.
185
196
  *
@@ -190,4 +201,4 @@ type CatalogEntry = {
190
201
  export declare function catalogEntries(records: Iterable<ReadRecord>): Generator<CatalogEntry>;
191
202
  /** Parse a WPILib struct specification string into declarations. */
192
203
  export declare function parseStructSpecification(declaration: string): import("wpilib-struct").StructDeclaration[];
193
- export { type CatalogEntry, type ControlRecord, type ControlRecordPayload, type DataLogHeader, type DataLogInput, type DataRecord, type DecodeRecordsOptions, type DecodedRecord, type EnumSpecification, type FinishControlRecord, KnownStructTypeName, type RawRecord, type ReadRecord, type SetMetadataControlRecord, type StartControlRecord, type StructDeclaration, type StructPayload, type StructSpecification, type StructTypeName };
204
+ export { type CatalogEntry, type ControlRecord, type ControlRecordPayload, type DataLogGenerator, type DataLogHeader, type DataLogInput, type DataRecord, type DecodeRecordsOptions, type DecodedRecord, type EnumSpecification, type FinishControlRecord, KnownStructTypeName, type RawRecord, type ReadRecord, type SetMetadataControlRecord, type StartControlRecord, type StructDeclaration, type StructPayload, type StructSpecification, type StructTypeName };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as readRecords, c as isDataRecord, i as withStructDiagnostics, n as decodeRecords, o as ControlRecordType, r as parseDataLog, s as RecordType, t as catalogEntries } from "./catalog-Dz8xPVYl.mjs";
1
+ import { a as readRecords, c as isDataRecord, i as withStructDiagnostics, n as decodeRecords, o as ControlRecordType, r as parseDataLog, s as RecordType, t as catalogEntries } from "./catalog-DPm4EBaR.mjs";
2
2
  import { KnownStructTypeName, parseStructSpecification as parseStructSpecification$1 } from "wpilib-struct";
3
3
  // src/struct/parse-struct.ts
4
4
  /** Parse a WPILib struct specification string into declarations. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wpilog-parser",
3
- "version": "3.2.2",
3
+ "version": "4.1.0",
4
4
  "description": "Read WPILib wpilog data log files in TypeScript & JavaScript",
5
5
  "homepage": "https://github.com/jonahsnider/wpilog-parser#readme",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@ WPILOG is the binary log format used by logging libraries in the FRC ecosystem.
22
22
 
23
23
  ## Analyzing logs
24
24
 
25
- Use `parseDataLog` to parse DataLog bytes. Filter by `name` and narrow on `type`:
25
+ Use `parseDataLog` to parse DataLog bytes. Filter by `entry.name` and narrow on `type`:
26
26
 
27
27
  ```ts
28
28
  import { readFile } from 'node:fs/promises';
@@ -33,7 +33,7 @@ const bytes = await readFile('./example.wpilog');
33
33
  for (const record of parseDataLog(bytes)) {
34
34
  if (!isDataRecord(record)) continue;
35
35
 
36
- if (record.name === '/Robot/Intake/Voltage' && record.type === RecordType.Double) {
36
+ if (record.entry.name === '/Robot/Intake/Voltage' && record.type === RecordType.Double) {
37
37
  console.log(record.timestamp, record.payload);
38
38
  }
39
39
  }
@@ -45,9 +45,9 @@ for (const record of parseDataLog(bytes)) {
45
45
  import { parseDataLog, RecordType } from 'wpilog-parser';
46
46
 
47
47
  for (const record of parseDataLog(bytes)) {
48
- if (record.type === RecordType.Struct && record.name === '/Robot/Localization/EstimatedPose') {
48
+ if (record.type === RecordType.Struct && record.entry.name === '/Robot/Localization/EstimatedPose') {
49
49
  console.log(record.timestamp, record.payload);
50
- // 18688018n {
50
+ // 18688018 {
51
51
  // translation: { x: 10.289, y: 0.47 },
52
52
  // rotation: { value: 1.5707961072652017 },
53
53
  // }
@@ -74,7 +74,7 @@ When DriverStation logging is on, every WPILOG has these `boolean` entries:
74
74
  | `/DS:test` | `true` during test mode. |
75
75
  | `/DS:estop` | `true` if e-stopped. |
76
76
 
77
- The mode flags (`autonomous`, `test`) reflect what the DS _would_ run if enabled, so check `/DS:enabled` together with them. Timestamps are microseconds (`bigint`).
77
+ The mode flags (`autonomous`, `test`) reflect what the DS _would_ run if enabled, so check `/DS:enabled` together with them. Timestamps are microseconds (`number`).
78
78
 
79
79
  ### Tracking enable/mode durations
80
80
 
@@ -91,8 +91,8 @@ function modeOf(auto: boolean, test: boolean): Mode {
91
91
  let enabled = false;
92
92
  let auto = false;
93
93
  let test = false;
94
- let enabledSince: bigint | null = null;
95
- const totals = { auto: 0n, teleop: 0n, test: 0n };
94
+ let enabledSince: number | null = null;
95
+ const totals = { auto: 0, teleop: 0, test: 0 };
96
96
 
97
97
  for (const r of parseDataLog(bytes)) {
98
98
  if (!isDataRecord(r) || r.type !== RecordType.Boolean) continue;
@@ -100,9 +100,9 @@ for (const r of parseDataLog(bytes)) {
100
100
  const wasEnabled = enabled;
101
101
  const prevMode = modeOf(auto, test);
102
102
 
103
- if (r.name === '/DS:enabled') enabled = r.payload;
104
- else if (r.name === '/DS:autonomous') auto = r.payload;
105
- else if (r.name === '/DS:test') test = r.payload;
103
+ if (r.entry.name === '/DS:enabled') enabled = r.payload;
104
+ else if (r.entry.name === '/DS:autonomous') auto = r.payload;
105
+ else if (r.entry.name === '/DS:test') test = r.payload;
106
106
  else continue;
107
107
 
108
108
  if (wasEnabled && (!enabled || modeOf(auto, test) !== prevMode)) {
@@ -113,6 +113,6 @@ for (const r of parseDataLog(bytes)) {
113
113
  }
114
114
  }
115
115
 
116
- // Durations in microseconds; divide by 1_000_000n for seconds.
116
+ // Durations in microseconds; divide by 1e6 for seconds.
117
117
  console.log(totals);
118
118
  ```