@genee/struct
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

struct

A C-like struct library for buffer parsing and packing

Usage

import { struct, int16_t, uint16_t, uint8_t, LE, UINT16_MAX, INT16_MIN } from '../../lib/struct';

const SENSOR = struct({
    manufacturer: uint16_t,
    version: uint8_t,
    modeAndModel: uint8_t,
    mac: uint8_t[6],
    temperature: LE(int16_t),
    humidity: LE(uint16_t),
    pressure: LE(int16_t),
    flag: uint8_t,
    gasType: uint8_t,
    gasValue: LE(int16_t),
    gasScale: uint8_t,
    adValue: LE(uint16_t),
    battery: uint8_t,
});

const parsed = SENSOR.parse(binaryData);

parsed.humidity = 16;
const newBuf = SENSOR.update({ version: 1 }).pack(parsed);

Readme

Keywords

none

Package Sidebar

Install

npm i @genee/struct

Weekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

18.2 kB

Total Files

9

Last publish

Collaborators

  • iamfat