# @cloudpss/ubjson

Opinionated UBJSON encoder/decoder for CloudPSS.

Inspired by https://bitbucket.org/shelacek/ubjson, optimized for huge objects.

## Example

```ts
import { encode, decode } from '@cloudpss/ubjson';

const bytes = encode({ foo: 'bar' });
const value = decode(bytes);
```

## API

### encode(value: unknown): Uint8Array

Encode JS value to UBJSON binary data.

`Uint8Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Float32Array`, `Float64Array` are recognized and encoded as optimized object format.
Other type of typed arrays are not supported.

### decode(value: Uint8Array): unknown

Decode UBJSON binary data to JS value.

Numeric array of optimized object format will be decoded into corresponding typed arrays.
Int64 (`L`) and high-precision number (`H`) are not supported.
