Extends streams.Duplex.
A finite-state machine for handling Lair protocol messsages. It has 2 states
0
- Get header1
- Get payload
The header
event is emitted as soon as 0
state (Get header) completes. The corrosponding
payload is automatically attached to the emitted request
object so that the payload
event is not
required for processing full messages.
Basic example
let parser = new MessageParser();
<some readable stream>.pipe( parser );
for await ( let req of this.parser ) {
if ( req === null )
continue;
...handle request
}
Or manual writing
let parser = new MessageParser();
parser.write( Buffer.from("00010000100000ff0100000000000000", "hex") );
for await ( let req of parser ) {
req.wire_type_id; // 4278190096
}
Iterator that yields the request
object for each header
event.
for await ( let req of parser ) {
...handle request
}
Stop all iterators next tick.
Where incoming chunks are added to the internal buffers for consumption.
Loop for processing avilable buffers until more chunks are needed.
A method for getting a given number of bytes from available buffers.
length
- the number of bytes to be consumed
Where header
bytes are parsed into request
objects and emitted.
Where payload
bytes are gathered and emitted.