Visitar URL original
Parsing binary protocols 路 Issue #31 路 nodejs/llparse 路 GitHub
Skip to content

Parsing binary protocols聽#31

Description

@arthurschreiber

I was looking through the code and noticed this project does not (yet) support parsing of binary protocols - is that something you want to add support for later? 馃檱

Activity

  1. indutny commented on Nov 28, 2019

    @indutny
    Member

    Maybe...?

  2. arthurschreiber commented on Dec 2, 2019

    @arthurschreiber
    Author

    So I played around with this a bit more.

    I added a new node type called Byte, that works like a mix between Invoke and Match - it matches any byte and then passes it on to a given code function.

    It works something like this:

    const p = new LLParse('example');
    
    p.property('i16', 'value');
    
    const uint16be = p.byte(p.code.store('value'));
    uint16be.skipTo(
      p.byte(p.code.mulAdd('value', { base: 2 ** 8 })).skipTo(uint16be)
    );
    
    const artifacts = p.build(uint16be);

    I've yet to figure the best way out to expose reading of values coming in in little endian order. 馃

    Anyway, is this how you'd implement binary reading in llparse? Or do you have any other ideas how this could be exposed in a nicer / more consistent fashion?

  3. arthurschreiber commented on Dec 2, 2019

    @arthurschreiber
    Author

    Maybe it would be better to just add two new nodes for reading signed/unsigned LE and BE encoded bytes into a field:

    const p = new LLParse('example');
    
    p.property('i8', 'type')
    p.property('i16', 'value');
    
    const type = p.uIntLE('type', 1);
    const valueLength = p.uIntLE('valueLength', 2);
    
    type.skipTo(valueLength.skipTo(p.consume('valueLength').skipTo(type)));

    This could automatically check that the field is large enough to read the required number of bytes into it.

    This would already cover most of my needs, and should be pretty straightforward to implement, I think. @indutny What do you think?

  4. Vizonex commented on May 28, 2026

    @Vizonex

    Sorry if I am choosing to reopen a dead issue but I am making a PR that attempts the same thing but is a lot simpler and has active tools to help prevent errors from occurring nodejs/llparse-builder#197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions