0.0.3 • Published 8 years ago

construction v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

construction

:construction: Interface with binary structures in Javascript, built for network protocols.

Build Status npm version

Features

  • Small, concise codebase with no dependencies.
  • Full test suite, testing every type.
  • Supports, Int8, Int16, Int32, UInt8, UInt16, UInt32.

To Do

  • Add char and array types.
struct User {
	uint8_t age;
	int32_t favouriteNumber;
}
const Construction = requrie("construction");
const t = Construction.types;

const User = new Construction("LE", {
	age: t.UInt8;
	favouriteNumber: t.Int32
});

API

new Construction(endianness, object)

Create a new construction object.

// Endianness can be "LE" or "BE"

const User = new Construction("LE", {
	age: t.UInt8,
	favouriteNumber: t.Int32
});

buffer Construction#write(object)

Convert a javascript object to a binary buffer.

const buffer = User.write({
	age: 15,
	favouriteNumber: 1000000
});

console.log(buffer);
// <Buffer 0f 40 42 0f 00>

object Construction#read(buffer)

Convert a binary buffer to a javascript object.

const user = User.read(Buffer.from("0f40420f00", "hex"));

console.log(user);
// { age: 15, favouriteNumber: 1000000 }
0.0.3

8 years ago

0.0.1

8 years ago

1.0.0

9 years ago