Skip to content
Merged
453 changes: 39 additions & 414 deletions README.md

Large diffs are not rendered by default.

36 changes: 35 additions & 1 deletion src/bson/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
# BSON

Performant impelementation of [BSON][bson] (Binary JSON) for JavaScript.
Performant implementation of [BSON][bson] (Binary JSON) for JavaScript.

[bson]: https://bsonspec.org/

## Overview

BSON (Binary JSON) is a binary representation of JSON-like documents. It extends JSON's data model to provide additional data types, ordered fields, and efficient encoding and decoding.

## Features

- High-performance BSON encoding and decoding
- Support for all BSON data types including:
- ObjectId
- Binary data
- Dates
- Regular expressions
- JavaScript code
- MongoDB-compatible implementation
- Efficient binary representation

## Usage

```ts
import {BsonEncoder, BsonDecoder} from 'json-pack/lib/bson';

const encoder = new BsonEncoder();
const decoder = new BsonDecoder();

const data = {
name: 'example',
created: new Date(),
binary: new Uint8Array([1, 2, 3])
};

const encoded = encoder.encode(data);
const decoded = decoder.decode(encoded);
```


## Benchmarks

Expand Down
79 changes: 79 additions & 0 deletions src/cbor/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,84 @@
# `json-pack` CBOR Codec

`json-pack` implements fast [CBOR][cbor] encoder and decoder. It is written in TypeScript
and has no external dependencies.

[cbor]: https://cbor.io/

## Getting started

To get started you need to import `CborEncoder` and `CborDecoder` classes like
this:

```ts
import {CborEncoder} from 'json-joy/es2020/json-pack/cbor/CborEncoder';
import {CborDecoder} from 'json-joy/es2020/json-pack/cbor/CborDecoder';
```

The `CborDecoder` implements full decoding feature set including advanced
features like value skipping and decoding one level at-a-time. Those features
are not necessary for most use cases, to save on bundle size you can import
the "base" decoder instead:

```ts
import {CborDecoderBase} from 'json-joy/es2020/json-pack/cbor/CborDecoderBase';
```

The base decoder implements all CBOR decoding features except for the advanced
shallow decoding features, like skipping, one level at-a-time decoding.

## Usage

Encode a JavaScript POJO to CBOR:

```ts
const encoder = new CborEncoder();

const pojo = {
id: 123,
foo: 'bar',
tags: ['a', 'b', 'c'],
nested: {
a: 1,
b: 2,
level2: {
c: 3,
}
},
};

const encoded = encoder.encode(pojo);
console.log(encoded);
// Uint8Array(53) [
// 164, 98, 105, 100, 24, 123, 99, 102, 111, 111,
// 99, 98, 97, 114, 100, 116, 97, 103, 115, 131,
// 97, 97, 97, 98, 97, 99, 120, 6, 110, 101,
// 115, 116, 101, 100, 163, 97, 97, 1, 97, 98,
// 2, 120, 6, 108, 101, 118, 101, 108, 50, 161,
// 97, 99, 3
// ]
```

Decode CBOR back to JavaScript POJO:

```ts
const decoderBase = new CborDecoderBase();
const decoded = decoderBase.read(encoded);

console.log(decoded);
// {
// id: 123,
// foo: 'bar',
// tags: ['a', 'b', 'c'],
// nested: {
// a: 1,
// b: 2,
// level2: {
// c: 3,
// }
// },
// }
```

## Implementation details

Expand Down
22 changes: 22 additions & 0 deletions src/ion/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# Amazon Ion

Implementation of [Amazon Ion](https://amazon-ion.github.io/ion-docs/) data format for JavaScript.

Amazon Ion is a richly-typed, self-describing, hierarchical data serialization format offering interchangeable binary and text representations. The binary representation of Ion is efficient to parse, while the text representation is easy to author and debug.

## Features

- **IonEncoderFast** - High-performance encoder for Ion binary format
- Support for Ion's rich type system including symbols, timestamps, and annotations
- Self-describing binary format with efficient encoding

## Usage

```ts
import {IonEncoderFast} from 'json-pack/lib/ion';

const encoder = new IonEncoderFast();
const data = {name: 'example', value: 42, timestamp: new Date()};
const encoded = encoder.encode(data);
```

## Benchmarks

Encoding:
Expand Down
29 changes: 29 additions & 0 deletions src/json/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# JSON Encoder/Decoder

Enhanced JSON implementation with high-performance encoding and decoding capabilities.

## Features

- **JsonEncoder** - High-performance JSON encoder with better performance than native `JSON.stringify`
- **JsonDecoder** - Fast JSON decoder optimized for specific use cases
- Support for streaming operations
- Binary-safe encoding/decoding
- Optimized for repeated encoding operations

## Usage

```ts
import {JsonEncoder, JsonDecoder} from 'json-pack/lib/json';

const encoder = new JsonEncoder();
const decoder = new JsonDecoder();

const data = {hello: 'world', numbers: [1, 2, 3]};
const encoded = encoder.encode(data);
const decoded = decoder.decode(encoded);
```

## Performance

This JSON implementation is optimized for performance and in many cases outperforms the native `JSON.stringify()` and `JSON.parse()` methods, especially for repeated operations.

## Benchmarks

Encoding:
Expand Down
60 changes: 60 additions & 0 deletions src/resp/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
# RESP v2 and RESP3 codecs

Redis Serialization Protocol (RESP) implementation supporting both RESP2 and RESP3 formats.

## Overview

RESP is the protocol used by Redis to communicate between clients and servers. This implementation provides:

- **RESP3** encoder (`RespEncoder`) - Full support for all RESP3 data types
- **RESP2** encoder (`RespEncoderLegacy`) - Legacy RESP2 support
- **RESP decoder** (`RespDecoder`) - Decodes both RESP2 and RESP3 formats
- **Streaming decoder** (`RespStreamingDecoder`) - For parsing streaming RESP data

## Supported Data Types

### RESP3 Types
- Simple strings
- Simple errors
- Integers
- Bulk strings
- Arrays
- Nulls
- Booleans
- Doubles
- Maps
- Sets
- Attributes
- Push messages
- Verbatim strings

### RESP2 Types
- Simple strings
- Errors
- Integers
- Bulk strings
- Arrays

## Usage

```ts
import {RespEncoder, RespDecoder} from 'json-pack/lib/resp';

const encoder = new RespEncoder();
const decoder = new RespDecoder();

// Encode data
const data = {hello: 'world', count: 42};
const encoded = encoder.encode(data);

// Decode data
const decoded = decoder.decode(encoded);
console.log(decoded); // {hello: 'world', count: 42}
```

## Extensions

The RESP implementation supports Redis-specific extensions:

- **RespAttributes** - For attribute metadata
- **RespPush** - For push messages
- **RespVerbatimString** - For verbatim strings with format info