What is bser?
The 'bser' npm package is designed to encode and decode Binary Serialized Object Representation (BSER) format. BSER is a binary format used primarily for efficient data serialization and communication, particularly in applications where performance is critical. It is commonly used in conjunction with the Watchman file watching service.
Encoding to BSER
This feature allows you to encode JavaScript objects into BSER format. The example shows how to encode a simple object containing a greeting message.
const bser = require('bser');
const data = { hello: 'world' };
const encoded = bser.dumpToBuffer(data);
console.log(encoded);
Decoding from BSER
This feature enables the decoding of BSER formatted data back into JavaScript objects. The code sample demonstrates decoding a BSER encoded buffer to retrieve the original object.
const bser = require('bser');
const encoded = Buffer.from([0, 1, 3, 11, 1, 5, 104, 101, 108, 108, 111, 2, 5, 119, 111, 114, 108, 100]);
const decoded = bser.loadFromBuffer(encoded);
console.log(decoded);