Skip to content

Prevent copying on each read in websocket #150

Description

@sergiu128

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions