# msgpuck

> A fast and memory-efficient MessagePack serialization library

Latest version **0.7.6** (published 2018-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install msgpuck
pnpm add msgpuck
yarn add msgpuck
bun add msgpuck
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.6 |
| Published | 2018-11-02 |
| First published | 2018-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.3.0 |
| Dependencies | 2 |
| Unpacked size | 56.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Alex Masterov |
| Maintainers | asm |
| Keywords | messagepack, msgpack, binary, serialization, typescript |

## Links

- npm: https://www.npmjs.com/package/msgpuck
- Repository: https://github.com/AlexMasterov/msgpuck.js
- Homepage: https://github.com/AlexMasterov/msgpuck.js#readme
- Issues: https://github.com/AlexMasterov/msgpuck.js/issues
- npm.io page: https://npm.io/package/msgpuck

## Dependencies (2)

- [utf8-bin](https://npm.io/package/utf8-bin.md) 0.2.2
- [ascii-chr](https://npm.io/package/ascii-chr.md) 0.2.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.7.6 (latest) — 2018-11-02
- 0.7.5 — 2018-11-02
- 0.7.4 — 2018-10-29
- 0.7.3 — 2018-10-29
- 0.7.2 — 2018-10-28
- 0.7.1 — 2018-10-24
- 0.7.0 — 2018-10-21
- 0.6.2 — 2018-10-15
- 0.6.1 — 2018-10-15
- 0.6.0 — 2018-10-14
- 0.5.7 — 2018-09-29
- 0.5.6 — 2018-09-24
- 0.5.5 — 2018-09-24
- 0.5.4 — 2018-08-27
- 0.5.3 — 2018-08-25
- … 13 more at https://npm.io/package/msgpuck/versions

## README

# msgpuck

[![npm](https://img.shields.io/npm/v/msgpuck.svg)](https://www.npmjs.com/package/msgpuck)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Build Status](https://travis-ci.org/AlexMasterov/msgpuck.js.svg)](https://travis-ci.org/AlexMasterov/msgpuck.js)
[![Coverage Status](https://coveralls.io/repos/github/AlexMasterov/msgpuck.js/badge.svg?branch=master)](https://coveralls.io/github/AlexMasterov/msgpuck.js?branch=master)

A fast and memory-efficient [MessagePack](https://msgpack.org) serialization library.

## Features

- Fully compliant with the latest [MessagePack specification](https://github.com/msgpack/msgpack/blob/master/spec.md#messagepack-specification)
- Supports low-level methods
- Supports safe/big 64-bit integers handling
- Supports custom Extension Types (Serialization Codecs)
- [Fully tested](https://travis-ci.org/AlexMasterov/msgpuck.js), including V8 JIT optimizations

## Future works (not implemented yet)

- Decoder low-level methods
- Zero-copy stream handler
- Web browsers, WebAssembly, Bundler plugins

## Installation

```sh
# npm
npm install msgpuck

# yarn
yarn add msgpuck
```

## Usage

## Encoding

To encode values you can either use an instance of `Encoder`:

```javascript
const { Encoder } = require('msgpuck');

const encoder = new Encoder();

...

encoder.encode(value); // string(encoded values)
```

A list of all low-level encoder methods:

```javascript
encoder.encodeNil();                    // MP nil
encoder.encodeBool(true);               // MP bool
encoder.encodeInt(42);                  // MP int
encoder.encodeBigInt(42n);              // MP int64
encoder.encodeFloat(Math.PI);           // MP float
encoder.encodeStr('foo');               // MP str
encoder.encodeBin(Buffer.from([0x2a])); // MP bin
encoder.encodeArray([1, 2]);            // MP array
encoder.encodeObject({ key: 'value' }); // MP map
encoder.encodeMap(new Map([[1, 2]]);    // MP map
encoder.encodeExt(1, '\x2a');           // MP ext
```

### Encoding options
The `Encoder` object supports options for fine-tuning the encoding process (defaults are in bold):

| Name                 | Description                                                |
| -------------------- | ---------------------------------------------------------- |
| **float: '64'**      | Forces floats to be encoded as 64-bits MessagePack floats  |
| float: '32'          | Forces floats to be encoded as 32-bits MessagePack floats  |
| float: 'auto'        | Detects MessagePack floats type automatically              |
| bufferMinLen: **15** | The minimum length of the string to use the Buffer         |
| codecs: **false**    | An array of codecs                                         |

## Decoding

To decode data (buffer) you can either use an instance of `Decoder`:

```javascript
const { Decoder } = require('msgpuck');

const decoder = new Decoder();

...

decoder.decode(buffer);
```

## Extensions

To define application-specific types use the `Ext` class:

```javascript
const { Encoder, Decoder, Ext } = require('msgpuck');

const encoded = new Encoder().encode(Ext.make(42, '\x2a'));

const buffer = Buffer.from(encoded, 'binary');
const ext = new Decoder().decode(buffer);

console.log(ext.type === 42);     // bool(true)
console.log(ext.data === '\x2a'); // bool(true)
```

## Tests

Run tests as follows:

```
npm run test
```

## License

Copyright &#169; 2018-present Alex Masterov &lt;alex.masterow@gmail.com&gt;

msgpuck is licensed under MIT and can be used for any personal or commercial project.

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