We currently have AsyncNextMessage(b []byte, ...) where the message's payload is read into b. The issue is that the payload is copied from the websocket's internal buffer into b. We can remove this copy. Two cases:
- if the message is made up of a single frame, then just return the payload of that frame in the callback of the new function
- if the message is made up of multiple frames, then return the payloads of all those frames in a callback
So the function signature would look something like this:
AsyncNextMessageDirect(func(error, MessageType, b ...[]byte))
Then callers have the option to either read the fragments one by one or reassemble them. We can help with the reassembly by introducing a new construct: FrameAssembler. I think this one just needs to concatenate all []bytes. Callers will be expected to not hold onto the []bytes after the callback returns.
We currently have
AsyncNextMessage(b []byte, ...)where the message's payload is read intob. The issue is that the payload is copied from the websocket's internal buffer intob. We can remove this copy. Two cases:So the function signature would look something like this:
Then callers have the option to either read the fragments one by one or reassemble them. We can help with the reassembly by introducing a new construct:
FrameAssembler. I think this one just needs to concatenate all[]bytes. Callers will be expected to not hold onto the[]bytes after the callback returns.