import { addExtension } from 'cbor-x'; /** ## `CBOR` [`CBOR`](https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml) : 是一种紧凑的二进制数据序列化格式,类似 `JSON`,但更高效、更适合受限环境(如物联网设备)。 + 支持自定义序列化规则 */ export declare const CBOR: { /** ### `serialize` : 将数据转化为`CBOR` @example Usage ```ts const code = CBOR.serialize('11x23') const scode = Uint8Array.from([ 101, //==>长度为5的字符串 49, //==>'1' 49, //==>'1' 120, //==>'x' 50, //==>'2' 51, //==>'3' ] ) assert.equal(code, scode) ``` */ readonly serialize: (data: unknown) => Uint8Array; /** ### `structured` : 使用结构化克隆算法,将数据转化为`CBOR` 可解决引用循环问题,但是会降低性能(约 25-30%) @example Usage ```ts const D: any = { name: 'self', aa: Some('some') } D.self = D const R = CBOR.deserialize(CBOR.structured(D)) assert.equal(R.self, R) ``` */ readonly structured: (data: unknown) => Uint8Array; /** ### `deserialize` : `CBOR`解析 @example Usage ```ts const str = '11x23' const code = CBOR.serialize(str) assert.equal(CBOR.deserialize(code), str) ``` */ readonly deserialize: (data: Uint8Array) => T; /** ### `add_extension` : 添加自定义转化规则 @example ```ts CBOR.add_extension, unknown>({ tag: CBOR_TYPECLASS.OK, Class: get_ok_class(), encode: (instance, encodeing) => encodeing(instance.value), decode: data => Ok(data), }) ``` */ readonly add_extension: typeof addExtension; /** ## `clone` : 使用`CBOR`进行深度克隆 + 默认开启结构化克隆算法 + 对于简单的数据类型,速度略快于`JSON.parse(JSON.stringify())` + 对于复杂的数据类型,速度快于`structuredClone()` @example ```ts const cbmap = new Map() cbmap.set('a', 1) cbmap.set('b', 22) const data = { name: 'sss', ms: cbmap } const data1 = CBOR.clone(data) assert(data !== data1) assert(data.ms !== data1.ms) assert(data.name === data1.name) ``` */ readonly clone: (data: T) => T; }; //# sourceMappingURL=core.d.ts.map