wpilog-parser 4.0.0 → 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.
- package/dist/{catalog-BPg-SswK.mjs → catalog-DPm4EBaR.mjs} +33 -11
- package/dist/cli.mjs +2 -2
- package/dist/index.d.mts +11 -3
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -221,6 +221,7 @@ 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;
|
|
225
226
|
constructor(input) {
|
|
226
227
|
const source = openDataLog(input);
|
|
@@ -263,15 +264,13 @@ var RecordCursor = class {
|
|
|
263
264
|
return this.bytes.subarray(this.payloadOffset, this.payloadOffset + this.payloadSize);
|
|
264
265
|
}
|
|
265
266
|
};
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
*
|
|
271
|
-
* or an intermediate transformation are not needed.
|
|
272
|
-
*/
|
|
273
|
-
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) {
|
|
274
272
|
const { bytes, view, header, recordsOffset } = openDataLog(input);
|
|
273
|
+
progress.offset = recordsOffset;
|
|
275
274
|
const total = bytes.byteLength;
|
|
276
275
|
let offset = recordsOffset;
|
|
277
276
|
yield {
|
|
@@ -283,16 +282,23 @@ function* readRecords(input) {
|
|
|
283
282
|
const entryIdLength = 1 + (bitfield & 3);
|
|
284
283
|
const payloadSizeLength = 1 + (bitfield >> 2 & 3);
|
|
285
284
|
const timestampLength = 1 + (bitfield >> 4 & 7);
|
|
286
|
-
if (offset + entryIdLength + payloadSizeLength + timestampLength > total)
|
|
285
|
+
if (offset + entryIdLength + payloadSizeLength + timestampLength > total) {
|
|
286
|
+
progress.offset = total;
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
287
289
|
const entryId = readVarInt(view, offset, entryIdLength);
|
|
288
290
|
offset += entryIdLength;
|
|
289
291
|
const payloadSize = readVarInt(view, offset, payloadSizeLength);
|
|
290
292
|
offset += payloadSizeLength;
|
|
291
293
|
const timestamp = readTimestamp(view, offset, timestampLength);
|
|
292
294
|
offset += timestampLength;
|
|
293
|
-
if (offset + payloadSize > total)
|
|
295
|
+
if (offset + payloadSize > total) {
|
|
296
|
+
progress.offset = total;
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
294
299
|
const payload = bytes.subarray(offset, offset + payloadSize);
|
|
295
300
|
offset += payloadSize;
|
|
301
|
+
progress.offset = offset;
|
|
296
302
|
if (entryId === 0) yield {
|
|
297
303
|
kind: "control",
|
|
298
304
|
entryId,
|
|
@@ -309,6 +315,17 @@ function* readRecords(input) {
|
|
|
309
315
|
};
|
|
310
316
|
}
|
|
311
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
|
+
}
|
|
312
329
|
// src/struct/diagnostics.ts
|
|
313
330
|
/** Preserve the published WPILOG diagnostics at the protocol boundary. */
|
|
314
331
|
function withStructDiagnostics(action) {
|
|
@@ -533,8 +550,13 @@ function* decodeRecords(records, options = { strict: false }) {
|
|
|
533
550
|
* intermediate records produced by composing {@link readRecords} and
|
|
534
551
|
* {@link decodeRecords} while preserving the same output and strict-mode behavior.
|
|
535
552
|
*/
|
|
536
|
-
function
|
|
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) {
|
|
537
558
|
const cursor = new RecordCursor(input);
|
|
559
|
+
state.cursor = cursor;
|
|
538
560
|
const decoder = new RecordDecoder(options);
|
|
539
561
|
while (cursor.next()) {
|
|
540
562
|
if (cursor.entryId === 0) {
|
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-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 = "4.
|
|
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
|
@@ -148,6 +148,14 @@ 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
|
+
};
|
|
151
159
|
/**
|
|
152
160
|
* Read raw WPILOG records from an in-memory buffer.
|
|
153
161
|
*
|
|
@@ -155,7 +163,7 @@ type DataLogInput = Uint8Array | ArrayBuffer;
|
|
|
155
163
|
* Data record payloads are not decoded. Prefer `parseDataLog` when raw records
|
|
156
164
|
* or an intermediate transformation are not needed.
|
|
157
165
|
*/
|
|
158
|
-
export declare function readRecords(input: DataLogInput):
|
|
166
|
+
export declare function readRecords(input: DataLogInput): DataLogGenerator<ReadRecord>;
|
|
159
167
|
/** Options for {@link decodeRecords} and {@link parseDataLog}. */
|
|
160
168
|
type DecodeRecordsOptions = {
|
|
161
169
|
/**
|
|
@@ -182,7 +190,7 @@ export declare function decodeRecords(records: Iterable<ReadRecord>, options?: D
|
|
|
182
190
|
* intermediate records produced by composing {@link readRecords} and
|
|
183
191
|
* {@link decodeRecords} while preserving the same output and strict-mode behavior.
|
|
184
192
|
*/
|
|
185
|
-
export declare function parseDataLog(input: DataLogInput, options?: DecodeRecordsOptions):
|
|
193
|
+
export declare function parseDataLog(input: DataLogInput, options?: DecodeRecordsOptions): DataLogGenerator<DecodedRecord>;
|
|
186
194
|
/**
|
|
187
195
|
* Collect all entry definitions from a WPILOG record stream.
|
|
188
196
|
*
|
|
@@ -193,4 +201,4 @@ export declare function parseDataLog(input: DataLogInput, options?: DecodeRecord
|
|
|
193
201
|
export declare function catalogEntries(records: Iterable<ReadRecord>): Generator<CatalogEntry>;
|
|
194
202
|
/** Parse a WPILib struct specification string into declarations. */
|
|
195
203
|
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 };
|
|
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-
|
|
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