Skip to content

binary protocol #6

@jimmywarting

Description

@jimmywarting

Would have been nice with a binary protocol instead of base64
base64 adds a 1/3 extra bandwidth, and it is wasteful to have to decode and encode stuff and include a base64 encoder/deocder to do so.

const ws = new WebSocket(...)
ws.binaryType = "arraybuffer";

so JSON don't fit in well when you want to send binary data. and retrieving json with binary data don't make the communication any better

  • have the first byte or something be the data.code or something
  • have the first 2-x bytes indicate how long your (possible json) message is and the rest of the binary is the actual "data.data" (aka binary payload)

and with a binary protocol then i don't mean some BSON, protobuf or any other serialization that you would need a library for IMO,
should be dependent free and easy to parse with vanilla javascript (DataView comes to mind if you need something more fancy)

TextEncoder & TextDecoder, is easy to use if you have to convert to/from string & buffer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions