cborg 2.0.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +16 -0
- package/.github/workflows/test-and-release.yml +63 -0
- package/CHANGELOG.md +332 -0
- package/bench/bench.js +117 -0
- package/bench/json.js +124 -0
- package/bench/package.json +8 -0
- package/lib/bin.js +1 -1
- package/package.json +30 -47
- package/types/lib/bin.d.ts +1 -0
- package/cjs/browser-test/appendix_a.js +0 -643
- package/cjs/browser-test/common.js +0 -24
- package/cjs/browser-test/node-test-bin.js +0 -348
- package/cjs/browser-test/noop-bin-test.js +0 -4
- package/cjs/browser-test/test-0uint.js +0 -158
- package/cjs/browser-test/test-1negint.js +0 -152
- package/cjs/browser-test/test-2bytes.js +0 -254
- package/cjs/browser-test/test-3string.js +0 -144
- package/cjs/browser-test/test-4array.js +0 -200
- package/cjs/browser-test/test-5map.js +0 -667
- package/cjs/browser-test/test-6tag.js +0 -75
- package/cjs/browser-test/test-7float.js +0 -253
- package/cjs/browser-test/test-bl.js +0 -91
- package/cjs/browser-test/test-cbor-vectors.js +0 -98
- package/cjs/browser-test/test-decode-errors.js +0 -77
- package/cjs/browser-test/test-fuzz.js +0 -56
- package/cjs/browser-test/test-json.js +0 -281
- package/cjs/browser-test/test-length.js +0 -63
- package/cjs/cborg.js +0 -14
- package/cjs/lib/0uint.js +0 -163
- package/cjs/lib/1negint.js +0 -63
- package/cjs/lib/2bytes.js +0 -62
- package/cjs/lib/3string.js +0 -46
- package/cjs/lib/4array.js +0 -51
- package/cjs/lib/5map.js +0 -51
- package/cjs/lib/6tag.js +0 -36
- package/cjs/lib/7float.js +0 -188
- package/cjs/lib/bin.js +0 -139
- package/cjs/lib/bl.js +0 -77
- package/cjs/lib/byte-utils.js +0 -245
- package/cjs/lib/common.js +0 -22
- package/cjs/lib/decode.js +0 -140
- package/cjs/lib/diagnostic.js +0 -124
- package/cjs/lib/encode.js +0 -248
- package/cjs/lib/is.js +0 -87
- package/cjs/lib/json/decode.js +0 -414
- package/cjs/lib/json/encode.js +0 -161
- package/cjs/lib/json/json.js +0 -12
- package/cjs/lib/jump.js +0 -174
- package/cjs/lib/length.js +0 -36
- package/cjs/lib/token.js +0 -46
- package/cjs/node-test/appendix_a.js +0 -643
- package/cjs/node-test/common.js +0 -24
- package/cjs/node-test/node-test-bin.js +0 -348
- package/cjs/node-test/noop-bin-test.js +0 -4
- package/cjs/node-test/test-0uint.js +0 -158
- package/cjs/node-test/test-1negint.js +0 -152
- package/cjs/node-test/test-2bytes.js +0 -254
- package/cjs/node-test/test-3string.js +0 -144
- package/cjs/node-test/test-4array.js +0 -200
- package/cjs/node-test/test-5map.js +0 -667
- package/cjs/node-test/test-6tag.js +0 -75
- package/cjs/node-test/test-7float.js +0 -253
- package/cjs/node-test/test-bl.js +0 -91
- package/cjs/node-test/test-cbor-vectors.js +0 -98
- package/cjs/node-test/test-decode-errors.js +0 -77
- package/cjs/node-test/test-fuzz.js +0 -56
- package/cjs/node-test/test-json.js +0 -281
- package/cjs/node-test/test-length.js +0 -63
- package/cjs/taglib.js +0 -44
- package/cli.js +0 -7
- package/esm/browser-test/appendix_a.js +0 -640
- package/esm/browser-test/common.js +0 -19
- package/esm/browser-test/node-test-bin.js +0 -339
- package/esm/browser-test/noop-bin-test.js +0 -1
- package/esm/browser-test/test-0uint.js +0 -155
- package/esm/browser-test/test-1negint.js +0 -149
- package/esm/browser-test/test-2bytes.js +0 -252
- package/esm/browser-test/test-3string.js +0 -141
- package/esm/browser-test/test-4array.js +0 -197
- package/esm/browser-test/test-5map.js +0 -664
- package/esm/browser-test/test-6tag.js +0 -78
- package/esm/browser-test/test-7float.js +0 -250
- package/esm/browser-test/test-bl.js +0 -84
- package/esm/browser-test/test-cbor-vectors.js +0 -95
- package/esm/browser-test/test-decode-errors.js +0 -69
- package/esm/browser-test/test-fuzz.js +0 -50
- package/esm/browser-test/test-json.js +0 -279
- package/esm/browser-test/test-length.js +0 -55
- package/esm/cborg.js +0 -12
- package/esm/lib/0uint.js +0 -152
- package/esm/lib/1negint.js +0 -55
- package/esm/lib/2bytes.js +0 -59
- package/esm/lib/3string.js +0 -43
- package/esm/lib/4array.js +0 -41
- package/esm/lib/5map.js +0 -41
- package/esm/lib/6tag.js +0 -27
- package/esm/lib/7float.js +0 -179
- package/esm/lib/bin.js +0 -137
- package/esm/lib/bl.js +0 -74
- package/esm/lib/byte-utils.js +0 -228
- package/esm/lib/common.js +0 -19
- package/esm/lib/decode.js +0 -139
- package/esm/lib/diagnostic.js +0 -123
- package/esm/lib/encode.js +0 -246
- package/esm/lib/is.js +0 -81
- package/esm/lib/json/decode.js +0 -413
- package/esm/lib/json/encode.js +0 -160
- package/esm/lib/json/json.js +0 -10
- package/esm/lib/jump.js +0 -168
- package/esm/lib/length.js +0 -31
- package/esm/lib/token.js +0 -43
- package/esm/node-test/appendix_a.js +0 -640
- package/esm/node-test/common.js +0 -19
- package/esm/node-test/node-test-bin.js +0 -339
- package/esm/node-test/noop-bin-test.js +0 -1
- package/esm/node-test/test-0uint.js +0 -155
- package/esm/node-test/test-1negint.js +0 -149
- package/esm/node-test/test-2bytes.js +0 -252
- package/esm/node-test/test-3string.js +0 -141
- package/esm/node-test/test-4array.js +0 -197
- package/esm/node-test/test-5map.js +0 -664
- package/esm/node-test/test-6tag.js +0 -78
- package/esm/node-test/test-7float.js +0 -250
- package/esm/node-test/test-bl.js +0 -84
- package/esm/node-test/test-cbor-vectors.js +0 -95
- package/esm/node-test/test-decode-errors.js +0 -69
- package/esm/node-test/test-fuzz.js +0 -50
- package/esm/node-test/test-json.js +0 -279
- package/esm/node-test/test-length.js +0 -55
- package/esm/package.json +0 -4
- package/esm/taglib.js +0 -37
- package/index.js +0 -1
- package/json +0 -1
- package/length +0 -1
- package/taglib +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: 'github-actions'
|
|
4
|
+
directory: '/'
|
|
5
|
+
schedule:
|
|
6
|
+
interval: 'daily'
|
|
7
|
+
commit-message:
|
|
8
|
+
prefix: 'chore'
|
|
9
|
+
include: 'scope'
|
|
10
|
+
- package-ecosystem: 'npm'
|
|
11
|
+
directory: '/'
|
|
12
|
+
schedule:
|
|
13
|
+
interval: 'daily'
|
|
14
|
+
commit-message:
|
|
15
|
+
prefix: 'chore'
|
|
16
|
+
include: 'scope'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
name: Test & Maybe Release
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
jobs:
|
|
4
|
+
test:
|
|
5
|
+
strategy:
|
|
6
|
+
fail-fast: false
|
|
7
|
+
matrix:
|
|
8
|
+
node: [16.x, 18.x, lts/*, current]
|
|
9
|
+
os: [macos-latest, ubuntu-latest, windows-latest]
|
|
10
|
+
runs-on: ${{ matrix.os }}
|
|
11
|
+
steps:
|
|
12
|
+
- name: Checkout Repository
|
|
13
|
+
uses: actions/checkout@v4
|
|
14
|
+
- name: Use Node.js ${{ matrix.node }}
|
|
15
|
+
uses: actions/setup-node@v3.8.1
|
|
16
|
+
with:
|
|
17
|
+
node-version: ${{ matrix.node }}
|
|
18
|
+
- name: Install Dependencies
|
|
19
|
+
run: |
|
|
20
|
+
npm install --no-progress
|
|
21
|
+
- name: Run tests
|
|
22
|
+
run: |
|
|
23
|
+
npm config set script-shell bash
|
|
24
|
+
npm run test:ci
|
|
25
|
+
- name: Typecheck
|
|
26
|
+
uses: gozala/typescript-error-reporter-action@v1.0.9
|
|
27
|
+
release:
|
|
28
|
+
name: Release
|
|
29
|
+
needs: test
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
|
32
|
+
steps:
|
|
33
|
+
- name: Checkout
|
|
34
|
+
uses: actions/checkout@v4
|
|
35
|
+
with:
|
|
36
|
+
fetch-depth: 0
|
|
37
|
+
- name: Setup Node.js
|
|
38
|
+
uses: actions/setup-node@v3.8.1
|
|
39
|
+
with:
|
|
40
|
+
node-version: lts/*
|
|
41
|
+
- name: Install dependencies
|
|
42
|
+
run: |
|
|
43
|
+
npm install --no-progress --no-package-lock --no-save
|
|
44
|
+
- name: Build
|
|
45
|
+
run: |
|
|
46
|
+
npm run build
|
|
47
|
+
- name: Install plugins
|
|
48
|
+
run: |
|
|
49
|
+
npm install \
|
|
50
|
+
@semantic-release/commit-analyzer \
|
|
51
|
+
conventional-changelog-conventionalcommits \
|
|
52
|
+
@semantic-release/release-notes-generator \
|
|
53
|
+
@semantic-release/npm \
|
|
54
|
+
@semantic-release/github \
|
|
55
|
+
@semantic-release/git \
|
|
56
|
+
@semantic-release/changelog \
|
|
57
|
+
--no-progress --no-package-lock --no-save
|
|
58
|
+
- name: Release
|
|
59
|
+
env:
|
|
60
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
61
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
62
|
+
run: npx semantic-release
|
|
63
|
+
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
## [2.0.5](https://github.com/rvagg/cborg/compare/v2.0.4...v2.0.5) (2023-08-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Trivial Changes
|
|
5
|
+
|
|
6
|
+
* **deps-dev:** bump typescript from 5.1.6 to 5.2.2 ([4518600](https://github.com/rvagg/cborg/commit/451860087ae73f1aeaffcfa5fe64ecca068412e8))
|
|
7
|
+
* **deps:** bump actions/setup-node from 3.8.0 to 3.8.1 ([148013b](https://github.com/rvagg/cborg/commit/148013b2eb28453a6fad2d14ceb07080127574b9))
|
|
8
|
+
|
|
9
|
+
## [2.0.4](https://github.com/rvagg/cborg/compare/v2.0.3...v2.0.4) (2023-08-14)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Trivial Changes
|
|
13
|
+
|
|
14
|
+
* **deps:** bump actions/setup-node from 3.7.0 to 3.8.0 ([3c5c865](https://github.com/rvagg/cborg/commit/3c5c86584793f9a256b19b1efd20f29cfd05bcce))
|
|
15
|
+
|
|
16
|
+
## [2.0.3](https://github.com/rvagg/cborg/compare/v2.0.2...v2.0.3) (2023-07-07)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Trivial Changes
|
|
20
|
+
|
|
21
|
+
* **deps:** bump actions/setup-node from 3.6.0 to 3.7.0 ([6dccb1c](https://github.com/rvagg/cborg/commit/6dccb1c90d319b004f3be228aa4bc9c9994970b8))
|
|
22
|
+
|
|
23
|
+
## [2.0.2](https://github.com/rvagg/cborg/compare/v2.0.1...v2.0.2) (2023-06-28)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Trivial Changes
|
|
27
|
+
|
|
28
|
+
* **deps-dev:** bump typescript from 5.0.4 to 5.1.5 ([e5ed650](https://github.com/rvagg/cborg/commit/e5ed650051efb63cd55a2f7ab3d6c0768aea3b0d))
|
|
29
|
+
* **deps:** bump gozala/typescript-error-reporter-action ([9ac5f4a](https://github.com/rvagg/cborg/commit/9ac5f4a2a542b9f4eec61e5bce1e6a9d2c49a951))
|
|
30
|
+
|
|
31
|
+
## [2.0.1](https://github.com/rvagg/cborg/compare/v2.0.0...v2.0.1) (2023-06-14)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Trivial Changes
|
|
35
|
+
|
|
36
|
+
* **deps-dev:** bump c8 from 7.14.0 to 8.0.0 ([26e0a62](https://github.com/rvagg/cborg/commit/26e0a62143af996ff2abcb8741b51e7bde8f7a85))
|
|
37
|
+
|
|
38
|
+
## [2.0.0](https://github.com/rvagg/cborg/compare/v1.10.2...v2.0.0) (2023-06-14)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### ⚠ BREAKING CHANGES
|
|
42
|
+
|
|
43
|
+
* drop Node.js 14.x support
|
|
44
|
+
|
|
45
|
+
### Trivial Changes
|
|
46
|
+
|
|
47
|
+
* drop Node.js 14.x support ([cc28594](https://github.com/rvagg/cborg/commit/cc28594041204a80d5f722c137f41dd9ebc5b987))
|
|
48
|
+
|
|
49
|
+
## [1.10.2](https://github.com/rvagg/cborg/compare/v1.10.1...v1.10.2) (2023-05-17)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Trivial Changes
|
|
53
|
+
|
|
54
|
+
* **deps-dev:** bump polendina from 3.1.0 to 3.2.1 ([6098702](https://github.com/rvagg/cborg/commit/6098702f415a1e15a6d5a1fb3d630ebdce31cdfd))
|
|
55
|
+
|
|
56
|
+
## [1.10.1](https://github.com/rvagg/cborg/compare/v1.10.0...v1.10.1) (2023-03-17)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Bug Fixes
|
|
60
|
+
|
|
61
|
+
* release with Node.js 18 ([e1de3dc](https://github.com/rvagg/cborg/commit/e1de3dcb2376149c6db18bbb46a4dee6dd3bae3c))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Trivial Changes
|
|
65
|
+
|
|
66
|
+
* **deps-dev:** bump typescript from 4.9.5 to 5.0.2 ([46974d7](https://github.com/rvagg/cborg/commit/46974d7dd5eed6b7f776990ba81b33360333f56e))
|
|
67
|
+
|
|
68
|
+
## [1.10.0](https://github.com/rvagg/cborg/compare/v1.9.6...v1.10.0) (2023-01-06)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Features
|
|
72
|
+
|
|
73
|
+
* add rejectDuplicateMapKeys option (default false) ([450bc8c](https://github.com/rvagg/cborg/commit/450bc8c68006eb109c671084c5ff5dd22dc64e7a))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### Trivial Changes
|
|
77
|
+
|
|
78
|
+
* **no-release:** bump actions/setup-node from 3.5.1 to 3.6.0 ([#73](https://github.com/rvagg/cborg/issues/73)) ([a7d9e99](https://github.com/rvagg/cborg/commit/a7d9e99662eaf0b020b0124fceba56810d8a55d0))
|
|
79
|
+
* **no-release:** update node.js versions in CI ([6fe4131](https://github.com/rvagg/cborg/commit/6fe4131cc00a1c9c824974afb28eba7f6fea9ef1))
|
|
80
|
+
|
|
81
|
+
## [1.9.6](https://github.com/rvagg/cborg/compare/v1.9.5...v1.9.6) (2022-11-15)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
### Trivial Changes
|
|
85
|
+
|
|
86
|
+
* **deps-dev:** bump typescript from 4.8.4 to 4.9.3 ([#66](https://github.com/rvagg/cborg/issues/66)) ([38fc1c8](https://github.com/rvagg/cborg/commit/38fc1c862625bcab76340398897c0a2d928dc482))
|
|
87
|
+
* **no-release:** bump actions/setup-node from 3.4.1 to 3.5.0 ([#64](https://github.com/rvagg/cborg/issues/64)) ([927189a](https://github.com/rvagg/cborg/commit/927189a130d579fba41f62c327042d9166d32714))
|
|
88
|
+
* **no-release:** bump actions/setup-node from 3.5.0 to 3.5.1 ([#65](https://github.com/rvagg/cborg/issues/65)) ([d06f0c9](https://github.com/rvagg/cborg/commit/d06f0c9308627e3bdf2026be5ff4c05ab958b99d))
|
|
89
|
+
|
|
90
|
+
## [1.9.5](https://github.com/rvagg/cborg/compare/v1.9.4...v1.9.5) (2022-08-26)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Trivial Changes
|
|
94
|
+
|
|
95
|
+
* **deps-dev:** bump typescript from 4.7.4 to 4.8.2 ([#63](https://github.com/rvagg/cborg/issues/63)) ([b28e7de](https://github.com/rvagg/cborg/commit/b28e7defe986bfa134a8f1a9b9ea71f60682dbd3))
|
|
96
|
+
* **no-release:** bump actions/setup-node from 3.2.0 to 3.3.0 ([#59](https://github.com/rvagg/cborg/issues/59)) ([5f317db](https://github.com/rvagg/cborg/commit/5f317db133d5dd6b6eac369819860351b77a0954))
|
|
97
|
+
* **no-release:** bump actions/setup-node from 3.3.0 to 3.4.0 ([#61](https://github.com/rvagg/cborg/issues/61)) ([a104eb7](https://github.com/rvagg/cborg/commit/a104eb73f3b9e12fd30556e1ed9db017ca4b3b73))
|
|
98
|
+
* **no-release:** bump actions/setup-node from 3.4.0 to 3.4.1 ([#62](https://github.com/rvagg/cborg/issues/62)) ([883b273](https://github.com/rvagg/cborg/commit/883b273a68b08361a7cc8cb5f4f8be6aa8ae7ccc))
|
|
99
|
+
* **no-release:** bump ipld-garbage from 4.0.10 to 5.0.0 ([#60](https://github.com/rvagg/cborg/issues/60)) ([42e6f9a](https://github.com/rvagg/cborg/commit/42e6f9a20a1dcce5061c0a493931e4a060f1442e))
|
|
100
|
+
|
|
101
|
+
### [1.9.4](https://github.com/rvagg/cborg/compare/v1.9.3...v1.9.4) (2022-05-25)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### Trivial Changes
|
|
105
|
+
|
|
106
|
+
* **deps-dev:** bump typescript from 4.6.4 to 4.7.2 ([b3a63e5](https://github.com/rvagg/cborg/commit/b3a63e594afed42af0fbdd1f9f098ac31bc727b8))
|
|
107
|
+
|
|
108
|
+
### [1.9.3](https://github.com/rvagg/cborg/compare/v1.9.2...v1.9.3) (2022-05-19)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### Bug Fixes
|
|
112
|
+
|
|
113
|
+
* allow diag output to deal with integers outside of safe range ([5d4ed2c](https://github.com/rvagg/cborg/commit/5d4ed2c7e6f00db40150cb6e56c859bfb965d752))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### Trivial Changes
|
|
117
|
+
|
|
118
|
+
* **no-release:** bump actions/setup-node from 3.1.1 to 3.2.0 ([#57](https://github.com/rvagg/cborg/issues/57)) ([9594b16](https://github.com/rvagg/cborg/commit/9594b160dd9613baac0dadb14ee6e139c2c36853))
|
|
119
|
+
|
|
120
|
+
### [1.9.2](https://github.com/rvagg/cborg/compare/v1.9.1...v1.9.2) (2022-05-12)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
### Bug Fixes
|
|
124
|
+
|
|
125
|
+
* rework lib/bin.js inclusion in ipjx compile chain ([7b3cd32](https://github.com/rvagg/cborg/commit/7b3cd3297b174b42cf1c8fe480c8df430415db6e))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
### Trivial Changes
|
|
129
|
+
|
|
130
|
+
* **deps-dev:** bump mocha from 9.2.2 to 10.0.0 ([67db9a3](https://github.com/rvagg/cborg/commit/67db9a39991e0ac163d08870a93ef015510d8d35))
|
|
131
|
+
* **no-release:** bump polendina from 2.0.15 to 3.0.0 ([#54](https://github.com/rvagg/cborg/issues/54)) ([84e8037](https://github.com/rvagg/cborg/commit/84e80374a1a3c0ecaea8be67fd0b054a7d9422e3))
|
|
132
|
+
* **no-release:** bump polendina from 3.0.0 to 3.1.0 ([#55](https://github.com/rvagg/cborg/issues/55)) ([57a47f8](https://github.com/rvagg/cborg/commit/57a47f81ceacef6a00dcabf37befcefb2cd40860))
|
|
133
|
+
|
|
134
|
+
### [1.9.1](https://github.com/rvagg/cborg/compare/v1.9.0...v1.9.1) (2022-04-20)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### Bug Fixes
|
|
138
|
+
|
|
139
|
+
* standard@17 getting picky about ternaries ([5069065](https://github.com/rvagg/cborg/commit/50690659bfbf3fce871eeff6d311ec30bf6b9813))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
### Trivial Changes
|
|
143
|
+
|
|
144
|
+
* **deps-dev:** bump standard from 16.0.4 to 17.0.0 ([291c6ca](https://github.com/rvagg/cborg/commit/291c6ca23f302aec8e74363a039ba4b0696faf9f))
|
|
145
|
+
* **no-release:** bump actions/setup-node from 3.0.0 to 3.1.0 ([#49](https://github.com/rvagg/cborg/issues/49)) ([61e25e0](https://github.com/rvagg/cborg/commit/61e25e03481cebd7b3e25c0c42388b68df1f0474))
|
|
146
|
+
* **no-release:** bump actions/setup-node from 3.1.0 to 3.1.1 ([#51](https://github.com/rvagg/cborg/issues/51)) ([2993a82](https://github.com/rvagg/cborg/commit/2993a82d90197f424ca04041d5721ac16dbf1618))
|
|
147
|
+
|
|
148
|
+
## [1.9.0](https://github.com/rvagg/cborg/compare/v1.8.1...v1.9.0) (2022-03-30)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
### Features
|
|
152
|
+
|
|
153
|
+
* add encodedLength() function ([#48](https://github.com/rvagg/cborg/issues/48)) ([e8be1c0](https://github.com/rvagg/cborg/commit/e8be1c0f2cbe5b889cbf21a16693ec37cee1a1d6))
|
|
154
|
+
|
|
155
|
+
### [1.8.1](https://github.com/rvagg/cborg/compare/v1.8.0...v1.8.1) (2022-03-02)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
### Trivial Changes
|
|
159
|
+
|
|
160
|
+
* **deps-dev:** bump typescript from 4.5.5 to 4.6.2 ([#46](https://github.com/rvagg/cborg/issues/46)) ([cfe6aab](https://github.com/rvagg/cborg/commit/cfe6aab0cb2c67b61b4621d510d1df3d87485ff8))
|
|
161
|
+
* **no-release:** bump actions/checkout from 2.4.0 to 3 ([#45](https://github.com/rvagg/cborg/issues/45)) ([6620054](https://github.com/rvagg/cborg/commit/6620054274fc768ee5e874de1c590f929d331314))
|
|
162
|
+
|
|
163
|
+
## [1.8.0](https://github.com/rvagg/cborg/compare/v1.7.0...v1.8.0) (2022-02-25)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
### Features
|
|
167
|
+
|
|
168
|
+
* **string:** add `retainStringBytes` decode option, better non-unicode & non-printable diag output ([770dd6e](https://github.com/rvagg/cborg/commit/770dd6e2ad8da4b394164d42822b84805429c9ff))
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
### Trivial Changes
|
|
172
|
+
|
|
173
|
+
* **no-release:** bump actions/setup-node from 2.5.1 to 3.0.0 ([#44](https://github.com/rvagg/cborg/issues/44)) ([149afe0](https://github.com/rvagg/cborg/commit/149afe0f2a61084f0d29e3b49515fe4cef945e41))
|
|
174
|
+
|
|
175
|
+
## [1.7.0](https://github.com/rvagg/cborg/compare/v1.6.2...v1.7.0) (2022-02-21)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
### Features
|
|
179
|
+
|
|
180
|
+
* **cli:** add diag2* commands, minor diag fixes, README update ([bb52262](https://github.com/rvagg/cborg/commit/bb5226268bd7ed4170ff5a6230998cacf0397231))
|
|
181
|
+
|
|
182
|
+
### [1.6.2](https://github.com/rvagg/cborg/compare/v1.6.1...v1.6.2) (2022-02-21)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### Bug Fixes
|
|
186
|
+
|
|
187
|
+
* **diagnostic:** rework indenting algorithm to better handle recursives ([af47da1](https://github.com/rvagg/cborg/commit/af47da12835bd6d82982784ca4cd8903c4a966f1))
|
|
188
|
+
|
|
189
|
+
### [1.6.1](https://github.com/rvagg/cborg/compare/v1.6.0...v1.6.1) (2022-01-17)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### Bug Fixes
|
|
193
|
+
|
|
194
|
+
* **diagnostic:** handle zero-length recursives properly in diag output ([38ec7ea](https://github.com/rvagg/cborg/commit/38ec7ea054726bb8d71cc836019949e6b0e28d78))
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
### Trivial Changes
|
|
198
|
+
|
|
199
|
+
* **no-release:** bump actions/setup-node from 2.5.0 to 2.5.1 ([#38](https://github.com/rvagg/cborg/issues/38)) ([d46fae2](https://github.com/rvagg/cborg/commit/d46fae2c02641ddda0dfab21aa028d06ae6a8c13))
|
|
200
|
+
|
|
201
|
+
## [1.6.0](https://github.com/rvagg/cborg/compare/v1.5.4...v1.6.0) (2021-12-13)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
### Features
|
|
205
|
+
|
|
206
|
+
* add support for coerceUndefinedToNull option ([fd61bbe](https://github.com/rvagg/cborg/commit/fd61bbe95bfbc255fa371ae8e1e241a96f31e211))
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
### Trivial Changes
|
|
210
|
+
|
|
211
|
+
* test and document coerceUndefinedToNull ([61fd015](https://github.com/rvagg/cborg/commit/61fd0150be586aef5518f2fa9f64456639bd2011))
|
|
212
|
+
* update deps & test setup ([1246122](https://github.com/rvagg/cborg/commit/1246122ace46bbc6ba18b07a66afd4cfb057a3e7))
|
|
213
|
+
|
|
214
|
+
### [1.5.4](https://github.com/rvagg/cborg/compare/v1.5.3...v1.5.4) (2021-12-08)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
### Bug Fixes
|
|
218
|
+
|
|
219
|
+
* remove 'util' dependency ([875d5ea](https://github.com/rvagg/cborg/commit/875d5ea6cf226c6db8fc0a3fce6089592c9aadcd))
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
### Trivial Changes
|
|
223
|
+
|
|
224
|
+
* **deps-dev:** bump polendina from 1.1.1 to 2.0.0 ([9aeed6b](https://github.com/rvagg/cborg/commit/9aeed6bd2bbec7996b16dc8c2e00daa06721527e))
|
|
225
|
+
* expand browser testing to esm ([cc2a626](https://github.com/rvagg/cborg/commit/cc2a6261a9600abf005e46dc799940dca6626aaf))
|
|
226
|
+
* **no-release:** bump actions/setup-node from 2.4.1 to 2.5.0 ([#32](https://github.com/rvagg/cborg/issues/32)) ([5f7dba1](https://github.com/rvagg/cborg/commit/5f7dba1d1ade3e3da13db18d16635c2e01e71334))
|
|
227
|
+
|
|
228
|
+
### [1.5.3](https://github.com/rvagg/cborg/compare/v1.5.2...v1.5.3) (2021-11-04)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
### Trivial Changes
|
|
232
|
+
|
|
233
|
+
* **deps:** bump actions/checkout from 2.3.5 to 2.4.0 ([8a76824](https://github.com/rvagg/cborg/commit/8a7682419ebc854cf83395627d67823e0403ef46))
|
|
234
|
+
|
|
235
|
+
### [1.5.2](https://github.com/rvagg/cborg/compare/v1.5.1...v1.5.2) (2021-10-18)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
### Trivial Changes
|
|
239
|
+
|
|
240
|
+
* **deps,no-release:** bump actions/checkout from 2.3.4 to 2.3.5 ([#29](https://github.com/rvagg/cborg/issues/29)) ([fd0db75](https://github.com/rvagg/cborg/commit/fd0db75e19690541969d2aac8fb0d7d940be72a1))
|
|
241
|
+
|
|
242
|
+
### [1.5.1](https://github.com/rvagg/cborg/compare/v1.5.0...v1.5.1) (2021-09-28)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
### Trivial Changes
|
|
246
|
+
|
|
247
|
+
* **deps:** bump actions/setup-node from 2.4.0 to 2.4.1 ([a7a1d0c](https://github.com/rvagg/cborg/commit/a7a1d0cd11ce59481d8b1a0b9120cec27fda835d))
|
|
248
|
+
|
|
249
|
+
## [1.5.0](https://github.com/rvagg/cborg/compare/v1.4.2...v1.5.0) (2021-08-25)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
### Features
|
|
253
|
+
|
|
254
|
+
* enhance CLI - more commands & accept stdin ([333b379](https://github.com/rvagg/cborg/commit/333b379190b9a27ce9ab4811a8417a566eaeb7ed))
|
|
255
|
+
|
|
256
|
+
### [1.4.2](https://github.com/rvagg/cborg/compare/v1.4.1...v1.4.2) (2021-08-23)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
### Bug Fixes
|
|
260
|
+
|
|
261
|
+
* add a decimal point for whole number float tokens ([3a18861](https://github.com/rvagg/cborg/commit/3a18861dd8faff2af6ebd06f82b2d1a6dc691fbc))
|
|
262
|
+
|
|
263
|
+
### [1.4.1](https://github.com/rvagg/cborg/compare/v1.4.0...v1.4.1) (2021-08-05)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
### Trivial Changes
|
|
267
|
+
|
|
268
|
+
* **deps:** bump actions/setup-node from 2.3.2 to 2.4.0 ([eda1936](https://github.com/rvagg/cborg/commit/eda19366cb093caac5f3ce6e5bb94bd9b94dc988))
|
|
269
|
+
|
|
270
|
+
## [1.4.0](https://github.com/rvagg/cborg/compare/v1.3.8...v1.4.0) (2021-08-05)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
### Features
|
|
274
|
+
|
|
275
|
+
* handle JSON decoding of large integers as BigInt ([dc87eb4](https://github.com/rvagg/cborg/commit/dc87eb47f7afcd71d51f2d849a92951567f9d565))
|
|
276
|
+
* use `allowBigInt` option so BigInt handling isn't a breaking change ([66d61b5](https://github.com/rvagg/cborg/commit/66d61b51ada9e5f189d4fbc0f52b2423052f5bb1))
|
|
277
|
+
|
|
278
|
+
### [1.3.8](https://github.com/rvagg/cborg/compare/v1.3.7...v1.3.8) (2021-08-05)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
### Trivial Changes
|
|
282
|
+
|
|
283
|
+
* **deps:** bump actions/setup-node from 2.3.1 to 2.3.2 ([3a3cdc1](https://github.com/rvagg/cborg/commit/3a3cdc18ef9aaccff971950279a5470623841b53))
|
|
284
|
+
|
|
285
|
+
### [1.3.7](https://github.com/rvagg/cborg/compare/v1.3.6...v1.3.7) (2021-08-03)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
### Trivial Changes
|
|
289
|
+
|
|
290
|
+
* **deps:** bump actions/setup-node from 2.3.0 to 2.3.1 ([8cd4583](https://github.com/rvagg/cborg/commit/8cd45837e249f23558f08dfa60193a020571a7d7))
|
|
291
|
+
|
|
292
|
+
### [1.3.6](https://github.com/rvagg/cborg/compare/v1.3.5...v1.3.6) (2021-07-20)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
### Trivial Changes
|
|
296
|
+
|
|
297
|
+
* **deps:** bump actions/setup-node from 2.2.0 to 2.3.0 ([7d4a786](https://github.com/rvagg/cborg/commit/7d4a786217281b0041d3003cf96246eca85a8630))
|
|
298
|
+
|
|
299
|
+
### [1.3.5](https://github.com/rvagg/cborg/compare/v1.3.4...v1.3.5) (2021-07-01)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
### Trivial Changes
|
|
303
|
+
|
|
304
|
+
* **deps:** bump actions/setup-node from 2.1.5 to 2.2.0 ([661f195](https://github.com/rvagg/cborg/commit/661f195ebccf6da72e92478b8f3ba98c7b5a7f7c))
|
|
305
|
+
|
|
306
|
+
### [1.3.4](https://github.com/rvagg/cborg/compare/v1.3.3...v1.3.4) (2021-06-08)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
### Trivial Changes
|
|
310
|
+
|
|
311
|
+
* **deps-dev:** bump mocha from 8.4.0 to 9.0.0 ([8ad0905](https://github.com/rvagg/cborg/commit/8ad0905f714a82a431e50d07390d2fc5f80070e8))
|
|
312
|
+
|
|
313
|
+
### [1.3.3](https://github.com/rvagg/cborg/compare/v1.3.2...v1.3.3) (2021-05-31)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
### Trivial Changes
|
|
317
|
+
|
|
318
|
+
* **deps-dev:** bump ipld-garbage from 3.0.6 to 4.0.1 ([1615ec2](https://github.com/rvagg/cborg/commit/1615ec2251afed7bad4eb581c4975bf4913a10f7))
|
|
319
|
+
|
|
320
|
+
### [1.3.2](https://github.com/rvagg/cborg/compare/v1.3.1...v1.3.2) (2021-05-28)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
### Bug Fixes
|
|
324
|
+
|
|
325
|
+
* handle tag indenting properly with diagnostic output ([5312923](https://github.com/rvagg/cborg/commit/5312923c5feb05224dd920efa4e7735208e971fe))
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
### Trivial Changes
|
|
329
|
+
|
|
330
|
+
* add semantic-release for auto-releases ([155de4c](https://github.com/rvagg/cborg/commit/155de4c06e00bfbbeb397f0b31142dc6a609c742))
|
|
331
|
+
* s/15/16 in node test matrix ([363920f](https://github.com/rvagg/cborg/commit/363920f48af7592453f630d6102db2714ebaa92c))
|
|
332
|
+
* **deps:** bump actions/checkout from 2 to 2.3.4 ([0846f50](https://github.com/rvagg/cborg/commit/0846f502204660ca3c7d76d675edff315a8695c7))
|
package/bench/bench.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// can be run in a browser with `polendina --runner=bare-sync --timeout 6000 --cleanup bench.js`
|
|
2
|
+
// with additional dependencies for cborg installed here
|
|
3
|
+
|
|
4
|
+
import assert from 'assert'
|
|
5
|
+
import { garbage } from 'ipld-garbage'
|
|
6
|
+
import { decode, encode } from '../cborg.js'
|
|
7
|
+
import borc from 'borc'
|
|
8
|
+
|
|
9
|
+
let writebuf = ''
|
|
10
|
+
const write = process.stdout
|
|
11
|
+
? process.stdout.write.bind(process.stdout)
|
|
12
|
+
: (str) => {
|
|
13
|
+
writebuf += str
|
|
14
|
+
if (str.endsWith('\n')) {
|
|
15
|
+
console.log(writebuf.replace(/\n$/, ''))
|
|
16
|
+
writebuf = ''
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function runWith (description, count, targetTime, size, options) {
|
|
21
|
+
let borcDecoder = null
|
|
22
|
+
const borcDecode = (bytes) => {
|
|
23
|
+
if (!borcDecoder) {
|
|
24
|
+
// account for initial allocation & setup time in benchmark
|
|
25
|
+
borcDecoder = new borc.Decoder({ size: 10 * 1024 * 1024 })
|
|
26
|
+
}
|
|
27
|
+
return borcDecoder.decodeAll(bytes)[0]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const fixtures = []
|
|
31
|
+
|
|
32
|
+
console.log(`${description} @ ${count.toLocaleString()}`)
|
|
33
|
+
for (let i = 0; i < count; i++) {
|
|
34
|
+
const obj = garbage(size, options)
|
|
35
|
+
const cbyts = encode(obj)
|
|
36
|
+
/*
|
|
37
|
+
const bbyts = borc.encode(obj)
|
|
38
|
+
if (Buffer.compare(Buffer.from(cbyts), bbyts) !== 0) {
|
|
39
|
+
console.log(`mismatch for obj: ${JSON.stringify(obj)}`)
|
|
40
|
+
console.log('\t', Buffer.from(cbyts).toString('hex'))
|
|
41
|
+
console.log('\t', Buffer.from(bbyts).toString('hex'))
|
|
42
|
+
}
|
|
43
|
+
*/
|
|
44
|
+
if (cbyts.length <= size * 2) {
|
|
45
|
+
fixtures.push([obj, cbyts])
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const avgSize = Math.round(fixtures.reduce((p, c) => p + c[1].length, 0) / fixtures.length)
|
|
49
|
+
|
|
50
|
+
const enc = (encoder) => {
|
|
51
|
+
for (const [obj, byts] of fixtures) {
|
|
52
|
+
const ebyts = encoder(obj)
|
|
53
|
+
if (byts.length !== ebyts.length) {
|
|
54
|
+
throw new Error('bork')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return fixtures.length
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const bench = (bfn) => {
|
|
61
|
+
const start = Date.now()
|
|
62
|
+
let opcount = 0
|
|
63
|
+
do {
|
|
64
|
+
opcount += bfn()
|
|
65
|
+
} while (Date.now() - start < targetTime)
|
|
66
|
+
const ops = Math.round(opcount / ((Date.now() - start) / 1000))
|
|
67
|
+
return ops
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const dec = (decoder) => {
|
|
71
|
+
for (const [obj, byts] of fixtures) {
|
|
72
|
+
const cobj = decoder(byts)
|
|
73
|
+
if (obj != null && typeof obj === 'object') {
|
|
74
|
+
assert.deepStrictEqual(Object.keys(cobj).length, Object.keys(obj).length)
|
|
75
|
+
} else {
|
|
76
|
+
assert.deepStrictEqual(obj, cobj)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return fixtures.length
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const cmp = (desc, cbfn, bofn) => {
|
|
83
|
+
write(`\t${desc} (avg ${avgSize.toLocaleString()} b):`)
|
|
84
|
+
const cborgOps = bench(cbfn)
|
|
85
|
+
write(` cborg @ ${cborgOps.toLocaleString()} op/s`)
|
|
86
|
+
const borcOps = bench(bofn)
|
|
87
|
+
write(` / borc @ ${borcOps.toLocaleString()} op/s`)
|
|
88
|
+
const percent = Math.round((cborgOps / borcOps) * 1000) / 10
|
|
89
|
+
write(` = ${(percent).toLocaleString()} %\n`)
|
|
90
|
+
return percent
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return [
|
|
94
|
+
cmp('encode', () => enc(encode), () => enc(borc.encode)),
|
|
95
|
+
cmp('decode', () => dec(decode), () => dec(borcDecode))
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const targetTime = 1000
|
|
100
|
+
const accum = []
|
|
101
|
+
accum.push(runWith('rnd-100', 1000, targetTime, 100, { weights: { CID: 0 } }))
|
|
102
|
+
accum.push(runWith('rnd-300', 1000, targetTime, 300, { weights: { CID: 0 } }))
|
|
103
|
+
accum.push(runWith('rnd-nomap-300', 1000, targetTime, 300, { weights: { CID: 0, map: 0 } }))
|
|
104
|
+
accum.push(runWith('rnd-nolist-300', 1000, targetTime, 300, { weights: { CID: 0, list: 0 } }))
|
|
105
|
+
accum.push(runWith('rnd-nofloat-300', 1000, targetTime, 300, { weights: { CID: 0, float: 0 } }))
|
|
106
|
+
accum.push(runWith('rnd-nomaj7-300', 1000, targetTime, 300, { weights: { CID: 0, float: 0, null: 0, boolean: 0 } }))
|
|
107
|
+
accum.push(runWith('rnd-nostr-300', 1000, targetTime, 300, { weights: { CID: 0, string: 0, bytes: 0 } }))
|
|
108
|
+
accum.push(runWith('rnd-nostrbyts-300', 1000, targetTime, 300, { weights: { CID: 0, string: 0 } }))
|
|
109
|
+
accum.push(runWith('rnd-1000', 1000, targetTime, 1000, { weights: { CID: 0 } }))
|
|
110
|
+
accum.push(runWith('rnd-2000', 1000, targetTime, 2000, { weights: { CID: 0 } }))
|
|
111
|
+
accum.push(runWith('rnd-fil-100', 1000, targetTime, 100, { weights: { float: 0, map: 0, CID: 0 } }))
|
|
112
|
+
accum.push(runWith('rnd-fil-300', 1000, targetTime, 300, { weights: { float: 0, map: 0, CID: 0 } }))
|
|
113
|
+
accum.push(runWith('rnd-fil-500', 1000, targetTime, 500, { weights: { float: 0, map: 0, CID: 0 } }))
|
|
114
|
+
accum.push(runWith('rnd-fil-1000', 1000, targetTime, 1000, { weights: { float: 0, map: 0, CID: 0 } }))
|
|
115
|
+
accum.push(runWith('rnd-fil-2000', 1000, targetTime, 2000, { weights: { float: 0, map: 0, CID: 0 } }))
|
|
116
|
+
console.log(`Avg encode: ${Math.round(accum.reduce((p, c) => p + c[0], 0) / accum.length).toLocaleString()} %`)
|
|
117
|
+
console.log(`Avg decode: ${Math.round(accum.reduce((p, c) => p + c[1], 0) / accum.length).toLocaleString()} %`)
|
package/bench/json.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// can be run in a browser with `polendina --runner=bare-sync --timeout 6000 --cleanup bench.js`
|
|
2
|
+
// with additional dependencies for cborg installed here
|
|
3
|
+
|
|
4
|
+
import assert from 'assert'
|
|
5
|
+
import { garbage } from 'ipld-garbage'
|
|
6
|
+
import { decode, encode } from '../lib/json/json.js'
|
|
7
|
+
|
|
8
|
+
let writebuf = ''
|
|
9
|
+
const write = process.stdout
|
|
10
|
+
? process.stdout.write.bind(process.stdout)
|
|
11
|
+
: (str) => {
|
|
12
|
+
writebuf += str
|
|
13
|
+
if (str.endsWith('\n')) {
|
|
14
|
+
console.log(writebuf.replace(/\n$/, ''))
|
|
15
|
+
writebuf = ''
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const textEncoder = new TextEncoder()
|
|
20
|
+
const textDecoder = new TextDecoder()
|
|
21
|
+
|
|
22
|
+
function jencode (obj) {
|
|
23
|
+
return textEncoder.encode(JSON.stringify(obj))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function jdecode (buf) {
|
|
27
|
+
return JSON.parse(textDecoder.decode(buf))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function runWith (description, count, targetTime, size, options) {
|
|
31
|
+
const fixtures = []
|
|
32
|
+
|
|
33
|
+
console.log(`${description} @ ${count.toLocaleString()}`)
|
|
34
|
+
for (let i = 0; i < count; i++) {
|
|
35
|
+
const obj = garbage(size, options)
|
|
36
|
+
const cbyts = encode(obj)
|
|
37
|
+
/*
|
|
38
|
+
const jbyts = jencode(obj)
|
|
39
|
+
if (Buffer.compare(Buffer.from(cbyts), jbyts) !== 0) {
|
|
40
|
+
console.log(`mismatch for obj: ${JSON.stringify(obj)}`)
|
|
41
|
+
console.log('\tc> ', Buffer.from(cbyts).toString('utf8'))
|
|
42
|
+
console.log('\tj> ', Buffer.from(jbyts).toString('utf8'))
|
|
43
|
+
}
|
|
44
|
+
*/
|
|
45
|
+
if (cbyts.length <= size * 2) {
|
|
46
|
+
fixtures.push([obj, cbyts])
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const avgSize = Math.round(fixtures.reduce((p, c) => p + c[1].length, 0) / fixtures.length)
|
|
50
|
+
|
|
51
|
+
const enc = (encoder) => {
|
|
52
|
+
for (const [obj, byts] of fixtures) {
|
|
53
|
+
const ebyts = encoder(obj)
|
|
54
|
+
if (byts.length !== ebyts.length) {
|
|
55
|
+
throw new Error('bork')
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return fixtures.length
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const bench = (bfn) => {
|
|
62
|
+
const start = Date.now()
|
|
63
|
+
let opcount = 0
|
|
64
|
+
do {
|
|
65
|
+
opcount += bfn()
|
|
66
|
+
} while (Date.now() - start < targetTime)
|
|
67
|
+
const ops = Math.round(opcount / ((Date.now() - start) / 1000))
|
|
68
|
+
return ops
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const dec = (decoder) => {
|
|
72
|
+
for (const [obj, byts] of fixtures) {
|
|
73
|
+
let cobj
|
|
74
|
+
try {
|
|
75
|
+
cobj = decoder(byts)
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.log('Failed to decode:', Buffer.from(byts).toString('utf8'))
|
|
78
|
+
throw e
|
|
79
|
+
}
|
|
80
|
+
if (obj != null && typeof obj === 'object') {
|
|
81
|
+
assert.deepStrictEqual(Object.keys(cobj).length, Object.keys(obj).length)
|
|
82
|
+
} else {
|
|
83
|
+
assert.deepStrictEqual(obj, cobj)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return fixtures.length
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const cmp = (desc, cbfn, bofn) => {
|
|
90
|
+
write(`\t${desc} (avg ${avgSize.toLocaleString()} b):`)
|
|
91
|
+
const cborgOps = bench(cbfn)
|
|
92
|
+
write(` cborg @ ${cborgOps.toLocaleString()} op/s`)
|
|
93
|
+
const jOps = bench(bofn)
|
|
94
|
+
write(` / JSON @ ${jOps.toLocaleString()} op/s`)
|
|
95
|
+
const percent = Math.round((cborgOps / jOps) * 1000) / 10
|
|
96
|
+
write(` = ${(percent).toLocaleString()} %\n`)
|
|
97
|
+
return percent
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return [
|
|
101
|
+
cmp('encode', () => enc(encode), () => enc(jencode)),
|
|
102
|
+
cmp('decode', () => dec(decode), () => dec(jdecode))
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const targetTime = 1000
|
|
107
|
+
const accum = []
|
|
108
|
+
accum.push(runWith('rnd-100', 1000, targetTime, 100, { weights: { CID: 0, bytes: 0 } }))
|
|
109
|
+
accum.push(runWith('rnd-300', 1000, targetTime, 300, { weights: { CID: 0, bytes: 0 } }))
|
|
110
|
+
accum.push(runWith('rnd-nomap-300', 1000, targetTime, 300, { weights: { CID: 0, bytes: 0, map: 0 } }))
|
|
111
|
+
accum.push(runWith('rnd-nolist-300', 1000, targetTime, 300, { weights: { CID: 0, bytes: 0, list: 0 } }))
|
|
112
|
+
accum.push(runWith('rnd-nofloat-300', 1000, targetTime, 300, { weights: { CID: 0, bytes: 0, float: 0 } }))
|
|
113
|
+
accum.push(runWith('rnd-nomaj7-300', 1000, targetTime, 300, { weights: { CID: 0, bytes: 0, float: 0, null: 0, boolean: 0 } }))
|
|
114
|
+
accum.push(runWith('rnd-nostr-300', 1000, targetTime, 300, { weights: { CID: 0, bytes: 0, string: 0 } }))
|
|
115
|
+
accum.push(runWith('rnd-nostrbyts-300', 1000, targetTime, 300, { weights: { CID: 0, bytes: 0, string: 0 } }))
|
|
116
|
+
accum.push(runWith('rnd-1000', 1000, targetTime, 1000, { weights: { CID: 0, bytes: 0 } }))
|
|
117
|
+
accum.push(runWith('rnd-2000', 1000, targetTime, 2000, { weights: { CID: 0, bytes: 0 } }))
|
|
118
|
+
accum.push(runWith('rnd-fil-100', 1000, targetTime, 100, { weights: { float: 0, map: 0, CID: 0, bytes: 0 } }))
|
|
119
|
+
accum.push(runWith('rnd-fil-300', 1000, targetTime, 300, { weights: { float: 0, map: 0, CID: 0, bytes: 0 } }))
|
|
120
|
+
accum.push(runWith('rnd-fil-500', 1000, targetTime, 500, { weights: { float: 0, map: 0, CID: 0, bytes: 0 } }))
|
|
121
|
+
accum.push(runWith('rnd-fil-1000', 1000, targetTime, 1000, { weights: { float: 0, map: 0, CID: 0, bytes: 0 } }))
|
|
122
|
+
accum.push(runWith('rnd-fil-2000', 1000, targetTime, 2000, { weights: { float: 0, map: 0, CID: 0, bytes: 0 } }))
|
|
123
|
+
console.log(`Avg encode: ${Math.round(accum.reduce((p, c) => p + c[0], 0) / accum.length).toLocaleString()} %`)
|
|
124
|
+
console.log(`Avg decode: ${Math.round(accum.reduce((p, c) => p + c[1], 0) / accum.length).toLocaleString()} %`)
|
package/lib/bin.js
CHANGED