Boeuf
Boeuf is a node stream wrapper for protocol buffers. Under the hood it uses the mapbox pbf library for parsing and compiling, so can be used with either .proto
schemas or with custom read/write functions.
Usage
const boeuf = ; let ws = boeuf;let rs = boeuf; ws;ws; rsprocessstdin;
valid arguments for boeuf#readable
and boeuf#writable
are:
- a string path to a protocol buffers schema file (in which case the message name matching the name of the file given is used);
- as above but with a second argument specifying which message to use;
- a custom read or write function.
boeuf; // 1.boeuf; // 2.bouef; // 3.
Custom read/write functions
Message framing is handled by the library, so a custom read/write function need only deal with reading and writing fields. Example read and write functions are given here but more information can be found under the mapbox/pbf library.
// o = object to write as message, pbf = instance of mapbox/pbf. { if oname pbf; if oflag pbf; if osize pbf;} // tag = the protocol buffer tag, o and pbf as above, { if tag === 1 oname = pbf; if tag === 2 oflag = pbf; if tag === 3 osize = pbf;}
Multiplexing
const multiplex = ;const boeuf = ; // set up multiplexer...let multiplexer = ;let fooWritable = boeuf;let barWritable = boeuf;fooWritable;barWritable; //...somewhere else set up demultiplexerlet demultiplexer = ;let fooReadable = boeuf;let barReadable = boeuf;demultiplexer;demultiplexer; //connect the twomultiplexer; // write somethingfooWritable;barWritable;
Multiplexing can be used to send/receive different message formats over a single transport, or internally for making sure the correct message arrives at the correct parser.
Install
npm install boeuf