@fireproof/vendor 1.1.0 → 1.2.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/package.json +97 -4
- package/src/@ipld/car/LICENSE +4 -0
- package/src/@ipld/car/README.md +1132 -0
- package/src/@ipld/car/dist/index.min.js +5 -0
- package/src/@ipld/car/dist/src/api.d.ts +72 -0
- package/src/@ipld/car/dist/src/api.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/buffer-decoder.d.ts +67 -0
- package/src/@ipld/car/dist/src/buffer-decoder.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts +116 -0
- package/src/@ipld/car/dist/src/buffer-reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/buffer-reader.d.ts +31 -0
- package/src/@ipld/car/dist/src/buffer-reader.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/buffer-writer.d.ts +86 -0
- package/src/@ipld/car/dist/src/buffer-writer.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/coding.d.ts +49 -0
- package/src/@ipld/car/dist/src/coding.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/decoder-common.d.ts +43 -0
- package/src/@ipld/car/dist/src/decoder-common.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/decoder.d.ts +87 -0
- package/src/@ipld/car/dist/src/decoder.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/encoder.d.ts +17 -0
- package/src/@ipld/car/dist/src/encoder.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/header-validator.d.ts +5 -0
- package/src/@ipld/car/dist/src/header-validator.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/index-browser.d.ts +10 -0
- package/src/@ipld/car/dist/src/index-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/index.d.ts +11 -0
- package/src/@ipld/car/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts +5 -0
- package/src/@ipld/car/dist/src/indexed-reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/indexed-reader.d.ts +152 -0
- package/src/@ipld/car/dist/src/indexed-reader.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/indexer.d.ts +95 -0
- package/src/@ipld/car/dist/src/indexer.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/iterator-channel.d.ts +7 -0
- package/src/@ipld/car/dist/src/iterator-channel.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/iterator.d.ts +174 -0
- package/src/@ipld/car/dist/src/iterator.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/promise-fs-opts.d.ts +28 -0
- package/src/@ipld/car/dist/src/promise-fs-opts.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/reader-browser.d.ts +151 -0
- package/src/@ipld/car/dist/src/reader-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/reader.d.ts +40 -0
- package/src/@ipld/car/dist/src/reader.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/writer-browser.d.ts +155 -0
- package/src/@ipld/car/dist/src/writer-browser.d.ts.map +1 -0
- package/src/@ipld/car/dist/src/writer.d.ts +45 -0
- package/src/@ipld/car/dist/src/writer.d.ts.map +1 -0
- package/src/@ipld/car/src/api.ts +90 -0
- package/src/@ipld/car/src/buffer-decoder.js +213 -0
- package/src/@ipld/car/src/buffer-reader-browser.js +144 -0
- package/src/@ipld/car/src/buffer-reader.js +51 -0
- package/src/@ipld/car/src/buffer-writer.js +286 -0
- package/src/@ipld/car/src/coding.ts +68 -0
- package/src/@ipld/car/src/decoder-common.js +82 -0
- package/src/@ipld/car/src/decoder.js +347 -0
- package/src/@ipld/car/src/encoder.js +76 -0
- package/src/@ipld/car/src/header-validator.js +214 -0
- package/src/@ipld/car/src/header.ipldsch +18 -0
- package/src/@ipld/car/src/index-browser.js +18 -0
- package/src/@ipld/car/src/index.js +21 -0
- package/src/@ipld/car/src/indexed-reader-browser.js +7 -0
- package/src/@ipld/car/src/indexed-reader.js +211 -0
- package/src/@ipld/car/src/indexer.js +130 -0
- package/src/@ipld/car/src/iterator-channel.js +91 -0
- package/src/@ipld/car/src/iterator.js +267 -0
- package/src/@ipld/car/src/promise-fs-opts.js +46 -0
- package/src/@ipld/car/src/reader-browser.js +194 -0
- package/src/@ipld/car/src/reader.js +54 -0
- package/src/@ipld/car/src/writer-browser.js +250 -0
- package/src/@ipld/car/src/writer.js +81 -0
- package/src/@ipld/dag-cbor/LICENSE +4 -0
- package/src/@ipld/dag-cbor/README.md +80 -0
- package/src/@ipld/dag-cbor/dist/index.min.js +3 -0
- package/src/@ipld/dag-cbor/dist/src/index.d.ts +67 -0
- package/src/@ipld/dag-cbor/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/dag-cbor/src/index.js +147 -0
- package/src/@ipld/dag-json/LICENSE +4 -0
- package/src/@ipld/dag-json/README.md +58 -0
- package/src/@ipld/dag-json/dist/index.min.js +3 -0
- package/src/@ipld/dag-json/dist/src/index.d.ts +12 -0
- package/src/@ipld/dag-json/dist/src/index.d.ts.map +1 -0
- package/src/@ipld/dag-json/src/index.js +291 -0
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts +53 -1
- package/src/@web3-storage/pail/dist/src/batch/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/batch/shard.d.ts +1 -1
- package/src/@web3-storage/pail/dist/src/batch/shard.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/block.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/block.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/clock/index.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/clock/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/crdt/batch/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/crdt/index.d.ts +2 -2
- package/src/@web3-storage/pail/dist/src/crdt/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/diff.d.ts +3 -3
- package/src/@web3-storage/pail/dist/src/diff.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/index.d.ts +1 -1
- package/src/@web3-storage/pail/dist/src/index.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/merge.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/src/shard.d.ts +4 -4
- package/src/@web3-storage/pail/dist/src/shard.d.ts.map +1 -1
- package/src/@web3-storage/pail/dist/tsconfig.tsbuildinfo +1 -1
- package/src/@web3-storage/pail/src/api.ts +1 -1
- package/src/@web3-storage/pail/src/clock/index.js +1 -1
- package/src/@web3-storage/pail/src/shard.js +1 -1
- package/src/cborg/.github/dependabot.yml +16 -0
- package/src/cborg/.github/workflows/test-and-release.yml +52 -0
- package/src/cborg/CHANGELOG.md +513 -0
- package/src/cborg/LICENSE +13 -0
- package/src/cborg/README.md +515 -0
- package/src/cborg/bench/bench.js +117 -0
- package/src/cborg/bench/json.js +124 -0
- package/src/cborg/bench/package.json +8 -0
- package/src/cborg/cborg/bin.js +189 -0
- package/src/cborg/cborg/common.js +28 -0
- package/src/cborg/cborg/decode.js +211 -0
- package/src/cborg/cborg/diagnostic.js +158 -0
- package/src/cborg/cborg/diagnostic_test.js +117 -0
- package/src/cborg/cborg/encode.js +466 -0
- package/src/cborg/cborg/index.js +33 -0
- package/src/cborg/cborg/is.js +106 -0
- package/src/cborg/cborg/length.js +62 -0
- package/src/cborg/example-bytestrings.js +180 -0
- package/src/cborg/example-json.js +6 -0
- package/src/cborg/example.js +5 -0
- package/src/cborg/interface.ts +59 -0
- package/src/cborg/json/decode.js +462 -0
- package/src/cborg/json/encode.js +302 -0
- package/src/cborg/json/json.js +4 -0
- package/src/cborg/taglib.js +75 -0
- package/src/cborg/test/appendix_a.js +647 -0
- package/src/cborg/test/common.js +18 -0
- package/src/cborg/test/node-test-bin.js +402 -0
- package/src/cborg/test/noop-bin-test.js +3 -0
- package/src/cborg/test/test-0uint.js +103 -0
- package/src/cborg/test/test-1negint.js +96 -0
- package/src/cborg/test/test-2bytes.js +198 -0
- package/src/cborg/test/test-3string.js +136 -0
- package/src/cborg/test/test-4array.js +93 -0
- package/src/cborg/test/test-5map.js +284 -0
- package/src/cborg/test/test-6tag.js +84 -0
- package/src/cborg/test/test-7float.js +131 -0
- package/src/cborg/test/test-bl.js +37 -0
- package/src/cborg/test/test-cbor-vectors.js +107 -0
- package/src/cborg/test/test-decode-errors.js +65 -0
- package/src/cborg/test/test-fuzz.js +42 -0
- package/src/cborg/test/test-json.js +219 -0
- package/src/cborg/test/test-length.js +65 -0
- package/src/cborg/test/test-partial.js +111 -0
- package/src/cborg/tsconfig.json +48 -0
- package/src/cborg/types/cborg/decode.d.ts +43 -0
- package/src/cborg/types/cborg/decode.d.ts.map +1 -0
- package/src/cborg/types/cborg/encode.d.ts +51 -0
- package/src/cborg/types/cborg/encode.d.ts.map +1 -0
- package/src/cborg/types/cborg/index.d.ts +26 -0
- package/src/cborg/types/cborg/index.d.ts.map +1 -0
- package/src/cborg/types/cborg/is.d.ts +6 -0
- package/src/cborg/types/cborg/is.d.ts.map +1 -0
- package/src/cborg/types/example.d.ts +2 -0
- package/src/cborg/types/example.d.ts.map +1 -0
- package/src/cborg/types/interface.d.ts +49 -0
- package/src/cborg/types/interface.d.ts.map +1 -0
- package/src/cborg/types/json/decode.d.ts +67 -0
- package/src/cborg/types/json/decode.d.ts.map +1 -0
- package/src/cborg/types/json/encode.d.ts +11 -0
- package/src/cborg/types/json/encode.d.ts.map +1 -0
- package/src/cborg/types/json/json.d.ts +6 -0
- package/src/cborg/types/json/json.d.ts.map +1 -0
- package/src/cborg/types/taglib.d.ts +18 -0
- package/src/cborg/types/taglib.d.ts.map +1 -0
- package/src/cborg/types/tsconfig.tsbuildinfo +1 -0
- package/src/cborg/types/utils/0uint.d.ts +102 -0
- package/src/cborg/types/utils/0uint.d.ts.map +1 -0
- package/src/cborg/types/utils/1negint.d.ts +59 -0
- package/src/cborg/types/utils/1negint.d.ts.map +1 -0
- package/src/cborg/types/utils/2bytes.d.ts +69 -0
- package/src/cborg/types/utils/2bytes.d.ts.map +1 -0
- package/src/cborg/types/utils/3string.d.ts +46 -0
- package/src/cborg/types/utils/3string.d.ts.map +1 -0
- package/src/cborg/types/utils/4array.d.ts +66 -0
- package/src/cborg/types/utils/4array.d.ts.map +1 -0
- package/src/cborg/types/utils/5map.d.ts +66 -0
- package/src/cborg/types/utils/5map.d.ts.map +1 -0
- package/src/cborg/types/utils/6tag.d.ts +62 -0
- package/src/cborg/types/utils/6tag.d.ts.map +1 -0
- package/src/cborg/types/utils/7float.d.ts +60 -0
- package/src/cborg/types/utils/7float.d.ts.map +1 -0
- package/src/cborg/types/utils/bl.d.ts +26 -0
- package/src/cborg/types/utils/bl.d.ts.map +1 -0
- package/src/cborg/types/utils/byte-utils.d.ts +53 -0
- package/src/cborg/types/utils/byte-utils.d.ts.map +1 -0
- package/src/cborg/types/utils/common.d.ts +8 -0
- package/src/cborg/types/utils/common.d.ts.map +1 -0
- package/src/cborg/types/utils/index.d.ts +13 -0
- package/src/cborg/types/utils/index.d.ts.map +1 -0
- package/src/cborg/types/utils/jump.d.ts +16 -0
- package/src/cborg/types/utils/jump.d.ts.map +1 -0
- package/src/cborg/types/utils/token.d.ts +59 -0
- package/src/cborg/types/utils/token.d.ts.map +1 -0
- package/src/cborg/utils/0uint.js +229 -0
- package/src/cborg/utils/1negint.js +111 -0
- package/src/cborg/utils/2bytes.js +135 -0
- package/src/cborg/utils/3string.js +90 -0
- package/src/cborg/utils/4array.js +114 -0
- package/src/cborg/utils/5map.js +113 -0
- package/src/cborg/utils/6tag.js +81 -0
- package/src/cborg/utils/7float.js +310 -0
- package/src/cborg/utils/bl.js +124 -0
- package/src/cborg/utils/byte-utils.js +417 -0
- package/src/cborg/utils/common.js +11 -0
- package/src/cborg/utils/index.js +12 -0
- package/src/cborg/utils/jump.js +222 -0
- package/src/cborg/utils/token.js +76 -0
- package/src/ipfs-unixfs-exporter/LICENSE +4 -0
- package/src/ipfs-unixfs-exporter/README.md +105 -0
- package/src/ipfs-unixfs-exporter/dist/index.min.js +3 -0
- package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts +57 -0
- package/src/ipfs-unixfs-exporter/dist/src/errors.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/errors.js +73 -0
- package/src/ipfs-unixfs-exporter/dist/src/errors.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/index.d.ts +355 -0
- package/src/ipfs-unixfs-exporter/dist/src/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/index.js +197 -0
- package/src/ipfs-unixfs-exporter/dist/src/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js +9 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-cbor.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js +9 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/dag-json.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js +38 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/identity.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js +30 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js +9 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/json.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js +37 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/raw.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js +29 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/directory.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js +153 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/file.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +59 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js +25 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/content/raw.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js +104 -0
- package/src/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts +3 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js +20 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/extract-data-from-block.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts +6 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js +116 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts +4 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js +57 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/resolve-object-path.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts +6 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.d.ts.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js +30 -0
- package/src/ipfs-unixfs-exporter/dist/src/utils/validate-offset-and-length.js.map +1 -0
- package/src/ipfs-unixfs-exporter/dist/typedoc-urls.json +58 -0
- package/src/ipfs-unixfs-exporter/src/errors.ts +87 -0
- package/src/ipfs-unixfs-exporter/src/index.ts +498 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/dag-cbor.ts +12 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/dag-json.ts +12 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/identity.ts +49 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/index.ts +35 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/json.ts +12 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/raw.ts +49 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +39 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts +198 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +76 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.ts +37 -0
- package/src/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts +121 -0
- package/src/ipfs-unixfs-exporter/src/utils/extract-data-from-block.ts +24 -0
- package/src/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts +149 -0
- package/src/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts +62 -0
- package/src/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts +38 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Token, Type } from './token.js'
|
|
2
|
+
import { assertEnoughData } from './common.js'
|
|
3
|
+
import * as uint from './0uint.js'
|
|
4
|
+
import { compare, fromString, slice } from './byte-utils.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {import('./bl.js').Bl} Bl
|
|
8
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {Uint8Array} data
|
|
13
|
+
* @param {number} pos
|
|
14
|
+
* @param {number} prefix
|
|
15
|
+
* @param {number} length
|
|
16
|
+
* @param {string} decodeErrPrefix
|
|
17
|
+
* @returns {Token}
|
|
18
|
+
*/
|
|
19
|
+
function toToken (data, pos, prefix, length, decodeErrPrefix) {
|
|
20
|
+
assertEnoughData(data, pos, prefix + length, decodeErrPrefix)
|
|
21
|
+
const buf = slice(data, pos + prefix, pos + prefix + length)
|
|
22
|
+
return new Token(Type.bytes, buf, prefix + length)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {Uint8Array} data
|
|
27
|
+
* @param {number} pos
|
|
28
|
+
* @param {number} minor
|
|
29
|
+
* @param {DecodeOptions} options
|
|
30
|
+
* @returns {Token}
|
|
31
|
+
*/
|
|
32
|
+
export function decodeBytesCompact (data, pos, minor, options) {
|
|
33
|
+
return toToken(data, pos, 1, minor, options.decodeErrPrefix)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {Uint8Array} data
|
|
38
|
+
* @param {number} pos
|
|
39
|
+
* @param {number} _minor
|
|
40
|
+
* @param {DecodeOptions} options
|
|
41
|
+
* @returns {Token}
|
|
42
|
+
*/
|
|
43
|
+
export function decodeBytes8 (data, pos, _minor, options) {
|
|
44
|
+
return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options), options.decodeErrPrefix)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {Uint8Array} data
|
|
49
|
+
* @param {number} pos
|
|
50
|
+
* @param {number} _minor
|
|
51
|
+
* @param {DecodeOptions} options
|
|
52
|
+
* @returns {Token}
|
|
53
|
+
*/
|
|
54
|
+
export function decodeBytes16 (data, pos, _minor, options) {
|
|
55
|
+
return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options), options.decodeErrPrefix)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {Uint8Array} data
|
|
60
|
+
* @param {number} pos
|
|
61
|
+
* @param {number} _minor
|
|
62
|
+
* @param {DecodeOptions} options
|
|
63
|
+
* @returns {Token}
|
|
64
|
+
*/
|
|
65
|
+
export function decodeBytes32 (data, pos, _minor, options) {
|
|
66
|
+
return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options), options.decodeErrPrefix)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// TODO: maybe we shouldn't support this ..
|
|
70
|
+
/**
|
|
71
|
+
* @param {Uint8Array} data
|
|
72
|
+
* @param {number} pos
|
|
73
|
+
* @param {number} _minor
|
|
74
|
+
* @param {DecodeOptions} options
|
|
75
|
+
* @returns {Token}
|
|
76
|
+
*/
|
|
77
|
+
export function decodeBytes64 (data, pos, _minor, options) {
|
|
78
|
+
const l = uint.readUint64(data, pos + 1, options)
|
|
79
|
+
if (typeof l === 'bigint') {
|
|
80
|
+
throw new Error(`${options.decodeErrPrefix} 64-bit integer bytes lengths not supported`)
|
|
81
|
+
}
|
|
82
|
+
return toToken(data, pos, 9, l, options.decodeErrPrefix)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* `encodedBytes` allows for caching when we do a byte version of a string
|
|
87
|
+
* for key sorting purposes
|
|
88
|
+
* @param {Token} token
|
|
89
|
+
* @returns {Uint8Array}
|
|
90
|
+
*/
|
|
91
|
+
function tokenBytes (token) {
|
|
92
|
+
if (token.encodedBytes === undefined) {
|
|
93
|
+
token.encodedBytes = token.type.equals(Type.string) ? fromString(token.value) : token.value
|
|
94
|
+
}
|
|
95
|
+
// @ts-ignore c'mon
|
|
96
|
+
return token.encodedBytes
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {Bl} buf
|
|
101
|
+
* @param {Token} token
|
|
102
|
+
* @param {import('../interface.js').EncodeOptions} options
|
|
103
|
+
*/
|
|
104
|
+
export function encodeBytes (buf, token, { encodeErrPrefix }) {
|
|
105
|
+
const bytes = tokenBytes(token)
|
|
106
|
+
uint.encodeUintValue(buf, token.type.majorEncoded, bytes.length, encodeErrPrefix)
|
|
107
|
+
buf.push(bytes)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {Token} token
|
|
112
|
+
* @returns {number}
|
|
113
|
+
*/
|
|
114
|
+
encodeBytes.encodedSize = function encodedSize (token) {
|
|
115
|
+
const bytes = tokenBytes(token)
|
|
116
|
+
return uint.encodeUintValue.encodedSize(bytes.length) + bytes.length
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {Token} tok1
|
|
121
|
+
* @param {Token} tok2
|
|
122
|
+
* @returns {number}
|
|
123
|
+
*/
|
|
124
|
+
encodeBytes.compareTokens = function compareTokens (tok1, tok2) {
|
|
125
|
+
return compareBytes(tokenBytes(tok1), tokenBytes(tok2))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {Uint8Array} b1
|
|
130
|
+
* @param {Uint8Array} b2
|
|
131
|
+
* @returns {number}
|
|
132
|
+
*/
|
|
133
|
+
export function compareBytes (b1, b2) {
|
|
134
|
+
return b1.length < b2.length ? -1 : b1.length > b2.length ? 1 : compare(b1, b2)
|
|
135
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Token, Type } from './token.js'
|
|
2
|
+
import { assertEnoughData } from './common.js'
|
|
3
|
+
import * as uint from './0uint.js'
|
|
4
|
+
import { encodeBytes } from './2bytes.js'
|
|
5
|
+
import { toString, slice } from './byte-utils.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {import('./bl.js').Bl} Bl
|
|
9
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {Uint8Array} data
|
|
14
|
+
* @param {number} pos
|
|
15
|
+
* @param {number} prefix
|
|
16
|
+
* @param {number} length
|
|
17
|
+
* @param {DecodeOptions} options
|
|
18
|
+
* @returns {Token}
|
|
19
|
+
*/
|
|
20
|
+
function toToken (data, pos, prefix, length, options) {
|
|
21
|
+
const totLength = prefix + length
|
|
22
|
+
assertEnoughData(data, pos, totLength, options.decodeErrPrefix)
|
|
23
|
+
const tok = new Token(Type.string, toString(data, pos + prefix, pos + totLength), totLength)
|
|
24
|
+
if (options.retainStringBytes === true) {
|
|
25
|
+
tok.byteValue = slice(data, pos + prefix, pos + totLength)
|
|
26
|
+
}
|
|
27
|
+
return tok
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {Uint8Array} data
|
|
32
|
+
* @param {number} pos
|
|
33
|
+
* @param {number} minor
|
|
34
|
+
* @param {DecodeOptions} options
|
|
35
|
+
* @returns {Token}
|
|
36
|
+
*/
|
|
37
|
+
export function decodeStringCompact (data, pos, minor, options) {
|
|
38
|
+
return toToken(data, pos, 1, minor, options)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {Uint8Array} data
|
|
43
|
+
* @param {number} pos
|
|
44
|
+
* @param {number} _minor
|
|
45
|
+
* @param {DecodeOptions} options
|
|
46
|
+
* @returns {Token}
|
|
47
|
+
*/
|
|
48
|
+
export function decodeString8 (data, pos, _minor, options) {
|
|
49
|
+
return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options), options)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {Uint8Array} data
|
|
54
|
+
* @param {number} pos
|
|
55
|
+
* @param {number} _minor
|
|
56
|
+
* @param {DecodeOptions} options
|
|
57
|
+
* @returns {Token}
|
|
58
|
+
*/
|
|
59
|
+
export function decodeString16 (data, pos, _minor, options) {
|
|
60
|
+
return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options), options)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {Uint8Array} data
|
|
65
|
+
* @param {number} pos
|
|
66
|
+
* @param {number} _minor
|
|
67
|
+
* @param {DecodeOptions} options
|
|
68
|
+
* @returns {Token}
|
|
69
|
+
*/
|
|
70
|
+
export function decodeString32 (data, pos, _minor, options) {
|
|
71
|
+
return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options), options)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// TODO: maybe we shouldn't support this ..
|
|
75
|
+
/**
|
|
76
|
+
* @param {Uint8Array} data
|
|
77
|
+
* @param {number} pos
|
|
78
|
+
* @param {number} _minor
|
|
79
|
+
* @param {DecodeOptions} options
|
|
80
|
+
* @returns {Token}
|
|
81
|
+
*/
|
|
82
|
+
export function decodeString64 (data, pos, _minor, options) {
|
|
83
|
+
const l = uint.readUint64(data, pos + 1, options)
|
|
84
|
+
if (typeof l === 'bigint') {
|
|
85
|
+
throw new Error(`${options.decodeErrPrefix} 64-bit integer string lengths not supported`)
|
|
86
|
+
}
|
|
87
|
+
return toToken(data, pos, 9, l, options)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const encodeString = encodeBytes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Token, Type } from './token.js'
|
|
2
|
+
import * as uint from './0uint.js'
|
|
3
|
+
// import { decodeErrPrefix } from '../lib/common.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('./bl.js').Bl} Bl
|
|
7
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {Uint8Array} _data
|
|
12
|
+
* @param {number} _pos
|
|
13
|
+
* @param {number} prefix
|
|
14
|
+
* @param {number} length
|
|
15
|
+
* @returns {Token}
|
|
16
|
+
*/
|
|
17
|
+
function toToken (_data, _pos, prefix, length) {
|
|
18
|
+
return new Token(Type.array, length, prefix)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {Uint8Array} data
|
|
23
|
+
* @param {number} pos
|
|
24
|
+
* @param {number} minor
|
|
25
|
+
* @param {DecodeOptions} _options
|
|
26
|
+
* @returns {Token}
|
|
27
|
+
*/
|
|
28
|
+
export function decodeArrayCompact (data, pos, minor, _options) {
|
|
29
|
+
return toToken(data, pos, 1, minor)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {Uint8Array} data
|
|
34
|
+
* @param {number} pos
|
|
35
|
+
* @param {number} _minor
|
|
36
|
+
* @param {DecodeOptions} options
|
|
37
|
+
* @returns {Token}
|
|
38
|
+
*/
|
|
39
|
+
export function decodeArray8 (data, pos, _minor, options) {
|
|
40
|
+
return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {Uint8Array} data
|
|
45
|
+
* @param {number} pos
|
|
46
|
+
* @param {number} _minor
|
|
47
|
+
* @param {DecodeOptions} options
|
|
48
|
+
* @returns {Token}
|
|
49
|
+
*/
|
|
50
|
+
export function decodeArray16 (data, pos, _minor, options) {
|
|
51
|
+
return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {Uint8Array} data
|
|
56
|
+
* @param {number} pos
|
|
57
|
+
* @param {number} _minor
|
|
58
|
+
* @param {DecodeOptions} options
|
|
59
|
+
* @returns {Token}
|
|
60
|
+
*/
|
|
61
|
+
export function decodeArray32 (data, pos, _minor, options) {
|
|
62
|
+
return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// TODO: maybe we shouldn't support this ..
|
|
66
|
+
/**
|
|
67
|
+
* @param {Uint8Array} data
|
|
68
|
+
* @param {number} pos
|
|
69
|
+
* @param {number} _minor
|
|
70
|
+
* @param {DecodeOptions} options
|
|
71
|
+
* @returns {Token}
|
|
72
|
+
*/
|
|
73
|
+
export function decodeArray64 (data, pos, _minor, options) {
|
|
74
|
+
const l = uint.readUint64(data, pos + 1, options)
|
|
75
|
+
if (typeof l === 'bigint') {
|
|
76
|
+
throw new Error(`${options.decodeErrPrefix} 64-bit integer array lengths not supported`)
|
|
77
|
+
}
|
|
78
|
+
return toToken(data, pos, 9, l)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {Uint8Array} data
|
|
83
|
+
* @param {number} pos
|
|
84
|
+
* @param {number} _minor
|
|
85
|
+
* @param {DecodeOptions} options
|
|
86
|
+
* @returns {Token}
|
|
87
|
+
*/
|
|
88
|
+
export function decodeArrayIndefinite (data, pos, _minor, options) {
|
|
89
|
+
if (options.allowIndefinite === false) {
|
|
90
|
+
throw new Error(`${options.decodeErrPrefix} indefinite length items not allowed`)
|
|
91
|
+
}
|
|
92
|
+
return toToken(data, pos, 1, Infinity)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {Bl} buf
|
|
97
|
+
* @param {Token} token
|
|
98
|
+
* @param {import('../interface.js').EncodeOptions} options
|
|
99
|
+
*/
|
|
100
|
+
export function encodeArray (buf, token, { encodeErrPrefix }) {
|
|
101
|
+
uint.encodeUintValue(buf, Type.array.majorEncoded, token.value, encodeErrPrefix)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// using an array as a map key, are you sure about this? we can only sort
|
|
105
|
+
// by map length here, it's up to the encoder to decide to look deeper
|
|
106
|
+
encodeArray.compareTokens = uint.encodeUint.compareTokens
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {Token} token
|
|
110
|
+
* @returns {number}
|
|
111
|
+
*/
|
|
112
|
+
encodeArray.encodedSize = function encodedSize (token) {
|
|
113
|
+
return uint.encodeUintValue.encodedSize(token.value)
|
|
114
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Token, Type } from './token.js'
|
|
2
|
+
import * as uint from './0uint.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('./bl.js').Bl} Bl
|
|
6
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Uint8Array} _data
|
|
11
|
+
* @param {number} _pos
|
|
12
|
+
* @param {number} prefix
|
|
13
|
+
* @param {number} length
|
|
14
|
+
* @returns {Token}
|
|
15
|
+
*/
|
|
16
|
+
function toToken (_data, _pos, prefix, length) {
|
|
17
|
+
return new Token(Type.map, length, prefix)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {Uint8Array} data
|
|
22
|
+
* @param {number} pos
|
|
23
|
+
* @param {number} minor
|
|
24
|
+
* @param {DecodeOptions} _options
|
|
25
|
+
* @returns {Token}
|
|
26
|
+
*/
|
|
27
|
+
export function decodeMapCompact (data, pos, minor, _options) {
|
|
28
|
+
return toToken(data, pos, 1, minor)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {Uint8Array} data
|
|
33
|
+
* @param {number} pos
|
|
34
|
+
* @param {number} _minor
|
|
35
|
+
* @param {DecodeOptions} options
|
|
36
|
+
* @returns {Token}
|
|
37
|
+
*/
|
|
38
|
+
export function decodeMap8 (data, pos, _minor, options) {
|
|
39
|
+
return toToken(data, pos, 2, uint.readUint8(data, pos + 1, options))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {Uint8Array} data
|
|
44
|
+
* @param {number} pos
|
|
45
|
+
* @param {number} _minor
|
|
46
|
+
* @param {DecodeOptions} options
|
|
47
|
+
* @returns {Token}
|
|
48
|
+
*/
|
|
49
|
+
export function decodeMap16 (data, pos, _minor, options) {
|
|
50
|
+
return toToken(data, pos, 3, uint.readUint16(data, pos + 1, options))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {Uint8Array} data
|
|
55
|
+
* @param {number} pos
|
|
56
|
+
* @param {number} _minor
|
|
57
|
+
* @param {DecodeOptions} options
|
|
58
|
+
* @returns {Token}
|
|
59
|
+
*/
|
|
60
|
+
export function decodeMap32 (data, pos, _minor, options) {
|
|
61
|
+
return toToken(data, pos, 5, uint.readUint32(data, pos + 1, options))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// TODO: maybe we shouldn't support this ..
|
|
65
|
+
/**
|
|
66
|
+
* @param {Uint8Array} data
|
|
67
|
+
* @param {number} pos
|
|
68
|
+
* @param {number} _minor
|
|
69
|
+
* @param {DecodeOptions} options
|
|
70
|
+
* @returns {Token}
|
|
71
|
+
*/
|
|
72
|
+
export function decodeMap64 (data, pos, _minor, options) {
|
|
73
|
+
const l = uint.readUint64(data, pos + 1, options)
|
|
74
|
+
if (typeof l === 'bigint') {
|
|
75
|
+
throw new Error(`${options.decodeErrPrefix} 64-bit integer map lengths not supported`)
|
|
76
|
+
}
|
|
77
|
+
return toToken(data, pos, 9, l)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {Uint8Array} data
|
|
82
|
+
* @param {number} pos
|
|
83
|
+
* @param {number} _minor
|
|
84
|
+
* @param {DecodeOptions} options
|
|
85
|
+
* @returns {Token}
|
|
86
|
+
*/
|
|
87
|
+
export function decodeMapIndefinite (data, pos, _minor, options) {
|
|
88
|
+
if (options.allowIndefinite === false) {
|
|
89
|
+
throw new Error(`${options.decodeErrPrefix} indefinite length items not allowed`)
|
|
90
|
+
}
|
|
91
|
+
return toToken(data, pos, 1, Infinity)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {Bl} buf
|
|
96
|
+
* @param {Token} token
|
|
97
|
+
* @param {import('../interface.js').EncodeOptions} options
|
|
98
|
+
*/
|
|
99
|
+
export function encodeMap (buf, token, { encodeErrPrefix }) {
|
|
100
|
+
uint.encodeUintValue(buf, Type.map.majorEncoded, token.value, encodeErrPrefix)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// using a map as a map key, are you sure about this? we can only sort
|
|
104
|
+
// by map length here, it's up to the encoder to decide to look deeper
|
|
105
|
+
encodeMap.compareTokens = uint.encodeUint.compareTokens
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {Token} token
|
|
109
|
+
* @returns {number}
|
|
110
|
+
*/
|
|
111
|
+
encodeMap.encodedSize = function encodedSize (token) {
|
|
112
|
+
return uint.encodeUintValue.encodedSize(token.value)
|
|
113
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Token, Type } from './token.js'
|
|
2
|
+
import * as uint from './0uint.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('./bl.js').Bl} Bl
|
|
6
|
+
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Uint8Array} _data
|
|
11
|
+
* @param {number} _pos
|
|
12
|
+
* @param {number} minor
|
|
13
|
+
* @param {DecodeOptions} _options
|
|
14
|
+
* @returns {Token}
|
|
15
|
+
*/
|
|
16
|
+
export function decodeTagCompact (_data, _pos, minor, _options) {
|
|
17
|
+
return new Token(Type.tag, minor, 1)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {Uint8Array} data
|
|
22
|
+
* @param {number} pos
|
|
23
|
+
* @param {number} _minor
|
|
24
|
+
* @param {DecodeOptions} options
|
|
25
|
+
* @returns {Token}
|
|
26
|
+
*/
|
|
27
|
+
export function decodeTag8 (data, pos, _minor, options) {
|
|
28
|
+
return new Token(Type.tag, uint.readUint8(data, pos + 1, options), 2)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {Uint8Array} data
|
|
33
|
+
* @param {number} pos
|
|
34
|
+
* @param {number} _minor
|
|
35
|
+
* @param {DecodeOptions} options
|
|
36
|
+
* @returns {Token}
|
|
37
|
+
*/
|
|
38
|
+
export function decodeTag16 (data, pos, _minor, options) {
|
|
39
|
+
return new Token(Type.tag, uint.readUint16(data, pos + 1, options), 3)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {Uint8Array} data
|
|
44
|
+
* @param {number} pos
|
|
45
|
+
* @param {number} _minor
|
|
46
|
+
* @param {DecodeOptions} options
|
|
47
|
+
* @returns {Token}
|
|
48
|
+
*/
|
|
49
|
+
export function decodeTag32 (data, pos, _minor, options) {
|
|
50
|
+
return new Token(Type.tag, uint.readUint32(data, pos + 1, options), 5)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {Uint8Array} data
|
|
55
|
+
* @param {number} pos
|
|
56
|
+
* @param {number} _minor
|
|
57
|
+
* @param {DecodeOptions} options
|
|
58
|
+
* @returns {Token}
|
|
59
|
+
*/
|
|
60
|
+
export function decodeTag64 (data, pos, _minor, options) {
|
|
61
|
+
return new Token(Type.tag, uint.readUint64(data, pos + 1, options), 9)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Bl} buf
|
|
66
|
+
* @param {Token} token
|
|
67
|
+
* @param {import('../interface.js').EncodeOptions} options
|
|
68
|
+
*/
|
|
69
|
+
export function encodeTag (buf, token, { encodeErrPrefix }) {
|
|
70
|
+
uint.encodeUintValue(buf, Type.tag.majorEncoded, token.value, encodeErrPrefix)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
encodeTag.compareTokens = uint.encodeUint.compareTokens
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {Token} token
|
|
77
|
+
* @returns {number}
|
|
78
|
+
*/
|
|
79
|
+
encodeTag.encodedSize = function encodedSize (token) {
|
|
80
|
+
return uint.encodeUintValue.encodedSize(token.value)
|
|
81
|
+
}
|