https://github.com/softvisio-node/msgpack
https://github.com/softvisio-node/msgpack
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/softvisio-node/msgpack
- Owner: softvisio-node
- Created: 2021-06-03T04:57:37.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-22T10:19:23.000Z (over 1 year ago)
- Last Synced: 2025-01-08T21:43:32.856Z (over 1 year ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
> :information_source: Please, see the full project documentation here:
# Introduction
Fork of the `notepack.io` with improvements:
- Code optimizations.
- Streaming decoder.
- {Date} encoded with the standard msgpack protocol extension (breaking change).
- {BigInt} type support.
## Install
```sh
npm install @softvisio/msgpack
```
## Usage
```javascript
import * as msgpack from "@softvisio/msgpack";
const buffer = msgpack.encode( [ new Date() ] );
const data = msgpack.decode( buffer );
```
### msgpack.encode( data, encoding? )
- `data` {any} Data structire to encode.
- `encoding?` {string} Return string in the specified encoding.
- Returns: {Buffer|string} Encoded data. Returns {string} if `encoding` parameter is provided.
### msgpack.decode( data, encoding? )
- `data` {Buffer|ArrayBuffer|Uint8Array|string} Data to decode.
- `encoding?` {string} String encoding if `data` parameter is {string}.
- Returns: {any} Decoded data.
Throws error if unable to decode message.
### msgpack.decodeStream( data, offset )
- `data` {Buffer|ArrayBuffer|Uint8Array|string} Data to decode.
- `offset?` {integer} Offset of the message start in the passed data. **Default:** `0`.
- Returns: {Object}:
- `value` {any} Decoded data.
- `offset` {integer} Offset of the decoded message end in the passed data.
Returns {undefined} if message is incomplete.
Throws error if unable to decode message.
## Custom extensions
Specification .
| Type | Codes |
| ------------- | ----------- |
| {undefined} | `0xd4 0x00` |
| {ArrayBuffer} | `0xc7 0x00` |
| | `0xc8 0x00` |
| | `0xc9 0x09` |
| {Date} | `0xc7 0xff` |
| {BigInt} | `0xc7 0x01` |
| | `0xc8 0x01` |
| | `0xc9 0x01` |