https://github.com/agbianchessi/js-struct
C-like Structs for JavaScript.
https://github.com/agbianchessi/js-struct
binary c data struct
Last synced: 2 days ago
JSON representation
C-like Structs for JavaScript.
- Host: GitHub
- URL: https://github.com/agbianchessi/js-struct
- Owner: agbianchessi
- License: mit
- Created: 2023-04-07T12:28:34.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-21T06:39:28.000Z (about 3 years ago)
- Last Synced: 2025-09-19T08:08:50.666Z (9 months ago)
- Topics: binary, c, data, struct
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/js-struct-agb
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
JS-Struct-AGB
======
C-like Structs for JavaScript.
A browser porting of the Node.js [Struct library](https://github.com/xdenser/node-struct).
Install
============
```
npm install js-struct-agb
```
Example
=======
Define some structure:
import Struct from 'js-struct-agb';
var Person = Struct()
.chars('firstName',10)
.chars('lastName',10)
.array('items',3,'chars',10)
.word16Sle('balance'),
People = Struct()
.word8('presentCount')
.array('list',2,Person);
Now allocate buffer for it
People.allocate();
var buf = People.buffer();
Clear buffer to see how it will change later:
var buf = People.buffer();
for (var i = 0; i < buf.length ; i++) {
buf[i] = 0;
}
console.log(buf);
Output:
Now you can access memory as defined binary structure with `fields` property in a handy manner.
var proxy = People.fields;
proxy.presentCount = 2;
console.log(buf);
Output:
And so on
proxy.list[0].firstName = 'John';
console.log(buf);
Output: