1.0.0 • Published 5 years ago

@chengaoyuan/struct-utils v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

struct-utils

npm version

install size

NPM Downloads

Build Status

Coverage Status

Installation

$ npm install @chengaoyuan/struct-utils

Usage

import * as assert from "assert";
import { toStruct, TYPES, ARRARY, ARRARY_CHAR } from "@chengaoyuan/struct-utils";
const { BYTE, WORD, DWORD, INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, FLOAT, DOUBLE } = TYPES;

class msg {
    len = DWORD;
    data = ARRARY(UINT8, 0);
}
const struct = toStruct(msg);
const arr = [1, 2, 2, 2, 3, 3, 4, 2, 3, 34, 5, 42, 2, 21, 87, 4, 3, 2];
const oldObj: msg = {
    len: arr.length,
    data: arr
};
const ab = struct.serialize(oldObj);
const newObj = struct.unserialize(ab);

assert.deepEqual(newObj, oldObj);

Testing

$ npm test