wpilog-parser 4.1.0 → 4.2.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.
@@ -223,6 +223,8 @@ var RecordCursor = class {
223
223
  payloadSize = 0;
224
224
  /** Byte offset of the next record. */
225
225
  offset;
226
+ /** Whether the input ended partway through a record. */
227
+ truncated = false;
226
228
  constructor(input) {
227
229
  const source = openDataLog(input);
228
230
  this.bytes = source.bytes;
@@ -241,6 +243,7 @@ var RecordCursor = class {
241
243
  const timestampLength = 1 + (bitfield >> 4 & 7);
242
244
  if (offset + entryIdLength + payloadSizeLength + timestampLength > total) {
243
245
  this.offset = total;
246
+ this.truncated = true;
244
247
  return false;
245
248
  }
246
249
  const entryId = readVarInt(view, offset, entryIdLength);
@@ -251,6 +254,7 @@ var RecordCursor = class {
251
254
  offset += timestampLength;
252
255
  if (offset + payloadSize > total) {
253
256
  this.offset = total;
257
+ this.truncated = true;
254
258
  return false;
255
259
  }
256
260
  this.entryId = entryId;
@@ -264,9 +268,12 @@ var RecordCursor = class {
264
268
  return this.bytes.subarray(this.payloadOffset, this.payloadOffset + this.payloadSize);
265
269
  }
266
270
  };
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 });
271
+ /** Expose a parser's progress on its generator without adding work to the per-record loop. */
272
+ function withProgress(records, getBytesRead, getTruncated) {
273
+ return Object.defineProperties(records, {
274
+ bytesRead: { get: getBytesRead },
275
+ truncated: { get: getTruncated }
276
+ });
270
277
  }
271
278
  function* readRawRecords(input, progress) {
272
279
  const { bytes, view, header, recordsOffset } = openDataLog(input);
@@ -284,6 +291,7 @@ function* readRawRecords(input, progress) {
284
291
  const timestampLength = 1 + (bitfield >> 4 & 7);
285
292
  if (offset + entryIdLength + payloadSizeLength + timestampLength > total) {
286
293
  progress.offset = total;
294
+ progress.truncated = true;
287
295
  return;
288
296
  }
289
297
  const entryId = readVarInt(view, offset, entryIdLength);
@@ -294,6 +302,7 @@ function* readRawRecords(input, progress) {
294
302
  offset += timestampLength;
295
303
  if (offset + payloadSize > total) {
296
304
  progress.offset = total;
305
+ progress.truncated = true;
297
306
  return;
298
307
  }
299
308
  const payload = bytes.subarray(offset, offset + payloadSize);
@@ -323,8 +332,11 @@ function* readRawRecords(input, progress) {
323
332
  * or an intermediate transformation are not needed.
324
333
  */
325
334
  function readRecords(input) {
326
- const progress = { offset: 0 };
327
- return withBytesRead(readRawRecords(input, progress), () => progress.offset);
335
+ const progress = {
336
+ offset: 0,
337
+ truncated: false
338
+ };
339
+ return withProgress(readRawRecords(input, progress), () => progress.offset, () => progress.truncated);
328
340
  }
329
341
  // src/struct/diagnostics.ts
330
342
  /** Preserve the published WPILOG diagnostics at the protocol boundary. */
@@ -552,7 +564,7 @@ function* decodeRecords(records, options = { strict: false }) {
552
564
  */
553
565
  function parseDataLog(input, options = { strict: false }) {
554
566
  const state = {};
555
- return withBytesRead(decodeCursorRecords(input, options, state), () => state.cursor?.offset ?? 0);
567
+ return withProgress(decodeCursorRecords(input, options, state), () => state.cursor?.offset ?? 0, () => state.cursor?.truncated ?? false);
556
568
  }
557
569
  function* decodeCursorRecords(input, options, state) {
558
570
  const cursor = new RecordCursor(input);
@@ -587,7 +599,7 @@ function decodeNonScalarPayload(raw, entry, view, structRegistry, structDecodeQu
587
599
  }
588
600
  case "int64[]": {
589
601
  const payload = [];
590
- for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getBigUint64(i, true));
602
+ for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getBigInt64(i, true));
591
603
  return dataRecord(entry, timestamp, RecordType.Int64Array, payload);
592
604
  }
593
605
  case "float[]": {
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-DPm4EBaR.mjs";
2
+ import { a as readRecords, l as diagnostics, t as catalogEntries } from "./catalog-4hqIYGKb.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 = "4.1.0";
10
+ var version = "4.2.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
@@ -155,6 +155,11 @@ type DataLogGenerator<T> = Generator<T> & {
155
155
  * Divide by the input's `byteLength` to estimate progress; it equals `byteLength` once parsing finishes.
156
156
  */
157
157
  readonly bytesRead: number;
158
+ /**
159
+ * Whether the input ended partway through a record, such as a log cut off by a power loss.
160
+ * The incomplete record is not yielded. This is `false` until the parser reaches the end of the input.
161
+ */
162
+ readonly truncated: boolean;
158
163
  };
159
164
  /**
160
165
  * Read raw WPILOG records from an in-memory buffer.
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-DPm4EBaR.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-4hqIYGKb.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": "4.1.0",
3
+ "version": "4.2.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",