PMunch / binaryparse

Binary parser for Nim
MIT License
71 stars 6 forks source link

How to use a socket as input #6

Closed bluemax75 closed 3 years ago

bluemax75 commented 3 years ago

Is there a way of using a socket connection directly as a stream? I only see examples of StringStream and FileStream but don't know how to get data from a socket

PMunch commented 3 years ago

Unfortunately sockets don't have a stream defined for them in the stdlib. This means that you have to implement the stream interface over the stream yourself. If you look at the StreamObj you can see which procedures you'd need to implement. I don't think all of those are required for binaryparse though, and things like setPosition is only used to go forward in binaryparse so you can get away with implementing it as a writing of 0 bytes and discarding of input data for a read.

bluemax75 commented 3 years ago

Thank you for the prompt and most complete response. Thought it might be the case but wanted to make sure.