Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koerismo/struxt
Dynamic data structures for Javascript.
https://github.com/koerismo/struxt
binary javascript struct typescript
Last synced: about 1 month ago
JSON representation
Dynamic data structures for Javascript.
- Host: GitHub
- URL: https://github.com/koerismo/struxt
- Owner: koerismo
- Created: 2022-06-20T01:29:34.000Z (over 2 years ago)
- Default Branch: v3-alpha
- Last Pushed: 2023-12-26T07:10:36.000Z (about 1 year ago)
- Last Synced: 2024-02-20T17:18:19.747Z (11 months ago)
- Topics: binary, javascript, struct, typescript
- Language: TypeScript
- Homepage:
- Size: 226 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Struxt
Struxt is a portable zero-dependency library that abstracts binary packing/unpacking into reusable structures.## An Introduction
Rewritten from the ground up, struxt v3 allows developers to define data structures on-the-fly with Javascript code. This iteration features an api inspired by `smart-buffer` which allows data to be packed and unpacked via pointer methods.## Examples
```js
import { Struct, Literal } from 'struxt';const PlayerData = new Struct(ptr => {
// allocate 1 byte of data to a new pointer
const len_ptr = ptr.defer(1);// write some data
ptr.f32('position', 3);
ptr.f32('rotation', 3);
ptr.u8('health');
ptr.str('name');// write the chunk length to the allocated byte as a uint8
len_ptr.u8(Literal( ptr.position() - 1 ));
});
```