npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

msgpuck

v0.7.6

Published

A fast and memory-efficient MessagePack serialization library

Downloads

3

Readme

msgpuck

npm GitHub license Build Status Coverage Status

A fast and memory-efficient MessagePack serialization library.

Features

  • Fully compliant with the latest MessagePack specification
  • Supports low-level methods
  • Supports safe/big 64-bit integers handling
  • Supports custom Extension Types (Serialization Codecs)
  • Fully tested, including V8 JIT optimizations

Future works (not implemented yet)

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

Installation

# npm
npm install msgpuck

# yarn
yarn add msgpuck

Usage

Encoding

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

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

const encoder = new Encoder();

...

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

A list of all low-level encoder methods:

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:

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

const decoder = new Decoder();

...

decoder.decode(buffer);

Extensions

To define application-specific types use the Ext class:

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 © 2018-present Alex Masterov <[email protected]>

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