Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with async streams? #27

Open
arkanoid87 opened this issue Apr 30, 2023 · 0 comments
Open

How to use with async streams? #27

arkanoid87 opened this issue Apr 30, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@arkanoid87
Copy link

arkanoid87 commented Apr 30, 2023

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?

@sealmove sealmove added the enhancement New feature or request label Jun 27, 2023
@sealmove sealmove added this to the Streaming milestone Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants