# socket.io-msgpack-parser

> socket.io parser based on msgpack

Latest version **3.0.2** (published 2022-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install socket.io-msgpack-parser
pnpm add socket.io-msgpack-parser
yarn add socket.io-msgpack-parser
bun add socket.io-msgpack-parser
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2022-11-14 |
| First published | 2017-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 74 |
| Author | Damien Arrachequesne |
| Maintainers | darrachequesne |

## Links

- npm: https://www.npmjs.com/package/socket.io-msgpack-parser
- Repository: https://github.com/socketio/socket.io-msgpack-parser
- Homepage: https://github.com/socketio/socket.io-msgpack-parser#readme
- Issues: https://github.com/socketio/socket.io-msgpack-parser/issues
- npm.io page: https://npm.io/package/socket.io-msgpack-parser

## Dependencies (2)

- [notepack.io](https://npm.io/package/notepack.io.md) ~2.2.0
- [component-emitter](https://npm.io/package/component-emitter.md) ~1.3.0

## Recent versions

- 3.0.2 (latest) — 2022-11-14
- 3.0.1 — 2020-10-27
- 3.0.0 — 2020-10-23
- 2.2.1 — 2020-09-28
- 2.2.0 — 2017-08-09
- 2.1.0 — 2017-05-29
- 2.0.0 — 2017-05-08
- 1.0.3 — 2017-05-04
- 1.0.2 — 2017-05-04
- 1.0.1 — 2017-04-27
- 1.0.0 — 2017-02-21

## README

# socket.io-msgpack-parser

An alternative to the default [socket.io-parser](https://github.com/socketio/socket.io-parser), encoding and decoding packets with [msgpack](http://msgpack.org/).

With that parser, the browser build will be a bit heavier (an additional 7.5 KB minified, 3.0 KB gzipped), but each message will be smaller (sent as binary).

Please note that you MUST use the parser on both sides (server & client).

See also:

- the default parser: https://github.com/socketio/socket.io-parser
- a parser based on JSON.stringify/parse: https://github.com/darrachequesne/socket.io-json-parser

Compatibility table:

| Parser version | Socket.IO server version |
|----------------| ------------------------ |
| 2.x            | 1.x / 2.x                |
| 3.x            | 3.x / 4.x                |

## Usage

```js
const io = require('socket.io');
const ioc = require('socket.io-client');
const customParser = require('socket.io-msgpack-parser');

const server = io(PORT, {
  parser: customParser
});

const socket = ioc('ws://localhost:' + PORT, {
  parser: customParser
});

socket.on('connect', () => {
  socket.emit('hello');
});
```

## Format

`socket.emit('hello', 'you')` will create the following packet:

```json
{
  "type": 2,
  "nsp": "/",
  "data": ["hello", "you"]
}
```

which will be encoded by the parser as:

`<Buffer 83 a4 74 79 70 65 02 a3 6e 73 70 a1 2f a4 64 61 74 61 92 a5 68 65 6c 6c 6f a3 79 6f 75>`

More information about the exchange protocol can be found [here](https://github.com/socketio/socket.io-protocol).

---
_Source: https://npm.io/package/socket.io-msgpack-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
