Skip to content

Commit 77b5acf

Browse files
authored
Merge pull request #14 from jsonjoy-com/copilot/fix-13
Improve documentation with centralized docs/ folder and enhanced README
2 parents e360170 + 2e59483 commit 77b5acf

File tree

6 files changed

+247
-13
lines changed

6 files changed

+247
-13
lines changed

README.md

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,51 @@
22

33
High performance JSON serialization and deserialization library for JavaScript, Node.js, browser.
44

5-
`json-pack` contains implementations of various JSON codecs into binary,
6-
formats, such as MessagePack, CBOR and other formats.
5+
`json-pack` contains implementations of various JSON codecs into binary formats, such as MessagePack, CBOR and other formats.
76

8-
- [__MessagePack__](./src/msgpack/README.md)
9-
- [__CBOR__](./src/cbor/README.md)
10-
- DAG-CBOR
11-
- JSON
12-
- DAG-JSON
13-
- UBJSON
14-
- Amazon Ion
15-
- RESP3
16-
- Bencode
7+
## Supported Formats
8+
9+
This library implements the following serialization formats:
10+
11+
- **[MessagePack](./src/msgpack/README.md)** - Fast and lean implementation of MessagePack codec
12+
- **[CBOR](./src/cbor/README.md)** - Concise Binary Object Representation codec
13+
- **[UBJSON](./src/ubjson/README.md)** - Universal Binary JSON codec
14+
- **[JSON](./src/json/README.md)** - Enhanced JSON encoder/decoder with additional features
15+
- **[JSON Binary](./src/json-binary/README.md)** - JSON with binary data support using Uint8Array
16+
- **[Amazon Ion](./src/ion/README.md)** - Amazon's Ion data serialization format
17+
- **[BSON](./src/bson/README.md)** - Binary JSON format used by MongoDB
18+
- **[RESP](./src/resp/README.md)** - Redis Serialization Protocol (v2 and v3)
19+
- **[Bencode](./src/bencode/README.md)** - BitTorrent's encoding format
20+
21+
Each format comes with optimized encoders and decoders designed for maximum performance.
22+
23+
## Installation
24+
25+
```bash
26+
npm install @jsonjoy.com/json-pack
27+
```
28+
29+
## Quick Start
30+
31+
```ts
32+
import {MessagePackEncoder, MessagePackDecoder} from '@jsonjoy.com/json-pack/lib/msgpack';
33+
34+
const encoder = new MessagePackEncoder();
35+
const decoder = new MessagePackDecoder();
36+
37+
const data = {hello: 'world', numbers: [1, 2, 3]};
38+
const binary = encoder.encode(data);
39+
const restored = decoder.decode(binary);
40+
41+
console.log(restored); // {hello: 'world', numbers: [1, 2, 3]}
42+
```
43+
44+
## Documentation
45+
46+
For detailed documentation on each codec, refer to the individual README files in their respective folders:
47+
48+
- Individual codec documentation is available in each `src/<codec>/README.md` file
49+
- Each codec includes comprehensive usage examples, API documentation, and performance benchmarks
1750

1851

1952
## Benchmarks

src/bson/README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
11
# BSON
22

3-
Performant impelementation of [BSON][bson] (Binary JSON) for JavaScript.
3+
Performant implementation of [BSON][bson] (Binary JSON) for JavaScript.
44

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

7+
## Overview
8+
9+
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.
10+
11+
## Features
12+
13+
- High-performance BSON encoding and decoding
14+
- Support for all BSON data types including:
15+
- ObjectId
16+
- Binary data
17+
- Dates
18+
- Regular expressions
19+
- JavaScript code
20+
- MongoDB-compatible implementation
21+
- Efficient binary representation
22+
23+
## Usage
24+
25+
```ts
26+
import {BsonEncoder, BsonDecoder} from 'json-pack/lib/bson';
27+
28+
const encoder = new BsonEncoder();
29+
const decoder = new BsonDecoder();
30+
31+
const data = {
32+
name: 'example',
33+
created: new Date(),
34+
binary: new Uint8Array([1, 2, 3])
35+
};
36+
37+
const encoded = encoder.encode(data);
38+
const decoded = decoder.decode(encoded);
39+
```
40+
741

842
## Benchmarks
943

src/cbor/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,84 @@
11
# `json-pack` CBOR Codec
22

3+
`json-pack` implements fast [CBOR][cbor] encoder and decoder. It is written in TypeScript
4+
and has no external dependencies.
5+
6+
[cbor]: https://cbor.io/
7+
8+
## Getting started
9+
10+
To get started you need to import `CborEncoder` and `CborDecoder` classes like
11+
this:
12+
13+
```ts
14+
import {CborEncoder} from 'json-joy/es2020/json-pack/cbor/CborEncoder';
15+
import {CborDecoder} from 'json-joy/es2020/json-pack/cbor/CborDecoder';
16+
```
17+
18+
The `CborDecoder` implements full decoding feature set including advanced
19+
features like value skipping and decoding one level at-a-time. Those features
20+
are not necessary for most use cases, to save on bundle size you can import
21+
the "base" decoder instead:
22+
23+
```ts
24+
import {CborDecoderBase} from 'json-joy/es2020/json-pack/cbor/CborDecoderBase';
25+
```
26+
27+
The base decoder implements all CBOR decoding features except for the advanced
28+
shallow decoding features, like skipping, one level at-a-time decoding.
29+
30+
## Usage
31+
32+
Encode a JavaScript POJO to CBOR:
33+
34+
```ts
35+
const encoder = new CborEncoder();
36+
37+
const pojo = {
38+
id: 123,
39+
foo: 'bar',
40+
tags: ['a', 'b', 'c'],
41+
nested: {
42+
a: 1,
43+
b: 2,
44+
level2: {
45+
c: 3,
46+
}
47+
},
48+
};
49+
50+
const encoded = encoder.encode(pojo);
51+
console.log(encoded);
52+
// Uint8Array(53) [
53+
// 164, 98, 105, 100, 24, 123, 99, 102, 111, 111,
54+
// 99, 98, 97, 114, 100, 116, 97, 103, 115, 131,
55+
// 97, 97, 97, 98, 97, 99, 120, 6, 110, 101,
56+
// 115, 116, 101, 100, 163, 97, 97, 1, 97, 98,
57+
// 2, 120, 6, 108, 101, 118, 101, 108, 50, 161,
58+
// 97, 99, 3
59+
// ]
60+
```
61+
62+
Decode CBOR back to JavaScript POJO:
63+
64+
```ts
65+
const decoderBase = new CborDecoderBase();
66+
const decoded = decoderBase.read(encoded);
67+
68+
console.log(decoded);
69+
// {
70+
// id: 123,
71+
// foo: 'bar',
72+
// tags: ['a', 'b', 'c'],
73+
// nested: {
74+
// a: 1,
75+
// b: 2,
76+
// level2: {
77+
// c: 3,
78+
// }
79+
// },
80+
// }
81+
```
382

483
## Implementation details
584

src/ion/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ for (const item of items) {
3838
```
3939

4040
This limitation primarily affects complex nested objects with many string keys. Simple data structures may work with reused instances, but fresh instances are recommended for guaranteed correctness.
41-
4241
## Benchmarks
4342

4443
Encoding:

src/json/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
# JSON Encoder/Decoder
2+
3+
Enhanced JSON implementation with high-performance encoding and decoding capabilities.
4+
5+
## Features
6+
7+
- **JsonEncoder** - High-performance JSON encoder with better performance than native `JSON.stringify`
8+
- **JsonDecoder** - Fast JSON decoder optimized for specific use cases
9+
- Support for streaming operations
10+
- Binary-safe encoding/decoding
11+
- Optimized for repeated encoding operations
12+
13+
## Usage
14+
15+
```ts
16+
import {JsonEncoder, JsonDecoder} from 'json-pack/lib/json';
17+
18+
const encoder = new JsonEncoder();
19+
const decoder = new JsonDecoder();
20+
21+
const data = {hello: 'world', numbers: [1, 2, 3]};
22+
const encoded = encoder.encode(data);
23+
const decoded = decoder.decode(encoded);
24+
```
25+
26+
## Performance
27+
28+
This JSON implementation is optimized for performance and in many cases outperforms the native `JSON.stringify()` and `JSON.parse()` methods, especially for repeated operations.
29+
130
## Benchmarks
231

332
Encoding:

src/resp/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
11
# RESP v2 and RESP3 codecs
2+
3+
Redis Serialization Protocol (RESP) implementation supporting both RESP2 and RESP3 formats.
4+
5+
## Overview
6+
7+
RESP is the protocol used by Redis to communicate between clients and servers. This implementation provides:
8+
9+
- **RESP3** encoder (`RespEncoder`) - Full support for all RESP3 data types
10+
- **RESP2** encoder (`RespEncoderLegacy`) - Legacy RESP2 support
11+
- **RESP decoder** (`RespDecoder`) - Decodes both RESP2 and RESP3 formats
12+
- **Streaming decoder** (`RespStreamingDecoder`) - For parsing streaming RESP data
13+
14+
## Supported Data Types
15+
16+
### RESP3 Types
17+
- Simple strings
18+
- Simple errors
19+
- Integers
20+
- Bulk strings
21+
- Arrays
22+
- Nulls
23+
- Booleans
24+
- Doubles
25+
- Maps
26+
- Sets
27+
- Attributes
28+
- Push messages
29+
- Verbatim strings
30+
31+
### RESP2 Types
32+
- Simple strings
33+
- Errors
34+
- Integers
35+
- Bulk strings
36+
- Arrays
37+
38+
## Usage
39+
40+
```ts
41+
import {RespEncoder, RespDecoder} from 'json-pack/lib/resp';
42+
43+
const encoder = new RespEncoder();
44+
const decoder = new RespDecoder();
45+
46+
// Encode data
47+
const data = {hello: 'world', count: 42};
48+
const encoded = encoder.encode(data);
49+
50+
// Decode data
51+
const decoded = decoder.decode(encoded);
52+
console.log(decoded); // {hello: 'world', count: 42}
53+
```
54+
55+
## Extensions
56+
57+
The RESP implementation supports Redis-specific extensions:
58+
59+
- **RespAttributes** - For attribute metadata
60+
- **RespPush** - For push messages
61+
- **RespVerbatimString** - For verbatim strings with format info

0 commit comments

Comments
 (0)