forked from msgpack/msgpack-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.ts
More file actions
17 lines (16 loc) · 660 Bytes
/
Copy pathencode.ts
File metadata and controls
17 lines (16 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Encoder } from "./Encoder.ts";
import type { EncoderOptions } from "./Encoder.ts";
import type { SplitUndefined } from "./context.ts";
/**
* It encodes `value` in the MessagePack format and
* returns a byte buffer.
*
* 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`.
*/
export function encode<ContextType = undefined>(
value: unknown,
options?: EncoderOptions<SplitUndefined<ContextType>>,
): Uint8Array<ArrayBuffer> {
const encoder = new Encoder(options);
return encoder.encodeSharedRef(value);
}