You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> NOTE: This library is a fork of [msgpack/msgpack-javascript](https://github.com/msgpack/msgpack-javascript), with the following changes:
6
+
>
7
+
> - Improved bigint support. Bigints are no longer solely encoded as int64/uint64, which allows for greater compatibility with other MessagePack libraries. Additional decoding options are available as well.
8
+
> - Raw string decoding support. When decoding, strings can be decoded as Uint8Arrays. This supports reading non-UTF-8 encoded strings.
9
+
> - Number and binary map key support with Maps.
10
+
>
11
+
> The exact changes can be viewed [in this comparison](https://github.com/msgpack/msgpack-javascript/compare/1fc7622...algorand:msgpack-javascript:main).
12
+
5
13
This library is an implementation of **MessagePack** for TypeScript and JavaScript, providing a compact and efficient binary serialization format. Learn more about MessagePack at:
| intMode | IntMode |`IntMode.AS_ENCODED` if `useBigInt64` is `true` or `IntMode.UNSAFE_NUMBER` otherwise |
161
+
| rawBinaryStringKeys | boolean | false |
162
+
| rawBinaryStringValues | boolean | false |
163
+
| useMap | boolean | false |
164
+
| supportObjectNumberKeys | boolean | false |
165
+
| maxStrLength | number |`4_294_967_295` (UINT32_MAX) |
166
+
| maxBinLength | number |`4_294_967_295` (UINT32_MAX) |
167
+
| maxArrayLength | number |`4_294_967_295` (UINT32_MAX) |
168
+
| maxMapLength | number |`4_294_967_295` (UINT32_MAX) |
169
+
| maxExtLength | number |`4_294_967_295` (UINT32_MAX) |
161
170
162
171
You can use `max${Type}Length` to limit the length of each type decoded.
163
172
164
173
`intMode` determines whether decoded integers should be returned as numbers or bigints in different circumstances. The possible values are [described below](#intmode).
165
174
175
+
To skip UTF-8 decoding of strings, one or both of `rawBinaryStringKeys` and `rawBinaryStringValues` can be set to `true`. If enabled, strings are decoded into `Uint8Array`. `rawBinaryStringKeys` affects only map keys, while `rawBinaryStringValues` affect all other string values.
176
+
177
+
If `useMap` is enabled, maps are decoded into the `Map` container instead of plain objects. `Map` objects support a wider range of key types. Plain objects only support string keys (though you can enable `supportObjectNumberKeys` to coerce number keys to strings), while `Map` objects support strings, numbers, bigints, and Uint8Arrays.
178
+
166
179
##### `IntMode`
167
180
168
181
The `IntMode` enum defines different options for decoding integers. They are described below:
@@ -532,12 +545,12 @@ The mapping of integers varies on the setting of `intMode`.
532
545
| Date | timestamp ext family | Date (\*6) |
533
546
| bigint | int family | bigint |
534
547
535
-
*\*1 Both `null` and `undefined` are mapped to `nil` (`0xC0`) type, and are decoded into `null`
536
-
*\*2 MessagePack ints are decoded as either numbers or bigints depending on the [IntMode](#intmode) used during decoding.
537
-
*\*3 If you'd like to skip UTF-8 decoding of strings, set `useRawBinaryStrings: true`. In this case, strings are decoded into `Uint8Array`.
538
-
*\*4 Any `ArrayBufferView`s including NodeJS's `Buffer` are mapped to `bin` family, and are decoded into `Uint8Array`
539
-
*\*5 In handling `Object`, it is regarded as `Record<string, unknown>` in terms of TypeScript
540
-
*\*6 MessagePack timestamps may have nanoseconds, which will lost when it is decoded into JavaScript `Date`. This behavior can be overridden by registering `-1` for the extension codec.
548
+
-\*1 Both `null` and `undefined` are mapped to `nil` (`0xC0`) type, and are decoded into `null`
549
+
-\*2 MessagePack ints are decoded as either numbers or bigints depending on the [IntMode](#intmode) used during decoding.
550
+
-\*3 If you'd like to skip UTF-8 decoding of strings, enable one of `rawBinaryStringKeys` or `rawBinaryStringValues`. In that case, strings are decoded into `Uint8Array`.
551
+
-\*4 Any `ArrayBufferView`s including NodeJS's `Buffer` are mapped to `bin` family, and are decoded into `Uint8Array`
552
+
-\*5 In handling `Object`, it is regarded as `Record<string, unknown>` in terms of TypeScript
553
+
-\*6 MessagePack timestamps may have nanoseconds, which will lost when it is decoded into JavaScript `Date`. This behavior can be overridden by registering `-1` for the extension codec.
541
554
542
555
If you set `useBigInt64: true`, the following mapping is used:
543
556
@@ -554,9 +567,10 @@ If you set `useBigInt64: true`, the following mapping is used:
554
567
| Object | map family | Object |
555
568
| Date | timestamp ext family | Date |
556
569
557
-
*\*6 If the bigint is larger than the max value of uint64 or smaller than the min value of int64, then the behavior is undefined.
570
+
-\*6 If the bigint is larger than the max value of uint64 or smaller than the min value of int64, then the behavior is undefined.
571
+
572
+
-\*7 If the bigint is larger than the max value of uint64 or smaller than the min value of int64, then the behavior is undefined.
558
573
559
-
*\*7 If the bigint is larger than the max value of uint64 or smaller than the min value of int64, then the behavior is undefined.
560
574
## Prerequisites
561
575
562
576
This is a universal JavaScript library that supports major browsers and NodeJS.
0 commit comments