# binary-struct-ts

> Binary data structure library

Latest version **1.0.0** (published 2022-02-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install binary-struct-ts
pnpm add binary-struct-ts
yarn add binary-struct-ts
bun add binary-struct-ts
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-02-25 |
| First published | 2022-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 63.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ryan Conrad |
| Maintainers | rnconrad |

## Links

- npm: https://www.npmjs.com/package/binary-struct-ts
- Repository: https://github.com/rnconrad/binary-struct-ts
- Homepage: https://github.com/rnconrad/binary-struct-ts#readme
- Issues: https://github.com/rnconrad/binary-struct-ts/issues
- npm.io page: https://npm.io/package/binary-struct-ts

## Recent versions

- 1.0.0 (latest) — 2022-02-25

## README

# BinaryStruct.ts

A small, performant Typescript decorator-based module for working directly with
raw binary data structures.

## Examples

### Basic Usage
```ts
import { BinaryStruct, BinaryType, sizeOf, binaryStruct, binaryField } from "binary-struct-ts";

@binaryStruct()
class ExampleStruct extends BinaryStruct
{
  @binaryField(BinaryType.Int32)
  id: number;
  @binaryField(BinaryType.Float32)
  value: number;
  @binaryField(BinaryType.Uint8)
  isDeleted: number;
  @binaryField(BinaryType.BinaryStruct, AnotherStruct)
  details: AnotherStruct;
};

const data = new ExampleStruct(new ArrayBuffer(sizeOf(ExampleStruct)));
data.id = 1234;
data.value = 3.14;
data.details = anotherStructInstance;
```

### Read Structured Data
```ts
const data = new ExampleStruct(arrayBuffer, offsetBytes);
id = data.id;
value = data.value;
detailsValue = data.details.value;
```

### Copy Data
```ts
const src = new ExampleStruct(arrayBuffer, srcOffsetBytes);
const dst = new ExampleStruct(arrayBuffer, dstOffsetBytes);
dst.copyFrom(src);
```

### Additional Options
```ts
@binaryStruct({ endianness: Endianness.BigEndian,
  packingStrategy: new AlignedPackingStrategy(4) })
class ExampleStruct extends BinaryStruct
{
  @binaryField(BinaryType.Int32)
  id: number;
  @binaryField(BinaryType.Float32)
  value: number;
  @binaryField(BinaryType.Uint8)
  isDeleted: number;
  @binaryField(BinaryType.BinaryStruct, AnotherStruct)
  details: AnotherStruct;
};
```

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