Skip to content

How to use with async streams? #27

@arkanoid87

Description

@arkanoid87

I'm trying to parse incoming TCP stream from AsyncSocket.
The natural way would be to pull data byte-by-byte according to parser definition, terminating the read when end of parser logic is reached.

but BitStream is defined as a Stream wrapper, with constructor from strings or file

type
  BitStream* = ref object
    stream: Stream
    buffer: uint64
    bitsLeft: int

This forces me to pull data from async socket into a string until I know I've read enough for the next parser.get pass.
Another workaround is pulling one byte at time and try parsing the collected buffer, if it succeeds restart for next packet, otherwise repeat.

It would be nice if the actual async pulling could be controlled by binarylang. Is there a way to make a Stream based BitStream work with an AsyncStream, or get the expected size of a parser given its arguments?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions