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

    1.0.0 • Public • Published

    struct

    npm version install size NPM Downloads Build Status Coverage Status

    Installation

    $ npm install @chengaoyuan/struct
    

    Usage

    import * as assert from "assert";
    import Struct from "@chengaoyuan/struct";
    const struct = new Struct([
        ["DWORD", "len"],
        ["UINT8", "data", 0]
    ]);
     
    const arr = [1, 2, 2, 2, 3, 3, 4, 2, 3, 34, 5, 42, 2, 21, 87, 4, 3, 2];
    const oldObj = {
        len: arr.length,
        data: arr
    };
     
    {
        const ab = struct.serialize(oldObj);
        const newObj = struct.unserialize(ab);
        assert.deepEqual(newObj, oldObj);
    }
     
    {
        const size = struct.getRealSize(oldObj);
        const buf = new ArrayBuffer(size);
        const bufView = new DataView(buf);
        struct.encode(bufView, 0, data);
        const newObj = struct.decode(bufView, 0);
        assert.deepEqual(newObj, oldObj);
    }

    Testing

    $ npm test
    

    Keywords

    Install

    npm i @chengaoyuan/struct

    DownloadsWeekly Downloads

    3

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    35.5 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar