ubx-parser 0.1.4 → 0.2.1

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A native Node.js addon for parsing [u-blox UBX binary protocol](https://www.u-blox.com/) messages (GNSS/GPS). Built with [node-addon-api](https://github.com/nodejs/node-addon-api) (N-API) and wraps the [CommsChampion](https://github.com/commschamp) ecosystem for protocol definitions.
4
4
 
5
- Supports 315+ UBX message types with sub-millisecond parsing and auto-generated TypeScript definitions.
5
+ Supports 315+ UBX message types with sub-millisecond parsing and auto-generated TypeScript definitions. Includes two complementary classes: `UbxParser` for streaming and `UbxLog` for file-based navigation.
6
6
 
7
7
  ## Installation
8
8
 
@@ -47,6 +47,45 @@ for (const msg of messages) {
47
47
  }
48
48
  ```
49
49
 
50
+ ### File-based log reader
51
+
52
+ ```js
53
+ const { UbxLog } = require('ubx-parser');
54
+
55
+ const log = await UbxLog.open('recording.ubx');
56
+
57
+ console.log(`Total messages: ${log.count()}`);
58
+ console.log(`NAV-PVT count: ${log.count('NAV-PVT')}`);
59
+ console.log(`Message types: ${log.messageTypes().join(', ')}`);
60
+
61
+ // Navigate forward
62
+ const msg = log.next('NAV-PVT');
63
+ console.log(msg);
64
+
65
+ // Get the 5th NAV-PVT message (0-based)
66
+ const fifth = log.get('NAV-PVT', 4);
67
+
68
+ // Seek to beginning and iterate
69
+ log.seek(0);
70
+ let m;
71
+ while ((m = log.next()) !== null) {
72
+ console.log(m.name);
73
+ }
74
+
75
+ log.close();
76
+ ```
77
+
78
+ `UbxLog` builds a SQLite index on first open (saved as a companion `.idx` file). Subsequent opens reuse the index for instant access. Messages are deep-parsed on demand.
79
+
80
+ ## When to use which class
81
+
82
+ | | `UbxParser` | `UbxLog` |
83
+ |---|---|---|
84
+ | **Use case** | Streaming / real-time data | Post-processing log files |
85
+ | **Input** | Byte chunks (feed incrementally) | File path |
86
+ | **Navigation** | Forward only (event-driven) | Random access, cursor-based |
87
+ | **Memory** | Buffers only partial frames | SQLite index + on-demand parsing |
88
+
50
89
  ## API
51
90
 
52
91
  ### `new UbxParser()`
@@ -70,6 +109,38 @@ Static method. Parses a complete buffer and returns all decoded messages.
70
109
 
71
110
  Static method. Returns field metadata for all supported UBX message types. Used internally by the type generation script.
72
111
 
112
+ ### `UbxLog.open(filePath: string): Promise<UbxLog>`
113
+
114
+ Static async factory. Opens a `.ubx` file, builds or reuses a companion `.idx` index, and resolves with a ready `UbxLog` instance.
115
+
116
+ ### `log.count(name?: string): number`
117
+
118
+ Returns total message count, or count of a specific message type.
119
+
120
+ ### `log.messageTypes(): string[]`
121
+
122
+ Returns an array of distinct message type names found in the file.
123
+
124
+ ### `log.next(name?: string): UbxMessage | null`
125
+
126
+ Advances the cursor and returns the next message (optionally filtered by type). Returns `null` at end.
127
+
128
+ ### `log.prev(name?: string): UbxMessage | null`
129
+
130
+ Moves the cursor backward and returns the previous message. Returns `null` at beginning.
131
+
132
+ ### `log.seek(pos: number): void`
133
+
134
+ Positions the cursor. `seek(0)` resets to the beginning. `seek(-1)` moves to the end (for backward iteration with `prev()`).
135
+
136
+ ### `log.get(name: string, ordinal: number): UbxMessage | null`
137
+
138
+ Returns the Nth message (0-based) of a given type, without affecting the cursor.
139
+
140
+ ### `log.close(): void`
141
+
142
+ Closes the file handle.
143
+
73
144
  ## TypeScript
74
145
 
75
146
  Full TypeScript definitions are included with typed interfaces for all 315+ message types and type-narrowing event listeners.
package/lib/index.js CHANGED
@@ -34,4 +34,48 @@ class UbxParser extends EventEmitter {
34
34
  }
35
35
  }
36
36
 
37
- module.exports = { UbxParser };
37
+ const NativeUbxLog = ubx.UbxLog;
38
+
39
+ class UbxLog {
40
+ /** @type {import('../types').NativeUbxLog} */
41
+ _native;
42
+
43
+ constructor(native) {
44
+ this._native = native;
45
+ }
46
+
47
+ static async open(filePath) {
48
+ const native = await NativeUbxLog.open(filePath);
49
+ return new UbxLog(native);
50
+ }
51
+
52
+ count(name) {
53
+ return name !== undefined ? this._native.count(name) : this._native.count();
54
+ }
55
+
56
+ messageTypes() {
57
+ return this._native.messageTypes();
58
+ }
59
+
60
+ next(name) {
61
+ return name !== undefined ? this._native.next(name) : this._native.next();
62
+ }
63
+
64
+ prev(name) {
65
+ return name !== undefined ? this._native.prev(name) : this._native.prev();
66
+ }
67
+
68
+ seek(pos) {
69
+ this._native.seek(pos);
70
+ }
71
+
72
+ get(name, ordinal) {
73
+ return this._native.get(name, ordinal);
74
+ }
75
+
76
+ close() {
77
+ this._native.close();
78
+ }
79
+ }
80
+
81
+ module.exports = { UbxParser, UbxLog };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ubx-parser",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "Native Node.js addon for parsing u-blox UBX binary protocol (GNSS/GPS) messages",
5
5
  "main": "lib/index.js",
6
6
  "types": "types.d.ts",
Binary file
Binary file
package/types.d.ts CHANGED
@@ -3879,3 +3879,14 @@ export declare class UbxParser {
3879
3879
  static parse(data: Uint8Array): UbxMessage[];
3880
3880
  static schema(): object[];
3881
3881
  }
3882
+
3883
+ export declare class UbxLog {
3884
+ static open(filePath: string): Promise<UbxLog>;
3885
+ count(name?: string): number;
3886
+ messageTypes(): string[];
3887
+ next(name?: string): UbxMessage | null;
3888
+ prev(name?: string): UbxMessage | null;
3889
+ seek(pos: number): void;
3890
+ get(name: string, ordinal: number): UbxMessage | null;
3891
+ close(): void;
3892
+ }