Length-Object-Binary (LOB) Packet Encoding (javascript)
This module will encode and decode LOB packets to/from JSON and Buffers.
Install: npm install lob-enc
Primary usage:
var lob = ;var json = "type":"test" "foo":"bar";var body = "any binary!";var bin = lob);// bin will be a buffer with json and body encoded var packet = lob;// packet.json == json, and packet.body == body // do both encode and decode together, for conveniencevar packet = lob; // object validatorvar bool = lob;
Also supports reading a packet in a streaming mode:
var stream = lob; var es = ;stream; // test stream in fragmentsvar bin = '001d7b2274797065223a2274657374222c22666f6f223a5b22626172225d7d616e792062696e61727921''hex';es;
Packets can be read and written in chunks:
// args.ack = true will only send one chunk until another is read, blocking/ackingvar chunk = lob; chunk; // chunks are written to socketsocket; // incoming socket data is read back as chunks chunk; // send a packet as one or more chunks
Packets can be cloaked:
var cloaked = lob;var packet = lob;// packet.cloaked = # of rounds