samisagit / natskell

A NATS client library written in Haskell
MIT License
5 stars 0 forks source link

TCP payload size #107

Open samisagit opened 1 year ago

samisagit commented 1 year ago

If the last message in the buffer is cut off the parser will fail if that last message is processed before the rest can be read into the buffer. If the library used some kind of internal buffer larger than the largest reasonable message size expected (max payload bytes + boiler plate + header expectation) then this would be somewhat self healing, at least in the case of many messages, since some of the messages would be popped from the buffer, leading to more writes to the buffer (hopefully getting to the end of a message).

This does add some complexity, and there doesn't seem to be a good way to predict the largest message size since headers have been added.

samisagit commented 1 year ago

I think the best way of dealing with this might be to make it configurable to the end user i.e. configure the library to expect messages of x bytes. That way the end user can define how much memory will be used to buffer the socket.