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
Not that extension types for custom objects must be `[0, 127]`, while `[-1, -128]` is reserved for MessagePack itself.
263
266
267
+
#### Codec context
268
+
269
+
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:
@@ -15,19 +16,24 @@ export type EncodeOptions = Partial<
15
16
*/
16
17
forceFloat32: boolean;
17
18
}>
18
-
>;
19
+
>&
20
+
ContextOf<ContextType>;
19
21
20
-
constdefaultEncodeOptions={};
22
+
constdefaultEncodeOptions: EncodeOptions={};
21
23
22
24
/**
23
25
* It encodes `value` in the MessagePack format and
24
26
* returns a byte buffer.
25
27
*
26
28
* The returned buffer is a slice of a larger `ArrayBuffer`, so you have to use its `#byteOffset` and `#byteLength` in order to convert it to another typed arrays including NodeJS `Buffer`.
0 commit comments