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

c-struct-v2

v2.0.2

Published

A C-struct library to manage binary structures with Node.JS. One bug fix of the original repo c-struct

Downloads

15

Readme

c-struct Build Status

NPM

A fast binary data packing & unpacking library for node.js designed for multiplayer games.

What can it do?

  • 8, 16, 24, 32, 40 and 48 bit signed and unsigned integers.
  • String with length and null-terminated cstrings.
  • Boolean, nibble, float and double.
  • Big and little endianness.
  • Schema based packing and unpacking.
  • Unpack from buffer to object.
  • Pack from object to buffer.
  • Pack with default value if key isn't specified.

More

  • Available via npm.
  • Zero production dependencies.

Installation

npm install c-struct --save

Execute $ node examples/ to see the examples.

Usage

Unpacking

var _ = require('c-struct');

var playerSchema = new _.Schema({
  id: _.type.uint16,
  name: _.type.string(16),
  hp: _.type.uint24,
  exp: _.type.uint32,
  status: _.type.uint8,
  motd: _.type.string(), // null-terminated if no length
  motw: _.type.string(), // cstring if no length
  skills: [{
    id: _.type.uint8,
    name: _.type.string(32),
    secret: _.type.uint40
  }],
  position: {
    x: _.type.uint16,
    y: _.type.uint16
  },
  hash: _.type.uint48
});

// register to cache
_.register('Player', playerSchema);

// object to buffer | this can be on another file
var buf = _.packSync('Player', {
  id: 1,
  name: 'Foobar',
  hp: 1000,
  exp: 88888888,
  status: 100,
  skills: [{
    id: 1,
    name: 'traps of thunder',
    secret: 5151515151
  }, {
    id: 2,
  }, {
    name: 'fatal blow'
  }, {
    id: 3,
    name: 'galvano strike'
  }],
  position: {
    x: 102,
    y: 351
  },
  motd: 'welcome',
  motw: 'weekly',
  hash: 99999999,
});

Packing

var _ = require('c-struct');

var playerSchema = new _.Schema({
  id: _.type.uint16,
  name: _.type.string(16),
  hp: _.type.uint24,
  exp: _.type.uint32,
  status: _.type.uint8,
  motd: _.type.string(), // null-terminated if no length
  motw: _.type.string(), // cstring if no length
  skills: [{
    id: _.type.uint8,
    name: _.type.string(32),
    secret: _.type.uint40
  }],
  position: {
    x: _.type.uint16,
    y: _.type.uint16
  },
  hash: _.type.uint48
});

// register to cache
_.register('Player', playerSchema);

// buffer to object | this can be on another file
var obj = _.unpackSync('Player', BUFFER_HERE);

API

Currently only unsigned values in little endian are supported

_.type.uint8    // unsigned char
_.type.uint16   // unsigned short
_.type.uint24
_.type.uint32   // unsigned long
_.type.uint40
_.type.uint48

You can also specify default values

_.type.u8(9999) // default value 9999
_.type.u16(999) // default value 999
_.type.u24(888) // default value 888
_.type.u32(777) // default value 777
_.type.u40(666) // default value 666
_.type.u48(555) // default value 555

Configurations

There is currently no configs.

TODO

  • add configurable endianness
  • add async methods
  • add signed
  • add boolean and nibble
  • add float and double
  • add benchmark
  • documentation
  • more testing