Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
I've added two methods -
parse
andrest
.parse
is taken by analogy from node-binary but still keeps this module's code small, neat and clean. It is essential for TCP framing in a stream parser. It can be useful for defining strict boundaries for data segments inside a frame or a stream (although I didn't do it in my application).rest
is an important improvement, that does not exist in node-binary or dissolve-chunks. It allows the user to cut the rest of the frame without explicitly tracking current parsing position (and needed length). Of course, frame length is defined by the length of a previously sliced staticbuffer
, but if the internal parsing routine is complicated enough (see simplified real-life example), keeping track of buffer length left is tedious; while dissolve does not export a "parser position" property, and personally, I think it should stay this way. In my example,rest
allows cutting out non-terminated or EOM terminated strings of "unknown" lengths (in the last data segment for a parsingloop
inside a data frame).dissolve-chunks, while having an interesting approach to parsing data segments (they call it "chunks"), unfortunately, only relies on fixed length known beforehand.