Skip to content

Conversation

Vizonex
Copy link
Owner

@Vizonex Vizonex commented Sep 17, 2025

I'm going to add in integer parsing myself based off @arthurschreiber but with Indutny's requested features and nitpicks.
I will need to make a frame parser for http2 for the aiohttp developers soon since were looking into implementing http/2 protocols, however I would like something a little bit faster than python at parsing frames instead of what hyperframe does which is collecting 9 bits and then depacking. This will skip all of that and cut right to the juicy portions without bloating memory.

SEE: nodejs/llparse#32 for more details.

from llparse import LLParse

def main():
    p = LLParse("frame_parser")
    p.property("i32", "length")
    p.property("i32", "stream_id")
    p.property("i8", "type")
    p.property("i8", "flags")

    body_span = p.span(p.code.span("frame_parser__on_body"))

    root = p.uintBE("length", 3)
    ty = p.uintBE("type", 1)
    flags = p.uintBE("flags", 1)
    stream_id = p.uintBE("stream_id", 4)

    root.skipTo(ty)
    ty.skipTo(flags)
    flags.skipTo(stream_id)

    stream_id.skipTo(
        body_span.start(
            p.consume("length").otherwise(
                body_span.end(
                    p.pause(1, "waiting for next frame").otherwise(root)
                )
            )
        )
    )
    
    data = p.build(root)
    with open('frame_parser.c', 'w') as w:
        w.write(data.c)
    with open('frame_parser.h', 'w') as w:
        w.write(data.header)
    

if __name__ == "__main__":
    main()

Here's a dummy example based off RFC 9113 section 4.1

@Vizonex Vizonex changed the title add integer parsing based off https://github.com/nodejs/llparse/pull/32 add integer parsing based off https://github.com/nodejs/llparse/pull/32 And Fix Pausing Sep 17, 2025
@Vizonex Vizonex merged commit 46afdec into main Sep 17, 2025
20 checks passed
@Vizonex Vizonex deleted the protocol-features branch September 17, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant