Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/montyanderson/construction
:construction: Interface with binary structures in Javascript, built for network protocols.
https://github.com/montyanderson/construction
binary buffer c construction cpp interface javascript network-protocol node
Last synced: about 1 month ago
JSON representation
:construction: Interface with binary structures in Javascript, built for network protocols.
- Host: GitHub
- URL: https://github.com/montyanderson/construction
- Owner: montyanderson
- License: mit
- Created: 2016-11-04T11:50:11.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-05T00:00:37.000Z (about 8 years ago)
- Last Synced: 2024-10-13T16:23:29.326Z (3 months ago)
- Topics: binary, buffer, c, construction, cpp, interface, javascript, network-protocol, node
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/construction
- Size: 10.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# construction
:construction: Interface with binary structures in Javascript, built for network protocols.
[![Build Status](https://travis-ci.org/montyanderson/construction.svg?branch=master)](https://travis-ci.org/montyanderson/construction) [![npm version](https://badge.fury.io/js/construction.svg)](https://badge.fury.io/js/construction)
## 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.
``` C
struct User {
uint8_t age;
int32_t favouriteNumber;
}
`````` javascript
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.
``` javascript
// 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.
``` javascript
const buffer = User.write({
age: 15,
favouriteNumber: 1000000
});console.log(buffer);
//
```### object Construction#read(buffer)
Convert a binary buffer to a javascript object.
``` javascript
const user = User.read(Buffer.from("0f40420f00", "hex"));console.log(user);
// { age: 15, favouriteNumber: 1000000 }
```