Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

2pack

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

2pack

Data serialization

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by14.29%
Maintainers
1
Weekly downloads
 
Created
Source
  • Binary (Little/Big - Endian)
  • Relative and absolute zero-copy operations wherever possible
  • Browser
Goals:
  1. Low memory usage;
  2. Maximum performance.
const packer = require('2pack');

const header = packer('int16');
const payload = packer(['name:str', 'hp:int16']);

//------------------------------

payload.offset = header.maxSize;

//---------]>

const id = 69;
const data = { name: 'D', hp: 13 };

const buf = header.pack(id, payload.pack(data));
const size = buf.length;

//---------]>

console.log(packer.isBE, packer.isLE);

console.log(
    header.unpack(buf, 0, size),
    payload.unpack(buf, 0, size)
);

//------------------------------

/*
packer('int16'); // primitive | returns: value
pack(0);

packer(['int16']); // array | returns: array | unpackDataAsArray = true
pack([0]);

packer(['name:str']); // object | returns: object
pack(['D']);
pack({name: 'D'});

packer(['int16', 'name:str']); // error

//----)>

unpack(bin, offset, length, cbEndInfo(offset), target, asCopy, asArray);

@bin - Buffer / Uint8Array
*/
Packet type
NameAliasNote
-
bin<size (byte)>bdefault: max 1024 (0-65535); server: Buffer; client: Uint8Array;
str<size (byte)>sdefault: max 256 (0-65535)
int<size (bit)>isize: 8, 16, 32, 64 (BigInt64Array)
uint<size (bit)>usize: 8, 16, 32, 64 (BigUint64Array)
float<size (bit)>fsize: 32, 64
json<size (byte)>jdefault: max 8192 (0-65535)

License

MIT

Keywords

FAQs

Package last updated on 22 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc