@chengaoyuan/struct-utils
v1.0.0
Published
结构体辅助构建工具
Downloads
9
Readme
struct-utils
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