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
* Add an option `useBigInt64` to map JavaScript's BigInt to MessagePack's int64 and uint64 ([#223](https://github.com/msgpack/msgpack-javascript/pull/223))
8
8
* Drop IE11 support ([#221](https://github.com/msgpack/msgpack-javascript/pull/221))
9
9
* It also fixes [feature request: option to disable TEXT_ENCODING env check #219](https://github.com/msgpack/msgpack-javascript/issues/219)
10
-
*
10
+
* Change the interfaces of `Encoder` and `Decoder`, and describe the interfaces in README.md:
11
+
*`new Encoder(options: EncoderOptions)`: it takes the same named-options as `encode()`
12
+
*`new Decoder(options: DecoderOptions)`: it takes the same named-options as `decode()`
It encodes `data` into a single MessagePack-encoded object, and returns a byte array as `Uint8Array`. It throws errors if `data` is, or includes, a non-serializable object such as a `function` or a `symbol`.
It decodes `buffer` that includes multiple MessagePack-encoded objects, and returns decoded objects as a generator. See also `decodeMultiStream()`, which is an asynchronous variant of this function.
158
158
@@ -170,14 +170,12 @@ for (const object of decodeMulti(encoded)) {
It decodes `stream`, where `ReadableStreamLike<T>` is defined as `ReadableStream<T> | AsyncIterable<T>`, in an async iterable of byte arrays, and returns decoded object as `unknown` type, wrapped in `Promise`.
176
176
177
177
This function works asynchronously, and might CPU resources more efficiently compared with synchronous `decode()`, because it doesn't wait for the completion of downloading.
178
178
179
-
`DecodeAsyncOptions` is the same as `DecodeOptions` for `decode()`.
180
-
181
179
This function is designed to work with whatwg `fetch()` like this:
It is alike to `decodeAsync()` and `decodeArrayStream()`, but the input `stream` must consist of multiple MessagePack-encoded items. This is an asynchronous variant for `decodeMulti()`.
216
214
@@ -233,7 +231,7 @@ This function is available since v2.4.0; previously it was called as `decodeStre
233
231
234
232
### Reusing Encoder and Decoder instances
235
233
236
-
`Encoder` and `Decoder` classes is provided to have better performance by reusing instances:
234
+
`Encoder` and `Decoder` classes are provided to have better performance by reusing instances:
237
235
238
236
```typescript
239
237
import { deepStrictEqual } from"assert";
@@ -251,6 +249,8 @@ than `encode()` function, and reusing `Decoder` instance is about 2% faster
251
249
than `decode()` function. Note that the result should vary in environments
252
250
and data structure.
253
251
252
+
`Encoder` and `Decoder` take the same options as `encode()` and `decode()` respectively.
253
+
254
254
## Extension Types
255
255
256
256
To handle [MessagePack Extension Types](https://github.com/msgpack/msgpack/blob/master/spec.md#extension-types), this library provides `ExtensionCodec` class.
@@ -304,7 +304,7 @@ Not that extension types for custom objects must be `[0, 127]`, while `[-1, -128
304
304
305
305
#### ExtensionCodec context
306
306
307
-
When you use an extension codec, it might be necessary to have encoding/decoding state to keep track of which objects got encoded/re-created. To do this, pass a `context` to the `EncodeOptions` and `DecodeOptions`:
307
+
When you use an extension codec, it might be necessary to have encoding/decoding state to keep track of which objects got encoded/re-created. To do this, pass a `context` to the `EncoderOptions` and `DecoderOptions`:
this.context=(optionsas{context: ContextType}|undefined)?.contextasContextType;// needs a type assertion because EncoderOptions has no context property when ContextType is undefined
this.context=(optionsas{context: ContextType}|undefined)?.contextasContextType;// needs a type assertion because EncoderOptions has no context property when ContextType is undefined
0 commit comments