wpilog-parser 4.0.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.
- package/dist/{catalog-BPg-SswK.mjs → catalog-4hqIYGKb.mjs} +46 -12
- package/dist/cli.mjs +2 -2
- package/dist/index.d.mts +16 -3
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -221,7 +221,10 @@ var RecordCursor = class {
|
|
|
221
221
|
timestamp = 0;
|
|
222
222
|
payloadOffset = 0;
|
|
223
223
|
payloadSize = 0;
|
|
224
|
+
/** Byte offset of the next record. */
|
|
224
225
|
offset;
|
|
226
|
+
/** Whether the input ended partway through a record. */
|
|
227
|
+
truncated = false;
|
|
225
228
|
constructor(input) {
|
|
226
229
|
const source = openDataLog(input);
|
|
227
230
|
this.bytes = source.bytes;
|
|
@@ -240,6 +243,7 @@ var RecordCursor = class {
|
|
|
240
243
|
const timestampLength = 1 + (bitfield >> 4 & 7);
|
|
241
244
|
if (offset + entryIdLength + payloadSizeLength + timestampLength > total) {
|
|
242
245
|
this.offset = total;
|
|
246
|
+
this.truncated = true;
|
|
243
247
|
return false;
|
|
244
248
|
}
|
|
245
249
|
const entryId = readVarInt(view, offset, entryIdLength);
|
|
@@ -250,6 +254,7 @@ var RecordCursor = class {
|
|
|
250
254
|
offset += timestampLength;
|
|
251
255
|
if (offset + payloadSize > total) {
|
|
252
256
|
this.offset = total;
|
|
257
|
+
this.truncated = true;
|
|
253
258
|
return false;
|
|
254
259
|
}
|
|
255
260
|
this.entryId = entryId;
|
|
@@ -263,15 +268,16 @@ var RecordCursor = class {
|
|
|
263
268
|
return this.bytes.subarray(this.payloadOffset, this.payloadOffset + this.payloadSize);
|
|
264
269
|
}
|
|
265
270
|
};
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
function*
|
|
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
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function* readRawRecords(input, progress) {
|
|
274
279
|
const { bytes, view, header, recordsOffset } = openDataLog(input);
|
|
280
|
+
progress.offset = recordsOffset;
|
|
275
281
|
const total = bytes.byteLength;
|
|
276
282
|
let offset = recordsOffset;
|
|
277
283
|
yield {
|
|
@@ -283,16 +289,25 @@ function* readRecords(input) {
|
|
|
283
289
|
const entryIdLength = 1 + (bitfield & 3);
|
|
284
290
|
const payloadSizeLength = 1 + (bitfield >> 2 & 3);
|
|
285
291
|
const timestampLength = 1 + (bitfield >> 4 & 7);
|
|
286
|
-
if (offset + entryIdLength + payloadSizeLength + timestampLength > total)
|
|
292
|
+
if (offset + entryIdLength + payloadSizeLength + timestampLength > total) {
|
|
293
|
+
progress.offset = total;
|
|
294
|
+
progress.truncated = true;
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
287
297
|
const entryId = readVarInt(view, offset, entryIdLength);
|
|
288
298
|
offset += entryIdLength;
|
|
289
299
|
const payloadSize = readVarInt(view, offset, payloadSizeLength);
|
|
290
300
|
offset += payloadSizeLength;
|
|
291
301
|
const timestamp = readTimestamp(view, offset, timestampLength);
|
|
292
302
|
offset += timestampLength;
|
|
293
|
-
if (offset + payloadSize > total)
|
|
303
|
+
if (offset + payloadSize > total) {
|
|
304
|
+
progress.offset = total;
|
|
305
|
+
progress.truncated = true;
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
294
308
|
const payload = bytes.subarray(offset, offset + payloadSize);
|
|
295
309
|
offset += payloadSize;
|
|
310
|
+
progress.offset = offset;
|
|
296
311
|
if (entryId === 0) yield {
|
|
297
312
|
kind: "control",
|
|
298
313
|
entryId,
|
|
@@ -309,6 +324,20 @@ function* readRecords(input) {
|
|
|
309
324
|
};
|
|
310
325
|
}
|
|
311
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Read raw WPILOG records from an in-memory buffer.
|
|
329
|
+
*
|
|
330
|
+
* Yields a header record first, then control and data records in order.
|
|
331
|
+
* Data record payloads are not decoded. Prefer `parseDataLog` when raw records
|
|
332
|
+
* or an intermediate transformation are not needed.
|
|
333
|
+
*/
|
|
334
|
+
function readRecords(input) {
|
|
335
|
+
const progress = {
|
|
336
|
+
offset: 0,
|
|
337
|
+
truncated: false
|
|
338
|
+
};
|
|
339
|
+
return withProgress(readRawRecords(input, progress), () => progress.offset, () => progress.truncated);
|
|
340
|
+
}
|
|
312
341
|
// src/struct/diagnostics.ts
|
|
313
342
|
/** Preserve the published WPILOG diagnostics at the protocol boundary. */
|
|
314
343
|
function withStructDiagnostics(action) {
|
|
@@ -533,8 +562,13 @@ function* decodeRecords(records, options = { strict: false }) {
|
|
|
533
562
|
* intermediate records produced by composing {@link readRecords} and
|
|
534
563
|
* {@link decodeRecords} while preserving the same output and strict-mode behavior.
|
|
535
564
|
*/
|
|
536
|
-
function
|
|
565
|
+
function parseDataLog(input, options = { strict: false }) {
|
|
566
|
+
const state = {};
|
|
567
|
+
return withProgress(decodeCursorRecords(input, options, state), () => state.cursor?.offset ?? 0, () => state.cursor?.truncated ?? false);
|
|
568
|
+
}
|
|
569
|
+
function* decodeCursorRecords(input, options, state) {
|
|
537
570
|
const cursor = new RecordCursor(input);
|
|
571
|
+
state.cursor = cursor;
|
|
538
572
|
const decoder = new RecordDecoder(options);
|
|
539
573
|
while (cursor.next()) {
|
|
540
574
|
if (cursor.entryId === 0) {
|
|
@@ -565,7 +599,7 @@ function decodeNonScalarPayload(raw, entry, view, structRegistry, structDecodeQu
|
|
|
565
599
|
}
|
|
566
600
|
case "int64[]": {
|
|
567
601
|
const payload = [];
|
|
568
|
-
for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.
|
|
602
|
+
for (let i = 0; i < raw.payload.byteLength; i += 8) payload.push(view.getBigInt64(i, true));
|
|
569
603
|
return dataRecord(entry, timestamp, RecordType.Int64Array, payload);
|
|
570
604
|
}
|
|
571
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-
|
|
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.
|
|
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
|
@@ -148,6 +148,19 @@ type ReadRecord = {
|
|
|
148
148
|
};
|
|
149
149
|
/** Accepted input types for {@link readRecords} and `parseDataLog`. */
|
|
150
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
|
+
/**
|
|
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;
|
|
163
|
+
};
|
|
151
164
|
/**
|
|
152
165
|
* Read raw WPILOG records from an in-memory buffer.
|
|
153
166
|
*
|
|
@@ -155,7 +168,7 @@ type DataLogInput = Uint8Array | ArrayBuffer;
|
|
|
155
168
|
* Data record payloads are not decoded. Prefer `parseDataLog` when raw records
|
|
156
169
|
* or an intermediate transformation are not needed.
|
|
157
170
|
*/
|
|
158
|
-
export declare function readRecords(input: DataLogInput):
|
|
171
|
+
export declare function readRecords(input: DataLogInput): DataLogGenerator<ReadRecord>;
|
|
159
172
|
/** Options for {@link decodeRecords} and {@link parseDataLog}. */
|
|
160
173
|
type DecodeRecordsOptions = {
|
|
161
174
|
/**
|
|
@@ -182,7 +195,7 @@ export declare function decodeRecords(records: Iterable<ReadRecord>, options?: D
|
|
|
182
195
|
* intermediate records produced by composing {@link readRecords} and
|
|
183
196
|
* {@link decodeRecords} while preserving the same output and strict-mode behavior.
|
|
184
197
|
*/
|
|
185
|
-
export declare function parseDataLog(input: DataLogInput, options?: DecodeRecordsOptions):
|
|
198
|
+
export declare function parseDataLog(input: DataLogInput, options?: DecodeRecordsOptions): DataLogGenerator<DecodedRecord>;
|
|
186
199
|
/**
|
|
187
200
|
* Collect all entry definitions from a WPILOG record stream.
|
|
188
201
|
*
|
|
@@ -193,4 +206,4 @@ export declare function parseDataLog(input: DataLogInput, options?: DecodeRecord
|
|
|
193
206
|
export declare function catalogEntries(records: Iterable<ReadRecord>): Generator<CatalogEntry>;
|
|
194
207
|
/** Parse a WPILib struct specification string into declarations. */
|
|
195
208
|
export declare function parseStructSpecification(declaration: string): import("wpilib-struct").StructDeclaration[];
|
|
196
|
-
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 };
|
|
209
|
+
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-
|
|
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