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

pintpack

v0.0.1

Published

Super fast key value serialization.

Downloads

4

Readme

PintPack Build Status

Super fast key value serialization.

PintPack is a very fast and lightweight key/value serializer from object to Buffer and back again.

PintPack is more than 2x faster than JSON.parse and more than 4x faster than JSON.stringify. Designed to replace JSON, BSON or MessagePack etc where speed matters more than having deep nested objects. PintPack only supports single level unnested keys and values, EG: {foo:'bar', num:555}.

Installation

npm install pintpack

Examples

var pintpack = require('pintpack');

// first define a schema to use.
var schema = pintpack.schema(
  {
    schema: 
      [
        { key: 'foo', type: 'ascii', length: 3 },   // length can be greater than value.
        { key: 'num', type: 'U32int' } 
      ]
  }
);

// can now encode (to Buffer) values for the schema.
var encoded = pintpack.encode(['bar', 123456789], schema);    // values in array, schema to use.

console.log('encoded', encoded);    // <Buffer  00 00 00 00 00 00 00 00 00 00 62 61 72 07 5b cd 15>


// decode (Buffer to object) values using the schema.
var decoded = pintpack.decode(encoded);

console.log('decoded', decoded);    // schema object with values.

All the value types and options:

var pintpack = require('pintpack');

var schema = pintpack.schema(
  { client: new Buffer('abcd1234'),
    schema: 
      [
        { key: 'text', type: 'ascii', length: 5 },  // can set length greater than value.
        { key: 'buf', type: 'Buffer', length: 4 },
        { key: 'bool', type: 'boolean' },
        { key: 'nada', type: 'null' },
        { key: 'undef', type: 'undefined' },
        { key: 'uint32', type: 'U32int' },
        { key: 'uint16', type: 'U16int' },
        { key: 'uint8', type: 'U8int' }           
      ]
  }
);

var encoded = pintpack.encode(['hello', new Buffer('abcd'), true, null, undefined, 123456789, 65535, 255], schema);   // values in array, schema obj to use.
console.log('encoded', encoded);

var decoded = pintpack.decode(encoded, schema);		// can include schema to use.
console.log('decoded', decoded);

Supported Value Types

  • ascii (set length).
  • Buffer (set length).
  • boolean
  • null
  • undefined
  • U32int (unsigned 32 bit integer).
  • U16int (unsigned 16 bit integer).
  • U8int (unsigned 8 bit integer).

PintPack Protocol

The protocol consists of having a separate schema defining the keys and a separate binary object holding the values. The values object is encoded and decoded using the same schema - a id is assigned to both the schema and values.

The PintPack Protocol is designed for implemented in any programing language.

Schema

The schema is an array of key/values, each item sets the key name, type and length (if not set by the type). The array item order matches the values object, its order is strict. The schema can also be set with a client identifier (as a 8 byte Buffer) and will be assigned a id number per client (upto 65,535) - this will be used when decoding to match the assigned schema.

Values

The values is a array of the keys' values in binary. The first 8 bytes are to assign the client identifier, the next 2 bytes are used to assign the client id number - followed by the values in the order corresponding with the schema array of values, the order is strict.

Example

If the schema was:

var schema = pintpack.schema(
  {
    client: new Buffer('abcdefgh'),
    schema: 
      [
        { key: 'foo', type: 'ascii', length: 3 },   // length can be greater than value.
        { key: 'num', type: 'U32int' } 
      ]
  }
);

The values would be (shown is spaced hexadecimal):
+------------------------+-----+--------+------------+
| 61 62 63 64 65 66 67 68 00 00 62 61 72 07 5b cd 15 |
+------------------------+-----+--------+------------+
| CLIENT                 | ID  | f o o  | 123456789  |                                        |
+------------------------------+---------------------+
|                              | VALUES              |
+------------------------------+--------+------------+


Values octet structure:
+----------------------------------------------------------------+
| VALUE OBJECT (binary)                                          |
+--------+-----------------+------+-----------------+------------+
|        | CLIENT          | ID   | VALUE[0]        | NEXT VALUE |
+--------+-----------------+------+-----------------+------------+
| OCTETS | 0,1,2,3,4,5,6,7 | 8,9  | <KEY[0].LENGTH> | ...        |
+--------+-----------------+------+------------+-----------------+

License

Choose either: MIT or Apache 2.0.