FrameGenerator
Transform Binary Stream to Object Stream through Generator
It's suitable for parsing protocol from binary stream
Require
node > 6
Usage
new FrameGenerator(generator);
The FrameGenerator
is inherited from Stream.Transform
.
generator
is a Generator Function, that describes a format of frame.
In the generator
, following usages are defined:
yield number
read a known lenght buffer.yield string
read buffer until the string occured.yield iterator
parse asynchronously a sub-frme.yield array
read buffer until any one string occured.return any
return a value as the frame data.
Demo
const FrameGenerator = ; let fg = { let buffer1 = length; let buffer2 = terminator; let buffer3 = ; let buffer4 strx = str1 str2 ; return buffer1 buffer2 buffer3 buffer4 ;}; inputStream