# bincoder

> A binary encoder / decoder implementation in Typescript.

Latest version **0.5.0** (published 2023-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install bincoder
pnpm add bincoder
yarn add bincoder
bun add bincoder
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2023-08-13 |
| First published | 2023-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 50.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | felicityin |
| Maintainers | felicityin |
| Keywords | bincode, rust, serde |

## Links

- npm: https://www.npmjs.com/package/bincoder
- Repository: https://github.com/felicityin/bincoder
- Homepage: https://github.com/felicityin/bincoder#readme
- Issues: https://github.com/felicityin/bincoder/issues
- npm.io page: https://npm.io/package/bincoder

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^5.1.6

## Recent versions

- 0.5.0 (latest) — 2023-08-13
- 0.4.0 — 2023-08-06
- 0.3.0 — 2023-07-23
- 0.2.2 — 2023-07-09
- 0.1.7 — 2023-07-08

## README

A binary encoder / decoder implementation in Typescript.

The repo is heavily inspired by [bincode](https://github.com/bincode-org/bincode).

# Test
```
cd bincoder
yarn
yarn run test
```

# Install

```
yarn add bincoder
```

# Example
## Basic Type
```
import { Bool } from 'bincoder';

it("Bool", () => {
  let a = new Bool(true);

  let encoded = a.pack();
  console.log(encoded);

  let [decoded, size] = new Bool().unpack(encoded);
  console.log(decoded, " ", size);

  expect(decoded).toEqual(a);
});
```

## Class
```
import { Base, Uint16, Uint32, Vec } from 'bincoder';

class SimpleArrayTest extends Base {
  a: Uint16;
  b: Vec<Uint32>;

  constructor(a: Uint16 = new Uint16(), b: Vec<Uint32> = new Vec(Uint32)) {
    super();
    this.a = a;
    this.b = b;
  }
}

it("class with simple array", () => {
  let t = new SimpleArrayTest(
    new Uint16(1),
    new Vec(Uint32, [new Uint32(2), new Uint32(3)])
  );

  let encoded = t.pack();
  console.log("encoded: ", encoded);

  let [decoded, size] = new SimpleArrayTest().unpack(encoded);
  let decodedObj = decoded as SimpleArrayTest;
  console.log("decodedObj.b.v: ", decodedObj.b.v, "size: ", size);

  expect(decodedObj.a).toEqual(t.a);
  expect(decodedObj.b.v).toEqual(t.b.v);
});
```

More examples: `./__test__/*.test.ts`

---
_Source: https://npm.io/package/bincoder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
