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
Copy file name to clipboardExpand all lines: README.md
+13-11Lines changed: 13 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ This is a JavaScript/ECMA-262 implementation of **MessagePack**, an efficient bi
6
6
7
7
https://msgpack.org/
8
8
9
-
This library is a universal JavaScript, meaning it is compatible with all the major browsers and NodeJS. In addition, because it is implemented in [TypeScript](https://www.typescriptlang.org/), type definition files (`d.ts`) are bundled in the distribution.
9
+
This library is a universal JavaScript, meaning it is compatible with all the major browsers and NodeJS. In addition, because it is implemented in [TypeScript](https://www.typescriptlang.org/), type definition files (`d.ts`) are always up-to-date and bundled in the distribution.
10
10
11
11
*Note that this is the second version of MessagePack for JavaScript. The first version, which was implemented in ES5 and was never released to npmjs.com, is tagged as [classic](https://github.com/msgpack/msgpack-javascript/tree/classic).*
It encodes `data` into a single MessagePack-encoded object, and returns a byte array as `Uint8Array`, throwing errors if `data` is, or includes, a non-serializable object such as a `function` or a `symbol`.
85
+
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`.
86
86
87
87
for example:
88
88
@@ -124,7 +124,7 @@ It decodes `buffer` that includes a MessagePack-encoded object, and returns the
124
124
125
125
`buffer` must be an array of bytes, which is typically `Uint8Array` or `ArrayBuffer`. `BufferSource` is defined as `ArrayBuffer | ArrayBufferView`.
126
126
127
-
In addition, `buffer`can include a single encoded object. If the `buffer` includes extra bytes after an object, it will throw`RangeError`. To decode `buffer` that includes multiple encoded objects, use `decodeMulti()` or `decodeMultiStream()` (recommended) instead.
127
+
The `buffer`must include a single encoded object. If the `buffer` includes extra bytes after an object or the `buffer` is empty, it throws`RangeError`. To decode `buffer` that includes multiple encoded objects, use `decodeMulti()` or `decodeMultiStream()` (recommended) instead.
128
128
129
129
for example:
130
130
@@ -154,9 +154,9 @@ You can use `max${Type}Length` to limit the length of each type decoded.
It decodes `buffer` that includes multiple MessagePack-encoded objects, and returns decoded objects as a generator. That is, this is a synchronous variant for `decodeMultiStream()`.
157
+
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
159
-
This function is not recommended to decode a MessagePack binary via I/O stream including sockets because it's synchronous. Instead, `decodeMultiStream()` decodes it asynchronously, typically spending less time and memory.
159
+
This function is not recommended to decode a MessagePack binary via I/O stream including sockets because it's synchronous. Instead, `decodeMultiStream()` decodes a binary stream asynchronously, typically spending less CPU and memory.
160
160
161
161
for example:
162
162
@@ -172,7 +172,9 @@ 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`. This function works asynchronously. This is an async variant for `decode()`.
175
+
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
+
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.
176
178
177
179
`DecodeAsyncOptions` is the same as `DecodeOptions` for `decode()`.
178
180
@@ -231,7 +233,7 @@ This function is available since v2.4.0; previously it was called as `decodeStre
231
233
232
234
### Reusing Encoder and Decoder instances
233
235
234
-
`Encoder` and `Decoder` classes is provided for better performance:
236
+
`Encoder` and `Decoder` classes is provided to have better performance by reusing instances:
235
237
236
238
```typescript
237
239
import { deepStrictEqual } from"assert";
@@ -253,7 +255,7 @@ and data structure.
253
255
254
256
To handle [MessagePack Extension Types](https://github.com/msgpack/msgpack/blob/master/spec.md#extension-types), this library provides `ExtensionCodec` class.
255
257
256
-
Here is an example to setup custom extension types that handles `Map` and `Set` classes in TypeScript:
258
+
This is an example to setup custom extension types that handles `Map` and `Set` classes in TypeScript:
@@ -302,7 +304,7 @@ Not that extension types for custom objects must be `[0, 127]`, while `[-1, -128
302
304
303
305
#### ExtensionCodec context
304
306
305
-
When using an extension codec, it may be necessary to keep encoding/decoding state, to keep track of which objects got encoded/re-created. To do this, pass a `context` to the `EncodeOptions` and `DecodeOptions` (and if using typescript, type the `ExtensionCodec` too). Don't forget to pass the `{extensionCodec, context}` along recursive encoding/decoding:
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`:
0 commit comments