@schema-pack/message-pack 0.0.0-commit.7aad9bb7aa476e8148a2e2b9419af9356fd8d8e5 → 0.0.0-commit.fd50c1db034f7ca04b28f01b16e76470ecc500c7
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/README.md +131 -13
- package/dist/cjs/{bigInt-BdjzezQQ.d.cts → bigInt-CBB8PGpe.d.cts} +4 -4
- package/dist/{esm/bigInt-D37SPzzB.d.mts.map → cjs/bigInt-CBB8PGpe.d.cts.map} +1 -1
- package/dist/{esm/bufferWithExtensions-DzAs7yX1.d.mts → cjs/bufferWithExtensions-BAinwJsn.d.cts} +2 -2
- package/dist/cjs/{bufferWithExtensions-n6DtcUoA.d.cts.map → bufferWithExtensions-BAinwJsn.d.cts.map} +1 -1
- package/dist/cjs/bufferWithExtensions.d.cts +1 -1
- package/dist/cjs/decoder/decoder.cjs +1 -1
- package/dist/cjs/decoder/decoder.d.cts +1 -1
- package/dist/cjs/decoder/decoderBuffer.cjs +3 -2
- package/dist/cjs/decoder/decoderBuffer.d.cts +1 -1
- package/dist/cjs/decoder/index.cjs +0 -6
- package/dist/cjs/decoder/index.d.cts +5 -8
- package/dist/cjs/decoder/interfaces/index.d.cts +2 -2
- package/dist/cjs/decoder/interfaces/messagePackDecoderBuffer.d.cts +1 -1
- package/dist/cjs/decoder/interfaces/messagePackTextDecoder.d.cts +1 -1
- package/dist/cjs/decoder/textDecoders/defaultTextDecoder.d.cts +1 -1
- package/dist/cjs/decoder/types.d.cts +1 -1
- package/dist/cjs/{decoder-3WpVBZjY.d.cts → decoder-C1cd4I8S.d.cts} +4 -4
- package/dist/cjs/decoder-C1cd4I8S.d.cts.map +1 -0
- package/dist/{esm/decoderBuffer-93dMcsbx.d.mts → cjs/decoderBuffer-C9_0y-3q.d.cts} +5 -5
- package/dist/cjs/decoderBuffer-C9_0y-3q.d.cts.map +1 -0
- package/dist/{esm/defaultTextDecoder-DztyzoBV.d.mts → cjs/defaultTextDecoder-Ji2hTZkf.d.cts} +2 -2
- package/dist/cjs/{defaultTextDecoder-DY92jDSO.d.cts.map → defaultTextDecoder-Ji2hTZkf.d.cts.map} +1 -1
- package/dist/cjs/encoder/encoder.cjs +2 -2
- package/dist/cjs/encoder/encoder.d.cts +1 -1
- package/dist/cjs/encoder/encoderBuffer.cjs +23 -29
- package/dist/cjs/encoder/encoderBuffer.d.cts +1 -1
- package/dist/cjs/encoder/index.cjs +0 -2
- package/dist/cjs/encoder/index.d.cts +4 -5
- package/dist/cjs/encoder/interfaces/index.d.cts +2 -2
- package/dist/cjs/encoder/interfaces/messagePackEncoderBuffer.d.cts +1 -1
- package/dist/cjs/encoder/textEncoders/index.d.cts +1 -1
- package/dist/cjs/encoder/types.d.cts +1 -1
- package/dist/cjs/{encoder-B-rTvI4P.d.cts → encoder-DXuhGwd7.d.cts} +4 -4
- package/dist/cjs/{encoder-B-rTvI4P.d.cts.map → encoder-DXuhGwd7.d.cts.map} +1 -1
- package/dist/cjs/{encoderBuffer-3ur0iCYR.d.cts → encoderBuffer-DWGIXXjj.d.cts} +5 -7
- package/dist/cjs/{encoderBuffer-3ur0iCYR.d.cts.map → encoderBuffer-DWGIXXjj.d.cts.map} +1 -1
- package/dist/cjs/extensions/bigint/bigInt.d.cts +1 -1
- package/dist/cjs/extensions/bigint/index.d.cts +2 -2
- package/dist/cjs/extensions/index.d.cts +2 -2
- package/dist/cjs/extensions/interfaces/index.d.cts +2 -2
- package/dist/cjs/extensions/interfaces/messagePackExtension.d.cts +1 -1
- package/dist/cjs/extensions/timestampDate/index.d.cts +2 -2
- package/dist/cjs/extensions/timestampDate/timestampDate.d.cts +1 -1
- package/dist/cjs/index.cjs +0 -8
- package/dist/cjs/index.d.cts +11 -15
- package/dist/cjs/interfaces/index.d.cts +1 -1
- package/dist/cjs/interfaces/messagePackBufferWithExtensions.d.cts +1 -1
- package/dist/cjs/{messagePackDecoderBuffer-B2rRVlMX.d.cts → messagePackDecoderBuffer-CMG0LPbJ.d.cts} +2 -2
- package/dist/cjs/{messagePackDecoderBuffer-B2rRVlMX.d.cts.map → messagePackDecoderBuffer-CMG0LPbJ.d.cts.map} +1 -1
- package/dist/cjs/{messagePackExtension-Cd99Rw9t.d.cts → messagePackExtension-C_TQXlEn.d.cts} +3 -25
- package/dist/cjs/{messagePackExtension-Cd99Rw9t.d.cts.map → messagePackExtension-C_TQXlEn.d.cts.map} +1 -1
- package/dist/cjs/messagePackTextDecoder-CtyB0N6j.d.cts +7 -0
- package/dist/cjs/messagePackTextDecoder-CtyB0N6j.d.cts.map +1 -0
- package/dist/cjs/{timestampDate-Bi1rnvVd.d.cts → timestampDate-BtBd4bAx.d.cts} +3 -3
- package/dist/cjs/{timestampDate-Bi1rnvVd.d.cts.map → timestampDate-BtBd4bAx.d.cts.map} +1 -1
- package/dist/{esm/types-DTcs4Mkd.d.mts → cjs/types-BJie2edF.d.cts} +4 -4
- package/dist/cjs/types-BJie2edF.d.cts.map +1 -0
- package/dist/cjs/types-DHnp4kMw.d.cts +6 -0
- package/dist/cjs/types-DHnp4kMw.d.cts.map +1 -0
- package/dist/cjs/types.d.cts +2 -2
- package/dist/{esm/untypedExtension-Ckk9RwQw.d.mts → cjs/untypedExtension-WQvArYoO.d.cts} +3 -3
- package/dist/cjs/{untypedExtension-wx6-_4mg.d.cts.map → untypedExtension-WQvArYoO.d.cts.map} +1 -1
- package/dist/cjs/untypedExtension.d.cts +1 -1
- package/dist/esm/{bigInt-D37SPzzB.d.mts → bigInt-BvNVHUwj.d.mts} +4 -4
- package/dist/{cjs/bigInt-BdjzezQQ.d.cts.map → esm/bigInt-BvNVHUwj.d.mts.map} +1 -1
- package/dist/{cjs/bufferWithExtensions-n6DtcUoA.d.cts → esm/bufferWithExtensions-Bikyeyt1.d.mts} +2 -2
- package/dist/esm/{bufferWithExtensions-DzAs7yX1.d.mts.map → bufferWithExtensions-Bikyeyt1.d.mts.map} +1 -1
- package/dist/esm/bufferWithExtensions.d.mts +1 -1
- package/dist/esm/decoder/decoder.d.mts +1 -1
- package/dist/esm/decoder/decoder.mjs +1 -1
- package/dist/esm/decoder/decoder.mjs.map +1 -1
- package/dist/esm/decoder/decoderBuffer.d.mts +1 -1
- package/dist/esm/decoder/decoderBuffer.mjs +3 -2
- package/dist/esm/decoder/decoderBuffer.mjs.map +1 -1
- package/dist/esm/decoder/index.d.mts +5 -8
- package/dist/esm/decoder/index.mjs +1 -4
- package/dist/esm/decoder/interfaces/index.d.mts +2 -2
- package/dist/esm/decoder/interfaces/messagePackDecoderBuffer.d.mts +1 -1
- package/dist/esm/decoder/interfaces/messagePackTextDecoder.d.mts +1 -1
- package/dist/esm/decoder/textDecoders/defaultTextDecoder.d.mts +1 -1
- package/dist/esm/decoder/types.d.mts +1 -1
- package/dist/esm/{decoder-ByAWOgvm.d.mts → decoder-DEzsJjYj.d.mts} +4 -4
- package/dist/esm/decoder-DEzsJjYj.d.mts.map +1 -0
- package/dist/{cjs/decoderBuffer-CJU2hdt2.d.cts → esm/decoderBuffer-BxJJdy5k.d.mts} +5 -5
- package/dist/esm/decoderBuffer-BxJJdy5k.d.mts.map +1 -0
- package/dist/{cjs/defaultTextDecoder-DY92jDSO.d.cts → esm/defaultTextDecoder-B6a1HH2u.d.mts} +2 -2
- package/dist/esm/{defaultTextDecoder-DztyzoBV.d.mts.map → defaultTextDecoder-B6a1HH2u.d.mts.map} +1 -1
- package/dist/esm/encoder/encoder.d.mts +1 -1
- package/dist/esm/encoder/encoder.mjs +2 -2
- package/dist/esm/encoder/encoder.mjs.map +1 -1
- package/dist/esm/encoder/encoderBuffer.d.mts +1 -1
- package/dist/esm/encoder/encoderBuffer.mjs +24 -30
- package/dist/esm/encoder/encoderBuffer.mjs.map +1 -1
- package/dist/esm/encoder/index.d.mts +4 -5
- package/dist/esm/encoder/index.mjs +1 -2
- package/dist/esm/encoder/interfaces/index.d.mts +2 -2
- package/dist/esm/encoder/interfaces/messagePackEncoderBuffer.d.mts +1 -1
- package/dist/esm/encoder/textEncoders/index.d.mts +1 -1
- package/dist/esm/encoder/types.d.mts +1 -1
- package/dist/esm/{encoder-PfSLnKnK.d.mts → encoder-CQfcjnAe.d.mts} +4 -4
- package/dist/esm/{encoder-PfSLnKnK.d.mts.map → encoder-CQfcjnAe.d.mts.map} +1 -1
- package/dist/esm/{encoderBuffer-BZMIF5I2.d.mts → encoderBuffer-DEy8CuWQ.d.mts} +5 -7
- package/dist/esm/{encoderBuffer-BZMIF5I2.d.mts.map → encoderBuffer-DEy8CuWQ.d.mts.map} +1 -1
- package/dist/esm/extensions/bigint/bigInt.d.mts +1 -1
- package/dist/esm/extensions/bigint/index.d.mts +2 -2
- package/dist/esm/extensions/index.d.mts +2 -2
- package/dist/esm/extensions/interfaces/index.d.mts +2 -2
- package/dist/esm/extensions/interfaces/messagePackExtension.d.mts +1 -1
- package/dist/esm/extensions/timestampDate/index.d.mts +2 -2
- package/dist/esm/extensions/timestampDate/timestampDate.d.mts +1 -1
- package/dist/esm/index.d.mts +11 -15
- package/dist/esm/index.mjs +1 -5
- package/dist/esm/interfaces/index.d.mts +1 -1
- package/dist/esm/interfaces/messagePackBufferWithExtensions.d.mts +1 -1
- package/dist/esm/{messagePackDecoderBuffer-Cqvg0zW7.d.mts → messagePackDecoderBuffer-CGyYSweZ.d.mts} +2 -2
- package/dist/esm/{messagePackDecoderBuffer-Cqvg0zW7.d.mts.map → messagePackDecoderBuffer-CGyYSweZ.d.mts.map} +1 -1
- package/dist/esm/{messagePackExtension-fq36EMAg.d.mts → messagePackExtension-5TI02KG6.d.mts} +3 -25
- package/dist/esm/{messagePackExtension-fq36EMAg.d.mts.map → messagePackExtension-5TI02KG6.d.mts.map} +1 -1
- package/dist/esm/messagePackTextDecoder-CtyB0N6j.d.mts +7 -0
- package/dist/esm/messagePackTextDecoder-CtyB0N6j.d.mts.map +1 -0
- package/dist/esm/{timestampDate-C3Ch8aSB.d.mts → timestampDate-C1UzHhZL.d.mts} +3 -3
- package/dist/esm/{timestampDate-C3Ch8aSB.d.mts.map → timestampDate-C1UzHhZL.d.mts.map} +1 -1
- package/dist/{cjs/types-DTcs4Mkd.d.cts → esm/types-BJie2edF.d.mts} +4 -4
- package/dist/esm/types-BJie2edF.d.mts.map +1 -0
- package/dist/esm/types-DoBZbRkk.d.mts +6 -0
- package/dist/esm/types-DoBZbRkk.d.mts.map +1 -0
- package/dist/esm/types.d.mts +2 -2
- package/dist/{cjs/untypedExtension-wx6-_4mg.d.cts → esm/untypedExtension-6bNMj-lY.d.mts} +3 -3
- package/dist/esm/{untypedExtension-Ckk9RwQw.d.mts.map → untypedExtension-6bNMj-lY.d.mts.map} +1 -1
- package/dist/esm/untypedExtension.d.mts +1 -1
- package/package.json +1 -17
- package/LICENSE +0 -21
- package/dist/cjs/decode-BraWmoPw.d.cts +0 -5
- package/dist/cjs/decode-BraWmoPw.d.cts.map +0 -1
- package/dist/cjs/decoder/decode.cjs +0 -8
- package/dist/cjs/decoder/decode.d.cts +0 -2
- package/dist/cjs/decoder/textDecoders/index.cjs +0 -5
- package/dist/cjs/decoder/textDecoders/index.d.cts +0 -4
- package/dist/cjs/decoder/textDecoders/nodeTextDecoder.cjs +0 -8
- package/dist/cjs/decoder/textDecoders/nodeTextDecoder.d.cts +0 -2
- package/dist/cjs/decoder-3WpVBZjY.d.cts.map +0 -1
- package/dist/cjs/decoderBuffer-CJU2hdt2.d.cts.map +0 -1
- package/dist/cjs/encode-4SxHVw0M.d.cts +0 -5
- package/dist/cjs/encode-4SxHVw0M.d.cts.map +0 -1
- package/dist/cjs/encoder/encode.cjs +0 -8
- package/dist/cjs/encoder/encode.d.cts +0 -2
- package/dist/cjs/index-B5vbV8Ak.d.cts +0 -1
- package/dist/cjs/messagePackTextDecoder-J3fr-wQn.d.cts +0 -7
- package/dist/cjs/messagePackTextDecoder-J3fr-wQn.d.cts.map +0 -1
- package/dist/cjs/nodeTextDecoder-DrNFdTVk.d.cts +0 -9
- package/dist/cjs/nodeTextDecoder-DrNFdTVk.d.cts.map +0 -1
- package/dist/cjs/types-CC2wkzZa.d.cts +0 -9
- package/dist/cjs/types-CC2wkzZa.d.cts.map +0 -1
- package/dist/cjs/types-DTcs4Mkd.d.cts.map +0 -1
- package/dist/esm/decode-BraWmoPw.d.mts +0 -5
- package/dist/esm/decode-BraWmoPw.d.mts.map +0 -1
- package/dist/esm/decoder/decode.d.mts +0 -2
- package/dist/esm/decoder/decode.mjs +0 -11
- package/dist/esm/decoder/decode.mjs.map +0 -1
- package/dist/esm/decoder/textDecoders/index.d.mts +0 -4
- package/dist/esm/decoder/textDecoders/index.mjs +0 -3
- package/dist/esm/decoder/textDecoders/nodeTextDecoder.d.mts +0 -2
- package/dist/esm/decoder/textDecoders/nodeTextDecoder.mjs +0 -10
- package/dist/esm/decoder/textDecoders/nodeTextDecoder.mjs.map +0 -1
- package/dist/esm/decoder-ByAWOgvm.d.mts.map +0 -1
- package/dist/esm/decoderBuffer-93dMcsbx.d.mts.map +0 -1
- package/dist/esm/encode-4SxHVw0M.d.mts +0 -5
- package/dist/esm/encode-4SxHVw0M.d.mts.map +0 -1
- package/dist/esm/encoder/encode.d.mts +0 -2
- package/dist/esm/encoder/encode.mjs +0 -11
- package/dist/esm/encoder/encode.mjs.map +0 -1
- package/dist/esm/index-B5vbV8Ak.d.mts +0 -1
- package/dist/esm/messagePackTextDecoder-J3fr-wQn.d.mts +0 -7
- package/dist/esm/messagePackTextDecoder-J3fr-wQn.d.mts.map +0 -1
- package/dist/esm/nodeTextDecoder-Dhre7WkB.d.mts +0 -9
- package/dist/esm/nodeTextDecoder-Dhre7WkB.d.mts.map +0 -1
- package/dist/esm/types-CNR_qJsr.d.mts +0 -9
- package/dist/esm/types-CNR_qJsr.d.mts.map +0 -1
- package/dist/esm/types-DTcs4Mkd.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -6,18 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# @schema-pack/message-pack
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
<a href='/docs/message-pack'>
|
|
11
|
-
Documentation
|
|
12
|
-
</a>
|
|
13
|
-
|
|
|
14
|
-
<a href='/docs/message-pack/install'>
|
|
15
|
-
Quick start
|
|
16
|
-
</a>
|
|
17
|
-
</p>
|
|
18
|
-
|
|
19
|
-
Incremental
|
|
20
|
-
[MessagePack](https://github.com/msgpack/msgpack/blob/master/spec.md)
|
|
9
|
+
A [MessagePack](https://github.com/msgpack/msgpack/blob/master/spec.md)
|
|
21
10
|
encoder/decoder for TypeScript and JavaScript. It targets full compliance with
|
|
22
11
|
the MessagePack spec and exposes a pluggable extension system for encoding
|
|
23
12
|
custom types.
|
|
@@ -25,9 +14,138 @@ custom types.
|
|
|
25
14
|
## Installation
|
|
26
15
|
|
|
27
16
|
```bash
|
|
28
|
-
pnpm add @schema-pack/message-pack
|
|
17
|
+
pnpm add @schema-pack/message-pack
|
|
29
18
|
```
|
|
30
19
|
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { Decoder, Encoder } from '@schema-pack/message-pack';
|
|
24
|
+
|
|
25
|
+
const encoder = new Encoder();
|
|
26
|
+
const bytes = encoder.encode({ hello: 'world', values: [1, 2, 3] });
|
|
27
|
+
|
|
28
|
+
const decoder = new Decoder();
|
|
29
|
+
const value = decoder.decode(bytes);
|
|
30
|
+
// { hello: 'world', values: [1, 2, 3] }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## The 64-bit integer caveat
|
|
34
|
+
|
|
35
|
+
JavaScript numbers are IEEE 754 double-precision floats, so they can only
|
|
36
|
+
represent integers safely between `Number.MIN_SAFE_INTEGER` and
|
|
37
|
+
`Number.MAX_SAFE_INTEGER` (±(2^53 - 1)) — exported here as `INT64_MIN` and
|
|
38
|
+
`UINT64_MAX`. MessagePack's native `uint 64` / `int 64` formats, however, cover
|
|
39
|
+
the _full_ 64-bit range.
|
|
40
|
+
|
|
41
|
+
By default, the encoder and decoder read and write these formats as regular JS
|
|
42
|
+
`number`s, which is safe as long as your values stay within that safe integer
|
|
43
|
+
range. If you need the full 64-bit range — or want to work with `bigint`
|
|
44
|
+
directly — register the built-in `BigIntExtension`:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { BigIntExtension, Decoder, Encoder } from '@schema-pack/message-pack';
|
|
48
|
+
|
|
49
|
+
const extension = new BigIntExtension(); // extension type 0-127, defaults to 0
|
|
50
|
+
|
|
51
|
+
const encoder = new Encoder().addExtension(extension);
|
|
52
|
+
const decoder = new Decoder().addExtension(extension);
|
|
53
|
+
|
|
54
|
+
const bytes = encoder.encode(123_456_789_012_345_678_901_234_567_890n);
|
|
55
|
+
decoder.decode(bytes); // 123456789012345678901234567890n
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Values within the safe integer range are still encoded as native MessagePack
|
|
59
|
+
`uint`/`int` formats even with the extension registered — `BigIntExtension` only
|
|
60
|
+
takes over once a `bigint` value falls outside that range.
|
|
61
|
+
|
|
62
|
+
## Built-in extensions
|
|
63
|
+
|
|
64
|
+
- **`BigIntExtension`** — encodes/decodes `bigint` values outside the safe
|
|
65
|
+
integer range, using a variable-length representation of the value's magnitude
|
|
66
|
+
plus sign.
|
|
67
|
+
- **`TimestampDateExtension`** — encodes/decodes JS `Date` objects using the
|
|
68
|
+
standard MessagePack
|
|
69
|
+
[timestamp extension type](https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type)
|
|
70
|
+
(`-1`), automatically choosing the 32-bit, 64-bit, or 96-bit format based on
|
|
71
|
+
the date's range and precision. Because it uses the reserved timestamp type,
|
|
72
|
+
register it as an _internal_ extension:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import {
|
|
76
|
+
Decoder,
|
|
77
|
+
Encoder,
|
|
78
|
+
TimestampDateExtension,
|
|
79
|
+
} from '@schema-pack/message-pack';
|
|
80
|
+
|
|
81
|
+
const extension = new TimestampDateExtension();
|
|
82
|
+
|
|
83
|
+
const encoder = new Encoder().addInternalExtension(extension);
|
|
84
|
+
const decoder = new Decoder().addInternalExtension(extension);
|
|
85
|
+
|
|
86
|
+
const bytes = encoder.encode(new Date());
|
|
87
|
+
decoder.decode(bytes); // Date instance
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Writing your own extensions
|
|
91
|
+
|
|
92
|
+
Implement the `MessagePackExtension<TValue, TBuffer>` interface (or extend the
|
|
93
|
+
abstract `UntypedExtension` helper, which takes care of storing `type`):
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
interface MessagePackExtension<
|
|
97
|
+
TValue = unknown,
|
|
98
|
+
TBuffer extends Uint8Array = Uint8Array,
|
|
99
|
+
> {
|
|
100
|
+
readonly type: number;
|
|
101
|
+
encode(
|
|
102
|
+
value: object | bigint,
|
|
103
|
+
buffer: MessagePackEncoderBuffer<TBuffer>,
|
|
104
|
+
): void;
|
|
105
|
+
decode(decoderBuffer: MessagePackDecoderBuffer, size: number): TValue;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Then register it on both the encoder and the decoder:
|
|
110
|
+
|
|
111
|
+
- `addExtension(extension)` — custom extension types, in the range `0` to `127`.
|
|
112
|
+
- `addExtensionType(type, extension)` — same as above, with the type passed as a
|
|
113
|
+
separate argument.
|
|
114
|
+
- `addInternalExtension(extension)` — reserved types, in the range `-128` to
|
|
115
|
+
`-1`, used for spec-defined extensions such as timestamps.
|
|
116
|
+
- `fetchExtension(type)` — look up a registered extension by its type.
|
|
117
|
+
|
|
118
|
+
Inside `encode()`, the buffer argument exposes low-level writers (`writeUint8`,
|
|
119
|
+
`writeUint32`, `writeBin`, `ensureCapacity`, `view`, `offset`, etc.) for
|
|
120
|
+
building a custom binary payload — see the `MessagePackEncoderBuffer` interface
|
|
121
|
+
for the full API.
|
|
122
|
+
|
|
123
|
+
## Encoder options
|
|
124
|
+
|
|
125
|
+
| Option | Default | Description |
|
|
126
|
+
| ------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
127
|
+
| `initialBufferSize` | `1024` | Initial size of the encoding buffer; grows automatically as needed. |
|
|
128
|
+
| `newBufferFn` | `(size) => new Uint8Array(size)` | Factory used to allocate new buffers. |
|
|
129
|
+
| `initialSharedBufferSize` | `1024` | Initial size of the shared buffer used when encoding strings, to reduce allocations. |
|
|
130
|
+
| `textEncoder` | `DefaultTextEncoder` | Encoder used to turn strings into bytes. A `NodeTextEncoder` is also provided for faster string encoding on Node. |
|
|
131
|
+
| `sortKeys` | `false` | Sort object keys before encoding, for deterministic output. |
|
|
132
|
+
| `forceFloat32` | `false` | Always encode floating point numbers as `float32` instead of `float64`. This may lose precision for values that don't fit exactly in 32 bits (e.g. `1.2`) — only enable it if you know your floats can round-trip safely. |
|
|
133
|
+
|
|
134
|
+
## Decoder options
|
|
135
|
+
|
|
136
|
+
| Option | Default | Description |
|
|
137
|
+
| ------------------- | -------------------------------- | ------------------------------------------------------------------- |
|
|
138
|
+
| `initialBufferSize` | `1024` | Initial size of the decoding buffer; grows automatically as needed. |
|
|
139
|
+
| `newBufferFn` | `(size) => new Uint8Array(size)` | Factory used to allocate new buffers. |
|
|
140
|
+
|
|
141
|
+
## Error handling
|
|
142
|
+
|
|
143
|
+
The encoder and decoder currently throw plain `Error`s for invalid usage — e.g.
|
|
144
|
+
registering a duplicate or out-of-range extension type, looking up an extension
|
|
145
|
+
that isn't registered, or decoding a malformed timestamp payload. There's no
|
|
146
|
+
dedicated error class hierarchy yet, so catch `Error` and inspect `message` if
|
|
147
|
+
you need to branch on failure.
|
|
148
|
+
|
|
31
149
|
## License
|
|
32
150
|
|
|
33
151
|
MIT
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as MessagePackDecoderBuffer } from "./messagePackDecoderBuffer-
|
|
2
|
-
import { i as ExtensionEncoderBuffer } from "./messagePackExtension-
|
|
3
|
-
import { t as UntypedExtension } from "./untypedExtension-
|
|
1
|
+
import { t as MessagePackDecoderBuffer } from "./messagePackDecoderBuffer-CMG0LPbJ.cjs";
|
|
2
|
+
import { i as ExtensionEncoderBuffer } from "./messagePackExtension-C_TQXlEn.cjs";
|
|
3
|
+
import { t as UntypedExtension } from "./untypedExtension-WQvArYoO.cjs";
|
|
4
4
|
//#region src/extensions/bigint/bigInt.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* This class encodes and decodes JavaScript BigInt values that are outside the
|
|
@@ -32,4 +32,4 @@ declare class BigIntExtension<TBuffer extends Uint8Array = Uint8Array> extends U
|
|
|
32
32
|
}
|
|
33
33
|
//#endregion
|
|
34
34
|
export { BigIntExtension as t };
|
|
35
|
-
//# sourceMappingURL=bigInt-
|
|
35
|
+
//# sourceMappingURL=bigInt-CBB8PGpe.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bigInt-
|
|
1
|
+
{"version":3,"file":"bigInt-CBB8PGpe.d.cts","names":[],"sources":["../../src/extensions/bigint/bigInt.ts"],"mappings":";;;;;;;;;;;;cAcM,gBACJ,gBAAgB,aAAa,oBACrB,yBAAyB;;;;;;;;;;;;EAYjC,OACE,wBACA,QAAQ,uBAAuB;;;;;;EAyBjC,OAAO,QAAQ,0BAA0B"}
|
package/dist/{esm/bufferWithExtensions-DzAs7yX1.d.mts → cjs/bufferWithExtensions-BAinwJsn.d.cts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as MessagePackBufferWithExtensions, t as MessagePackExtension } from "./messagePackExtension-
|
|
1
|
+
import { o as MessagePackBufferWithExtensions, t as MessagePackExtension } from "./messagePackExtension-C_TQXlEn.cjs";
|
|
2
2
|
//#region src/bufferWithExtensions.d.ts
|
|
3
3
|
declare abstract class BufferWithExtensions<TBuffer extends Uint8Array = Uint8Array> implements MessagePackBufferWithExtensions<TBuffer> {
|
|
4
4
|
protected extensions: Map<number, MessagePackExtension<unknown, TBuffer>>;
|
|
@@ -9,4 +9,4 @@ declare abstract class BufferWithExtensions<TBuffer extends Uint8Array = Uint8Ar
|
|
|
9
9
|
}
|
|
10
10
|
//#endregion
|
|
11
11
|
export { BufferWithExtensions as t };
|
|
12
|
-
//# sourceMappingURL=bufferWithExtensions-
|
|
12
|
+
//# sourceMappingURL=bufferWithExtensions-BAinwJsn.d.cts.map
|
package/dist/cjs/{bufferWithExtensions-n6DtcUoA.d.cts.map → bufferWithExtensions-BAinwJsn.d.cts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferWithExtensions-
|
|
1
|
+
{"version":3,"file":"bufferWithExtensions-BAinwJsn.d.cts","names":[],"sources":["../../src/bufferWithExtensions.ts"],"mappings":";;uBAGe,qBACb,gBAAgB,aAAa,uBAClB,gCAAgC;YACjC,YAAY,YAAY,8BAA8B;EAEhE;EAIA,aAAa,WAAW,8BAA8B;EAsBtD,qBACE,WAAW,8BAA8B;EAuB3C,eAAe,eAAe,8BAA8B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as BufferWithExtensions } from "./bufferWithExtensions-
|
|
1
|
+
import { t as BufferWithExtensions } from "./bufferWithExtensions-BAinwJsn.cjs";
|
|
2
2
|
export = BufferWithExtensions;
|
|
@@ -6,7 +6,7 @@ var Decoder = class {
|
|
|
6
6
|
this.decoderBuffer = new require_decoder_decoderBuffer(options);
|
|
7
7
|
}
|
|
8
8
|
decode(encodedBuffer) {
|
|
9
|
-
const decoderBuffer = this
|
|
9
|
+
const { decoderBuffer } = this;
|
|
10
10
|
decoderBuffer.setBuffer(encodedBuffer);
|
|
11
11
|
return decoderBuffer.nextValue();
|
|
12
12
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as Decoder } from "../decoder-
|
|
1
|
+
import { t as Decoder } from "../decoder-C1cd4I8S.cjs";
|
|
2
2
|
export = Decoder;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_bufferWithExtensions = require("../bufferWithExtensions.cjs");
|
|
2
|
+
require("../constants.cjs");
|
|
2
3
|
const require_defaultNewBufferFn = require("../defaultNewBufferFn.cjs");
|
|
3
4
|
const require_symbols = require("../symbols.cjs");
|
|
4
5
|
const require_decoder_textDecoders_defaultTextDecoder = require("./textDecoders/defaultTextDecoder.cjs");
|
|
@@ -10,8 +11,8 @@ var DecoderBuffer = class extends require_bufferWithExtensions {
|
|
|
10
11
|
textDecoder = new require_decoder_textDecoders_defaultTextDecoder();
|
|
11
12
|
constructor(options) {
|
|
12
13
|
super();
|
|
13
|
-
const
|
|
14
|
-
this.buffer =
|
|
14
|
+
const newBufferFn = options?.newBufferFn ?? require_defaultNewBufferFn;
|
|
15
|
+
this.buffer = newBufferFn(options?.initialBufferSize ?? 1024);
|
|
15
16
|
this.view = new DataView(this.buffer.buffer);
|
|
16
17
|
this.offset = 0;
|
|
17
18
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as DecoderBuffer } from "../decoderBuffer-
|
|
1
|
+
import { t as DecoderBuffer } from "../decoderBuffer-C9_0y-3q.cjs";
|
|
2
2
|
export = DecoderBuffer;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_decoder_textDecoders_defaultTextDecoder = require("./textDecoders/defaultTextDecoder.cjs");
|
|
3
|
-
const require_decoder_textDecoders_nodeTextDecoder = require("./textDecoders/nodeTextDecoder.cjs");
|
|
4
2
|
const require_decoder_decoderBuffer = require("./decoderBuffer.cjs");
|
|
5
3
|
const require_decoder_decoder = require("./decoder.cjs");
|
|
6
|
-
const require_decoder_decode = require("./decode.cjs");
|
|
7
4
|
exports.Decoder = require_decoder_decoder;
|
|
8
5
|
exports.DecoderBuffer = require_decoder_decoderBuffer;
|
|
9
|
-
exports.DefaultTextDecoder = require_decoder_textDecoders_defaultTextDecoder;
|
|
10
|
-
exports.NodeTextDecoder = require_decoder_textDecoders_nodeTextDecoder;
|
|
11
|
-
exports.decode = require_decoder_decode;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { t as MessagePackTextDecoder } from "../messagePackTextDecoder-
|
|
2
|
-
import { t as MessagePackDecoderBuffer } from "../messagePackDecoderBuffer-
|
|
3
|
-
import { t as
|
|
4
|
-
import { t as
|
|
5
|
-
|
|
6
|
-
import { t as Decoder } from "../decoder-3WpVBZjY.cjs";
|
|
7
|
-
import { t as NodeTextDecoder } from "../nodeTextDecoder-DrNFdTVk.cjs";
|
|
8
|
-
export { Decoder, DecoderBuffer, DefaultTextDecoder, type MessagePackDecoderBuffer, type MessagePackTextDecoder, NodeTextDecoder, decode };
|
|
1
|
+
import { t as MessagePackTextDecoder } from "../messagePackTextDecoder-CtyB0N6j.cjs";
|
|
2
|
+
import { t as MessagePackDecoderBuffer } from "../messagePackDecoderBuffer-CMG0LPbJ.cjs";
|
|
3
|
+
import { t as DecoderBuffer } from "../decoderBuffer-C9_0y-3q.cjs";
|
|
4
|
+
import { t as Decoder } from "../decoder-C1cd4I8S.cjs";
|
|
5
|
+
export { Decoder, DecoderBuffer, type MessagePackDecoderBuffer, type MessagePackTextDecoder };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as MessagePackTextDecoder } from "../../messagePackTextDecoder-
|
|
2
|
-
import { t as MessagePackDecoderBuffer } from "../../messagePackDecoderBuffer-
|
|
1
|
+
import { t as MessagePackTextDecoder } from "../../messagePackTextDecoder-CtyB0N6j.cjs";
|
|
2
|
+
import { t as MessagePackDecoderBuffer } from "../../messagePackDecoderBuffer-CMG0LPbJ.cjs";
|
|
3
3
|
import "../../index-CaxrMD1A.cjs";
|
|
4
4
|
export type { MessagePackDecoderBuffer, MessagePackTextDecoder };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as MessagePackDecoderBuffer } from "../../messagePackDecoderBuffer-
|
|
1
|
+
import { t as MessagePackDecoderBuffer } from "../../messagePackDecoderBuffer-CMG0LPbJ.cjs";
|
|
2
2
|
export = MessagePackDecoderBuffer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as MessagePackTextDecoder } from "../../messagePackTextDecoder-
|
|
1
|
+
import { t as MessagePackTextDecoder } from "../../messagePackTextDecoder-CtyB0N6j.cjs";
|
|
2
2
|
export = MessagePackTextDecoder;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as DefaultTextDecoder } from "../../defaultTextDecoder-
|
|
1
|
+
import { t as DefaultTextDecoder } from "../../defaultTextDecoder-Ji2hTZkf.cjs";
|
|
2
2
|
export = DefaultTextDecoder;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as DecoderBufferOptions } from "../types-
|
|
1
|
+
import { t as DecoderBufferOptions } from "../types-DHnp4kMw.cjs";
|
|
2
2
|
export { DecoderBufferOptions };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as MessagePackExtension } from "./messagePackExtension-
|
|
2
|
-
import { t as DecoderBufferOptions } from "./types-
|
|
3
|
-
import { t as DecoderBuffer } from "./decoderBuffer-
|
|
1
|
+
import { t as MessagePackExtension } from "./messagePackExtension-C_TQXlEn.cjs";
|
|
2
|
+
import { t as DecoderBufferOptions } from "./types-DHnp4kMw.cjs";
|
|
3
|
+
import { t as DecoderBuffer } from "./decoderBuffer-C9_0y-3q.cjs";
|
|
4
4
|
//#region src/decoder/decoder.d.ts
|
|
5
5
|
declare class Decoder<TBuffer extends Uint8Array = Uint8Array> {
|
|
6
6
|
protected decoderBuffer: DecoderBuffer<TBuffer>;
|
|
@@ -12,4 +12,4 @@ declare class Decoder<TBuffer extends Uint8Array = Uint8Array> {
|
|
|
12
12
|
}
|
|
13
13
|
//#endregion
|
|
14
14
|
export { Decoder as t };
|
|
15
|
-
//# sourceMappingURL=decoder-
|
|
15
|
+
//# sourceMappingURL=decoder-C1cd4I8S.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoder-C1cd4I8S.d.cts","names":[],"sources":["../../src/decoder/decoder.ts"],"mappings":";;;;cAUM,QAAQ,gBAAgB,aAAa;YAC/B,eAAe,cAAc;EAEvC,YAAY,UAAU,qBAAqB;EAK3C,OAAO,kBAAkB,eAAe,UAAU;EAoBlD,aAAa,WAAW,8BAA8B;EAMtD,qBACE,WAAW,8BAA8B;EAO3C,iBACE,cACA,WAAW,KAAK,8BAA8B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as MessagePackDecoderBuffer } from "./messagePackDecoderBuffer-
|
|
2
|
-
import { t as BufferWithExtensions } from "./bufferWithExtensions-
|
|
3
|
-
import { t as DefaultTextDecoder } from "./defaultTextDecoder-
|
|
4
|
-
import { t as DecoderBufferOptions } from "./types-
|
|
1
|
+
import { t as MessagePackDecoderBuffer } from "./messagePackDecoderBuffer-CMG0LPbJ.cjs";
|
|
2
|
+
import { t as BufferWithExtensions } from "./bufferWithExtensions-BAinwJsn.cjs";
|
|
3
|
+
import { t as DefaultTextDecoder } from "./defaultTextDecoder-Ji2hTZkf.cjs";
|
|
4
|
+
import { t as DecoderBufferOptions } from "./types-DHnp4kMw.cjs";
|
|
5
5
|
//#region src/decoder/decoderBuffer.d.ts
|
|
6
6
|
declare class DecoderBuffer<TBuffer extends Uint8Array = Uint8Array> extends BufferWithExtensions<TBuffer> implements MessagePackDecoderBuffer<TBuffer> {
|
|
7
7
|
buffer: TBuffer;
|
|
@@ -19,4 +19,4 @@ declare class DecoderBuffer<TBuffer extends Uint8Array = Uint8Array> extends Buf
|
|
|
19
19
|
}
|
|
20
20
|
//#endregion
|
|
21
21
|
export { DecoderBuffer as t };
|
|
22
|
-
//# sourceMappingURL=decoderBuffer-
|
|
22
|
+
//# sourceMappingURL=decoderBuffer-C9_0y-3q.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoderBuffer-C9_0y-3q.d.cts","names":[],"sources":["../../src/decoder/decoderBuffer.ts"],"mappings":";;;;;cASM,cAAc,gBAAgB,aAAa,oBACvC,qBAAqB,oBAClB,yBAAyB;EAEpC,QAAQ;EACR;EACA,MAAM;EACN,aAAW;EAEX,YAAY,UAAU,qBAAqB;EAY3C,UAAU,QAAQ;EAYlB,UAAU;EAcV,QAAQ;EAkDR;EAIA,QAAQ,iBAAiB;EAoBzB,kBAAkB;EAgLlB,UAAU,qBAAqB"}
|
package/dist/{esm/defaultTextDecoder-DztyzoBV.d.mts → cjs/defaultTextDecoder-Ji2hTZkf.d.cts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as MessagePackTextDecoder } from "./messagePackTextDecoder-
|
|
1
|
+
import { t as MessagePackTextDecoder } from "./messagePackTextDecoder-CtyB0N6j.cjs";
|
|
2
2
|
//#region src/decoder/textDecoders/defaultTextDecoder.d.ts
|
|
3
3
|
declare class DefaultTextDecoder implements MessagePackTextDecoder {
|
|
4
4
|
protected textDecoder: TextDecoder;
|
|
@@ -7,4 +7,4 @@ declare class DefaultTextDecoder implements MessagePackTextDecoder {
|
|
|
7
7
|
}
|
|
8
8
|
//#endregion
|
|
9
9
|
export { DefaultTextDecoder as t };
|
|
10
|
-
//# sourceMappingURL=defaultTextDecoder-
|
|
10
|
+
//# sourceMappingURL=defaultTextDecoder-Ji2hTZkf.d.cts.map
|
package/dist/cjs/{defaultTextDecoder-DY92jDSO.d.cts.map → defaultTextDecoder-Ji2hTZkf.d.cts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultTextDecoder-
|
|
1
|
+
{"version":3,"file":"defaultTextDecoder-Ji2hTZkf.d.cts","names":[],"sources":["../../src/decoder/textDecoders/defaultTextDecoder.ts"],"mappings":";;cAEM,8BAA8B;YACxB,aAAa;EAEvB;EAIA,OAAO,QAAQ,YAAY,eAAe"}
|
|
@@ -14,9 +14,9 @@ var Encoder = class {
|
|
|
14
14
|
this.buffer = new require_encoder_encoderBuffer(options);
|
|
15
15
|
}
|
|
16
16
|
encode(value) {
|
|
17
|
-
const buffer = this
|
|
17
|
+
const { buffer } = this;
|
|
18
18
|
buffer.write(value);
|
|
19
|
-
return buffer.flush();
|
|
19
|
+
return this.buffer.flush();
|
|
20
20
|
}
|
|
21
21
|
addExtension(extension) {
|
|
22
22
|
this.buffer.addExtension(extension);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as Encoder } from "../encoder-
|
|
1
|
+
import { t as Encoder } from "../encoder-DXuhGwd7.cjs";
|
|
2
2
|
export = Encoder;
|
|
@@ -39,7 +39,7 @@ var EncoderBuffer = class EncoderBuffer extends require_bufferWithExtensions {
|
|
|
39
39
|
* to accommodate the data being written. The function should return a new
|
|
40
40
|
* instance of TBuffer with the specified size.
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
newBufferFn;
|
|
43
43
|
textEncoder;
|
|
44
44
|
buffer;
|
|
45
45
|
view;
|
|
@@ -58,25 +58,25 @@ var EncoderBuffer = class EncoderBuffer extends require_bufferWithExtensions {
|
|
|
58
58
|
super();
|
|
59
59
|
this.offset = 0;
|
|
60
60
|
this.textEncoder = options?.textEncoder ?? new require_encoder_textEncoders_defaultTextEncoder();
|
|
61
|
-
this.
|
|
62
|
-
this.buffer = this.
|
|
63
|
-
this.sharedBuffer = this.
|
|
61
|
+
this.newBufferFn = options?.newBufferFn ?? require_defaultNewBufferFn;
|
|
62
|
+
this.buffer = this.newBufferFn(options?.initialBufferSize ?? 1024);
|
|
63
|
+
this.sharedBuffer = this.newBufferFn(options?.initialSharedBufferSize ?? 1024);
|
|
64
64
|
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
65
65
|
this.sortKeys = options?.sortKeys ?? false;
|
|
66
66
|
this.forceFloat32 = options?.forceFloat32 ?? false;
|
|
67
67
|
}
|
|
68
68
|
getExtensionBuffer() {
|
|
69
69
|
if (!this.#extensionBuffer) this.#extensionBuffer = new EncoderBuffer({
|
|
70
|
-
bufferFactory: this.bufferFactory,
|
|
71
70
|
initialBufferSize: this.sharedBuffer.byteLength,
|
|
72
71
|
initialSharedBufferSize: 0,
|
|
72
|
+
newBufferFn: this.newBufferFn,
|
|
73
73
|
sortKeys: this.sortKeys,
|
|
74
74
|
textEncoder: this.textEncoder
|
|
75
75
|
});
|
|
76
76
|
return this.#extensionBuffer;
|
|
77
77
|
}
|
|
78
78
|
resizeBuffer(newSize) {
|
|
79
|
-
const newBuffer = this.
|
|
79
|
+
const newBuffer = this.newBufferFn(newSize);
|
|
80
80
|
newBuffer.set(this.buffer);
|
|
81
81
|
this.buffer = newBuffer;
|
|
82
82
|
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
@@ -392,8 +392,8 @@ var EncoderBuffer = class EncoderBuffer extends require_bufferWithExtensions {
|
|
|
392
392
|
}
|
|
393
393
|
this.offset = initialoffset;
|
|
394
394
|
}
|
|
395
|
-
if (this.sharedBuffer.byteLength < requiredSize) this.sharedBuffer = this.
|
|
396
|
-
const sharedBuffer = this
|
|
395
|
+
if (this.sharedBuffer.byteLength < requiredSize) this.sharedBuffer = this.newBufferFn(requiredSize);
|
|
396
|
+
const { sharedBuffer } = this;
|
|
397
397
|
const byteLength = this.textEncoder.writeBytes(value, sharedBuffer);
|
|
398
398
|
if (require_utils_fitIn8Bits(byteLength)) {
|
|
399
399
|
this.ensureCapacity(2 + byteLength);
|
|
@@ -462,13 +462,18 @@ var EncoderBuffer = class EncoderBuffer extends require_bufferWithExtensions {
|
|
|
462
462
|
} else if (this.forceFloat32) {
|
|
463
463
|
this.ensureCapacity(5);
|
|
464
464
|
this.writeFloat32Symbol();
|
|
465
|
-
|
|
465
|
+
this.writeFloat32(value);
|
|
466
|
+
} else {
|
|
467
|
+
this.ensureCapacity(9);
|
|
468
|
+
this.writeFloat64Symbol();
|
|
469
|
+
this.writeFloat64(value);
|
|
466
470
|
}
|
|
467
|
-
this
|
|
468
|
-
this.writeFloat64Symbol();
|
|
469
|
-
return this.writeFloat64(value);
|
|
471
|
+
return this;
|
|
470
472
|
}
|
|
471
|
-
|
|
473
|
+
writeMap(value) {
|
|
474
|
+
const keys = Object.keys(value);
|
|
475
|
+
if (this.sortKeys) keys.sort();
|
|
476
|
+
const keysLength = keys.length;
|
|
472
477
|
const requiredSize = keysLength * 4;
|
|
473
478
|
if (keysLength < 16) {
|
|
474
479
|
this.ensureCapacity(requiredSize + 1);
|
|
@@ -479,21 +484,15 @@ var EncoderBuffer = class EncoderBuffer extends require_bufferWithExtensions {
|
|
|
479
484
|
} else if (require_utils_fitIn32Bits(keysLength)) {
|
|
480
485
|
this.ensureCapacity(requiredSize + 5);
|
|
481
486
|
this.writeMap32Symbol(keysLength);
|
|
482
|
-
} else throw new Error(`Map
|
|
483
|
-
return this;
|
|
484
|
-
}
|
|
485
|
-
writeMap(value) {
|
|
486
|
-
const keys = Object.keys(value);
|
|
487
|
-
if (this.sortKeys) keys.sort();
|
|
488
|
-
const keysLength = keys.length;
|
|
489
|
-
this.openMap(keysLength);
|
|
487
|
+
} else throw new Error(`Map too large to encode: ${keysLength} keys`);
|
|
490
488
|
for (const key of keys) {
|
|
491
|
-
this.
|
|
489
|
+
this.write(key);
|
|
492
490
|
this.write(value[key]);
|
|
493
491
|
}
|
|
494
492
|
return this;
|
|
495
493
|
}
|
|
496
|
-
|
|
494
|
+
writeArray(value) {
|
|
495
|
+
const length = value.length;
|
|
497
496
|
const requiredSize = length * 4;
|
|
498
497
|
if (length < 16) {
|
|
499
498
|
this.ensureCapacity(requiredSize + 1);
|
|
@@ -504,12 +503,7 @@ var EncoderBuffer = class EncoderBuffer extends require_bufferWithExtensions {
|
|
|
504
503
|
} else if (require_utils_fitIn32Bits(length)) {
|
|
505
504
|
this.ensureCapacity(requiredSize + 5);
|
|
506
505
|
this.writeArray32Symbol(length);
|
|
507
|
-
} else throw new Error(`Array
|
|
508
|
-
return this;
|
|
509
|
-
}
|
|
510
|
-
writeArray(value) {
|
|
511
|
-
const length = value.length;
|
|
512
|
-
this.openArray(length);
|
|
506
|
+
} else throw new Error(`Array too large to encode: ${length}`);
|
|
513
507
|
for (let index = 0; index < length; ++index) this.write(value[index]);
|
|
514
508
|
return this;
|
|
515
509
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as EncoderBuffer } from "../encoderBuffer-
|
|
1
|
+
import { t as EncoderBuffer } from "../encoderBuffer-DWGIXXjj.cjs";
|
|
2
2
|
export = EncoderBuffer;
|
|
@@ -3,9 +3,7 @@ const require_encoder_textEncoders_defaultTextEncoder = require("./textEncoders/
|
|
|
3
3
|
const require_encoder_encoderBuffer = require("./encoderBuffer.cjs");
|
|
4
4
|
const require_encoder_encoder = require("./encoder.cjs");
|
|
5
5
|
const require_encoder_textEncoders_nodeTextEncoder = require("./textEncoders/nodeTextEncoder.cjs");
|
|
6
|
-
const require_encoder_encode = require("./encode.cjs");
|
|
7
6
|
exports.DefaultTextEncoder = require_encoder_textEncoders_defaultTextEncoder;
|
|
8
7
|
exports.Encoder = require_encoder_encoder;
|
|
9
8
|
exports.EncoderBuffer = require_encoder_encoderBuffer;
|
|
10
9
|
exports.NodeTextEncoder = require_encoder_textEncoders_nodeTextEncoder;
|
|
11
|
-
exports.encode = require_encoder_encode;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { a as OmitByPattern, i as ExtensionEncoderBuffer, n as MessagePackEncoderBuffer, r as EncoderBufferOptions } from "../messagePackExtension-
|
|
1
|
+
import { a as OmitByPattern, i as ExtensionEncoderBuffer, n as MessagePackEncoderBuffer, r as EncoderBufferOptions } from "../messagePackExtension-C_TQXlEn.cjs";
|
|
2
2
|
import { t as MessagePackTextEncoder } from "../messagePackTextEncoder-D7iCft_t.cjs";
|
|
3
|
-
import { t as
|
|
4
|
-
import { t as
|
|
5
|
-
import { t as Encoder } from "../encoder-B-rTvI4P.cjs";
|
|
3
|
+
import { t as EncoderBuffer } from "../encoderBuffer-DWGIXXjj.cjs";
|
|
4
|
+
import { t as Encoder } from "../encoder-DXuhGwd7.cjs";
|
|
6
5
|
import { t as DefaultTextEncoder } from "../defaultTextEncoder-DzdGBX6s.cjs";
|
|
7
6
|
import { t as NodeTextEncoder } from "../nodeTextEncoder-DJzFDBXd.cjs";
|
|
8
|
-
export { DefaultTextEncoder, Encoder, EncoderBuffer, type EncoderBufferOptions, type ExtensionEncoderBuffer, type MessagePackEncoderBuffer, type MessagePackTextEncoder, NodeTextEncoder, type OmitByPattern
|
|
7
|
+
export { DefaultTextEncoder, Encoder, EncoderBuffer, type EncoderBufferOptions, type ExtensionEncoderBuffer, type MessagePackEncoderBuffer, type MessagePackTextEncoder, NodeTextEncoder, type OmitByPattern };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as MessagePackEncoderBuffer } from "../../messagePackExtension-
|
|
1
|
+
import { n as MessagePackEncoderBuffer } from "../../messagePackExtension-C_TQXlEn.cjs";
|
|
2
2
|
import { t as MessagePackTextEncoder } from "../../messagePackTextEncoder-D7iCft_t.cjs";
|
|
3
|
-
import "../../index-
|
|
3
|
+
import "../../index-DeSJDZGk.cjs";
|
|
4
4
|
export type { MessagePackEncoderBuffer, MessagePackTextEncoder };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as MessagePackEncoderBuffer } from "../../messagePackExtension-
|
|
1
|
+
import { n as MessagePackEncoderBuffer } from "../../messagePackExtension-C_TQXlEn.cjs";
|
|
2
2
|
export = MessagePackEncoderBuffer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { t as DefaultTextEncoder } from "../../defaultTextEncoder-DzdGBX6s.cjs";
|
|
2
2
|
import { t as NodeTextEncoder } from "../../nodeTextEncoder-DJzFDBXd.cjs";
|
|
3
|
-
import "../../index-
|
|
3
|
+
import "../../index-DMnXy2Rv.cjs";
|
|
4
4
|
export { DefaultTextEncoder, NodeTextEncoder };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as OmitByPattern, i as ExtensionEncoderBuffer, r as EncoderBufferOptions } from "../messagePackExtension-
|
|
1
|
+
import { a as OmitByPattern, i as ExtensionEncoderBuffer, r as EncoderBufferOptions } from "../messagePackExtension-C_TQXlEn.cjs";
|
|
2
2
|
export { EncoderBufferOptions, ExtensionEncoderBuffer, OmitByPattern };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as EncoderBufferOptions, t as MessagePackExtension } from "./messagePackExtension-
|
|
2
|
-
import { t as EncoderBuffer } from "./encoderBuffer-
|
|
1
|
+
import { r as EncoderBufferOptions, t as MessagePackExtension } from "./messagePackExtension-C_TQXlEn.cjs";
|
|
2
|
+
import { t as EncoderBuffer } from "./encoderBuffer-DWGIXXjj.cjs";
|
|
3
3
|
//#region src/encoder/encoder.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The `Encoder` class is responsible for encoding JavaScript values into the
|
|
@@ -12,7 +12,7 @@ import { t as EncoderBuffer } from "./encoderBuffer-3ur0iCYR.cjs";
|
|
|
12
12
|
declare class Encoder<TBuffer extends Uint8Array = Uint8Array> {
|
|
13
13
|
buffer: EncoderBuffer<TBuffer>;
|
|
14
14
|
constructor(options?: Partial<EncoderBufferOptions<TBuffer>>);
|
|
15
|
-
encode(value: unknown):
|
|
15
|
+
encode(value: unknown): Uint8Array;
|
|
16
16
|
addExtension(extension: MessagePackExtension<unknown, TBuffer>): this;
|
|
17
17
|
addInternalExtension(extension: MessagePackExtension<unknown, TBuffer>): this;
|
|
18
18
|
addExtensionType(type: number, extension: Omit<MessagePackExtension<unknown, TBuffer>, 'type'>): this;
|
|
@@ -20,4 +20,4 @@ declare class Encoder<TBuffer extends Uint8Array = Uint8Array> {
|
|
|
20
20
|
}
|
|
21
21
|
//#endregion
|
|
22
22
|
export { Encoder as t };
|
|
23
|
-
//# sourceMappingURL=encoder-
|
|
23
|
+
//# sourceMappingURL=encoder-DXuhGwd7.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoder-
|
|
1
|
+
{"version":3,"file":"encoder-DXuhGwd7.d.cts","names":[],"sources":["../../src/encoder/encoder.ts"],"mappings":";;;;;;;;;;;cAYM,QAAQ,gBAAgB,aAAa;EACzC,QAAQ,cAAc;EAEtB,YAAY,UAAU,QAAQ,qBAAqB;EAInD,OAAO,iBAAiB;EAQxB,aAAa,WAAW,8BAA8B;EAMtD,qBACE,WAAW,8BAA8B;EAO3C,iBACE,cACA,WAAW,KAAK,8BAA8B;EAOhD,eAAe,eAAe,8BAA8B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as ExtensionEncoderBuffer, n as MessagePackEncoderBuffer, r as EncoderBufferOptions, t as MessagePackExtension } from "./messagePackExtension-
|
|
2
|
-
import {
|
|
1
|
+
import { i as ExtensionEncoderBuffer, n as MessagePackEncoderBuffer, r as EncoderBufferOptions, t as MessagePackExtension } from "./messagePackExtension-C_TQXlEn.cjs";
|
|
2
|
+
import { n as NewBufferFn } from "./types-BJie2edF.cjs";
|
|
3
3
|
import { t as MessagePackTextEncoder } from "./messagePackTextEncoder-D7iCft_t.cjs";
|
|
4
|
-
import { t as BufferWithExtensions } from "./bufferWithExtensions-
|
|
4
|
+
import { t as BufferWithExtensions } from "./bufferWithExtensions-BAinwJsn.cjs";
|
|
5
5
|
//#region src/encoder/encoderBuffer.d.ts
|
|
6
6
|
declare class EncoderBuffer<TBuffer extends Uint8Array = Uint8Array> extends BufferWithExtensions<TBuffer> implements MessagePackEncoderBuffer<TBuffer> {
|
|
7
7
|
#private;
|
|
@@ -35,7 +35,7 @@ declare class EncoderBuffer<TBuffer extends Uint8Array = Uint8Array> extends Buf
|
|
|
35
35
|
* to accommodate the data being written. The function should return a new
|
|
36
36
|
* instance of TBuffer with the specified size.
|
|
37
37
|
*/
|
|
38
|
-
protected
|
|
38
|
+
protected newBufferFn: NewBufferFn<TBuffer>;
|
|
39
39
|
readonly textEncoder: MessagePackTextEncoder<TBuffer>;
|
|
40
40
|
buffer: TBuffer;
|
|
41
41
|
view: DataView;
|
|
@@ -95,9 +95,7 @@ declare class EncoderBuffer<TBuffer extends Uint8Array = Uint8Array> extends Buf
|
|
|
95
95
|
writeExt32Symbol(type: number, size: number): this;
|
|
96
96
|
writeString(value: string): this;
|
|
97
97
|
writeNumber(value: number): this;
|
|
98
|
-
openMap(keysLength: number): this;
|
|
99
98
|
writeMap<TKey extends string | number, TValue>(value: Record<TKey, TValue>): this;
|
|
100
|
-
openArray(length: number): this;
|
|
101
99
|
writeArray(value: unknown[]): this;
|
|
102
100
|
writeUint8Array(value: Uint8Array): this;
|
|
103
101
|
writeExtension(extension: MessagePackExtension, buffer: ExtensionEncoderBuffer<TBuffer>): this;
|
|
@@ -108,4 +106,4 @@ declare class EncoderBuffer<TBuffer extends Uint8Array = Uint8Array> extends Buf
|
|
|
108
106
|
}
|
|
109
107
|
//#endregion
|
|
110
108
|
export { EncoderBuffer as t };
|
|
111
|
-
//# sourceMappingURL=encoderBuffer-
|
|
109
|
+
//# sourceMappingURL=encoderBuffer-DWGIXXjj.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoderBuffer-
|
|
1
|
+
{"version":3,"file":"encoderBuffer-DWGIXXjj.d.cts","names":[],"sources":["../../src/encoder/encoderBuffer.ts"],"mappings":";;;;;cAsBM,cAAc,gBAAgB,aAAa,oBACvC,qBAAqB,oBAClB,yBAAyB;;;EAGpC;;;;;;;YAQU,cAAc;;;;;;;WAQf;;;;;;;;WASA;;;;;;;YAQC,aAAa,YAAY;WAE1B,aAAa,uBAAuB;EAE7C,QAAQ;EACR,MAAM;EAcN,YAAY,UAAU,QAAQ,qBAAqB;EAwBnD,sBAAsB,cAAc;EAcpC,aAAa;EAeb,eAAe;EAUf;EAMA,SAAS;EAST,oBAAoB;EAMpB,oBAAoB;EAOpB,SAAS,OAAO;EAQhB,aAAa;EAOb,aAAa;EAOb,WAAW;EAMX,YAAY;EAOZ,YAAY;EAOZ,YAAY;EAaZ,UAAU;EAMV,WAAW;EAOX,WAAW;EAOX,WAAW;EA0BX,SAAS;EAMT;EAMA;EAMA;EAMA,kBAAkB;EAMlB,oBAAoB;EAMpB,kBAAkB;EAMlB,gBAAgB;EAOhB,iBAAiB;EAQjB,iBAAiB;EAQjB;EAMA;EAMA;EAMA;EAMA;EAMA;EAMA;EAMA;EAMA;EAMA;EAMA,gBAAgB;EAOhB,iBAAiB;EASjB,iBAAiB;EASjB,mBAAmB;EASnB,mBAAmB;EASnB,iBAAiB;EASjB,iBAAiB;EASjB,mBAAmB;EAOnB,mBAAmB;EAOnB,mBAAmB;EAOnB,mBAAmB;EAOnB,oBAAoB;EAOpB,gBAAgB,cAAc;EAQ9B,iBAAiB,cAAc;EAW/B,iBAAiB,cAAc;EAW/B,YAAY;EAyGZ,YAAY;EA4EZ,SAAS,8BAA8B,QACrC,OAAO,OAAO,MAAM;EAiCtB,WAAW;EAoCX,gBAAgB,OAAO;EAiBvB,eACE,WAAW,sBACX,QAAQ,uBAAuB;EAiDjC,yBAAyB;EAqBzB,YAAY;EAYZ,YAAY;EAkBZ,MAAM"}
|