|
1 | 1 | # nbsjs |
2 | 2 |
|
3 | | -Node.js module for interacting with NUClear Binary Stream files |
| 3 | +[](https://github.com/Fastcode/nbsjs/actions/workflows/node.js.yml) |
| 4 | + |
| 5 | +Node.js module for interacting with [NUClear Binary Stream](https://nubook.nubots.net/system/foundations/nuclear#nbs-files) files. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +The package contains a native module, so you'll need a working C++ compiler on your system to install and build it. |
| 10 | + |
| 11 | +``` |
| 12 | +npm install nbsjs --save |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +The following example shows a typical usage pattern of creating a decoder with nbs file paths, and reading types, timestamps, and data packets. |
| 18 | + |
| 19 | +```js |
| 20 | +const { NbsDecoder } = require('nbsjs'); |
| 21 | + |
| 22 | +// Create a decoder instance |
| 23 | +const decoder = new NbsDecoder(['/path/to/file/a.nbs', '/path/to/file/b.nbs', '/path/to/file/c.nbs']); |
| 24 | + |
| 25 | +// Get a list of all types present in the NBS files, and get the first type |
| 26 | +const types = decoder.getAvailableTypes(); |
| 27 | +const firstType = types[0] |
| 28 | + |
| 29 | +// Set the timestamp range for the first available type |
| 30 | +const [start, end] = decoder.getTimestampRange(firstType); |
| 31 | + |
| 32 | +// Get the packet at the given timestamp for the first type |
| 33 | +const packets = decoder.getPackets(start, [firstType]) |
| 34 | + |
| 35 | +// Log all the values for inspection |
| 36 | +console.log({ types, firstType, start, end, packets }) |
| 37 | +``` |
| 38 | + |
| 39 | +## API |
| 40 | + |
| 41 | +See [`nbs.d.ts`](./nbs.d.ts) for API and types. |
0 commit comments