Node.js module for interacting with NUClear Binary Stream files.
The package contains a native module, so you'll need a working C++ compiler on your system to install and build it.
npm install nbsdecoder.js --save
This package contains classes for reading and writing nbs files.
The following example shows a typical usage pattern of creating a decoder with nbs file paths, and reading types, timestamps, and data packets.
const{ NbsDecoder }=require('nbsdecoder.js');// Create a decoder instanceconstdecoder=newNbsDecoder(['/path/to/file/a.nbs','/path/to/file/b.nbs','/path/to/file/c.nbs',]);// Get a list of all types present in the NBS files, and get the first typeconsttypes=decoder.getAvailableTypes();constfirstType=types[0];// Set the timestamp range for the first available typeconst[start,end]=decoder.getTimestampRange(firstType);// Get the packet at the given timestamp for the first typeconstpackets=decoder.getPackets(start,[firstType]);// Log all the values for inspectionconsole.log({ types, firstType, start, end, packets });The following example shows a typical usage pattern of creating an encoder with an nbs file path and writing a packet to it.
const{ NbsEncoder }=require('nbsdecoder.js');// Create an encoder instanceconstencoder=newNbsEncoder('/path/to/new/file.nbs');// Create a packet to write to the fileconstpacket={// Timestamp that the packet was emittedtimestamp: {seconds: 2000,nanos: 0},// The nuclear hash of the message type name (In this example 'message.Ping')type: Buffer.from('8ce1582fa0eadc84','hex'),// Optional subtype of the packetsubtype: 0,// Bytes of the payloadpayload: Buffer.from('Message','utf8'),};// Write the packet to the fileencoder.write(packet);// Close the file readerencoder.close();See nbsdecoder.d.ts for API and types.