2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-10 02:43:44 +00:00
|
|
|
// This module is browser compatible.
|
2023-07-10 03:09:49 +00:00
|
|
|
|
2024-05-22 12:20:52 +00:00
|
|
|
/**
|
2024-06-12 03:49:23 +00:00
|
|
|
* This module provides functions to encode and decode MessagePack.
|
|
|
|
*
|
2024-05-22 12:20:52 +00:00
|
|
|
* MessagePack is an efficient binary serialization format that is language
|
|
|
|
* agnostic. It is like JSON, but generally produces much smaller payloads.
|
2024-06-12 03:49:23 +00:00
|
|
|
* {@link https://msgpack.org/ | Learn more about MessagePack}.
|
2024-05-22 12:20:52 +00:00
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* import { decode, encode } from "@std/msgpack";
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { assertEquals } from "@std/assert";
|
2024-05-22 12:20:52 +00:00
|
|
|
*
|
|
|
|
* const obj = {
|
|
|
|
* str: "deno",
|
|
|
|
* arr: [1, 2, 3],
|
|
|
|
* bool: true,
|
|
|
|
* nil: null,
|
|
|
|
* map: {
|
|
|
|
* foo: "bar"
|
|
|
|
* }
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* const encoded = encode(obj);
|
2024-06-12 03:49:23 +00:00
|
|
|
* assertEquals(encoded.length, 42);
|
2024-05-22 12:20:52 +00:00
|
|
|
*
|
|
|
|
* const decoded = decode(encoded);
|
|
|
|
* assertEquals(decoded, obj);
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* MessagePack supports encoding and decoding the following types:
|
|
|
|
*
|
|
|
|
* - `number`
|
|
|
|
* - `bigint`
|
|
|
|
* - `string`
|
|
|
|
* - `boolean`
|
|
|
|
* - `null`
|
|
|
|
* - `Uint8Array`
|
|
|
|
* - arrays of values of these types
|
|
|
|
* - objects with string or number keys, and values of these types
|
|
|
|
*
|
|
|
|
* @module
|
|
|
|
*/
|
|
|
|
|
2023-07-10 03:09:49 +00:00
|
|
|
export * from "./decode.ts";
|
|
|
|
export * from "./encode.ts";
|