Back to Socket Io

Socket.IO custom parsers

examples/custom-parsers/README.md

4.7.51.7 KB
Original Source

Socket.IO custom parsers

Since Socket.IO version 2.0.0, you can provide your custom parser, according to the needs of your application.

Several parsers are showcased here:

They are tested with various payloads:

  • string: ['1', '2', ... '1000']
  • numeric: [1, 2, ... 1000]
  • binary: Buffer.allocUnsafe(1000), where buf[i] = i

How to use

$ npm i && npm start

Results

bytes / packetCONNECT packetstringnumericbinary
default15903390443 + 1000
msgpack20391926461029
JSON20593039313625
schemapack20389520051005

Comparison

default parser

  • supports any serializable datastructure, including Blob and File
  • but binary payload is encoded as 2 packets

msgpack

  • the size of payloads containing mostly numeric values will be greatly reduced
  • but rely on ArrayBuffer in the browser (IE > 9)

JSON

  • optimized
  • but does not support binary payloads

schemapack

  • the most efficient in both speed and size
  • but you have to provide a schema for each packet