cborg 4.4.1 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +21 -0
- package/bench/README.md +115 -0
- package/bench/bench-comparative.js +133 -0
- package/bench/bench.js +414 -101
- package/bench/fixtures.js +558 -0
- package/bench/index.html +405 -0
- package/cborg.js +2 -1
- package/interface.ts +8 -2
- package/lib/0uint.js +11 -11
- package/lib/1negint.js +4 -4
- package/lib/2bytes.js +5 -5
- package/lib/3string.js +1 -1
- package/lib/4array.js +4 -4
- package/lib/5map.js +4 -4
- package/lib/6tag.js +4 -4
- package/lib/7float.js +10 -10
- package/lib/bl.js +46 -0
- package/lib/encode.js +40 -15
- package/lib/is.js +12 -31
- package/lib/json/encode.js +10 -10
- package/package.json +1 -1
- package/test/test-0uint.js +12 -1
- package/test/test-1negint.js +12 -1
- package/test/test-2bytes.js +11 -1
- package/test/test-3string.js +11 -1
- package/test/test-4array.js +11 -1
- package/test/test-5map.js +11 -3
- package/test/test-6tag.js +19 -1
- package/test/test-7float.js +11 -1
- package/test/test-cbor-vectors.js +13 -2
- package/test/test-encodeInto.js +246 -0
- package/types/cborg.d.ts +2 -1
- package/types/cborg.d.ts.map +1 -1
- package/types/interface.d.ts +7 -2
- package/types/interface.d.ts.map +1 -1
- package/types/lib/0uint.d.ts +6 -6
- package/types/lib/0uint.d.ts.map +1 -1
- package/types/lib/1negint.d.ts +4 -4
- package/types/lib/1negint.d.ts.map +1 -1
- package/types/lib/2bytes.d.ts +3 -3
- package/types/lib/2bytes.d.ts.map +1 -1
- package/types/lib/3string.d.ts +1 -1
- package/types/lib/3string.d.ts.map +1 -1
- package/types/lib/4array.d.ts +3 -3
- package/types/lib/4array.d.ts.map +1 -1
- package/types/lib/5map.d.ts +3 -3
- package/types/lib/5map.d.ts.map +1 -1
- package/types/lib/6tag.d.ts +4 -4
- package/types/lib/6tag.d.ts.map +1 -1
- package/types/lib/7float.d.ts +3 -3
- package/types/lib/7float.d.ts.map +1 -1
- package/types/lib/bl.d.ts +25 -0
- package/types/lib/bl.d.ts.map +1 -1
- package/types/lib/encode.d.ts +12 -1
- package/types/lib/encode.d.ts.map +1 -1
- package/types/lib/is.d.ts.map +1 -1
- package/types/lib/json/encode.d.ts +1 -1
- package/types/lib/json/encode.d.ts.map +1 -1
package/types/lib/7float.d.ts
CHANGED
|
@@ -39,11 +39,11 @@ export function decodeFloat32(data: Uint8Array, pos: number, _minor: number, opt
|
|
|
39
39
|
*/
|
|
40
40
|
export function decodeFloat64(data: Uint8Array, pos: number, _minor: number, options: DecodeOptions): Token;
|
|
41
41
|
/**
|
|
42
|
-
* @param {
|
|
42
|
+
* @param {ByteWriter} writer
|
|
43
43
|
* @param {Token} token
|
|
44
44
|
* @param {EncodeOptions} options
|
|
45
45
|
*/
|
|
46
|
-
export function encodeFloat(
|
|
46
|
+
export function encodeFloat(writer: ByteWriter, token: Token, options: EncodeOptions): void;
|
|
47
47
|
export namespace encodeFloat {
|
|
48
48
|
/**
|
|
49
49
|
* @param {Token} token
|
|
@@ -53,7 +53,7 @@ export namespace encodeFloat {
|
|
|
53
53
|
function encodedSize(token: Token, options: EncodeOptions): number;
|
|
54
54
|
let compareTokens: (tok1: Token, tok2: Token) => number;
|
|
55
55
|
}
|
|
56
|
-
export type
|
|
56
|
+
export type ByteWriter = import("../interface").ByteWriter;
|
|
57
57
|
export type DecodeOptions = import("../interface").DecodeOptions;
|
|
58
58
|
export type EncodeOptions = import("../interface").EncodeOptions;
|
|
59
59
|
import { Token } from './token.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"7float.d.ts","sourceRoot":"","sources":["../../lib/7float.js"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,uCANW,UAAU,QACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CASjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,QACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAOjB;AAoBD;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"7float.d.ts","sourceRoot":"","sources":["../../lib/7float.js"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,uCANW,UAAU,QACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CASjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,QACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAOjB;AAoBD;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;GAIG;AACH,oCAJW,UAAU,SACV,KAAK,WACL,aAAa,QAwCvB;;IAED;;;;OAIG;IACH,4BAJW,KAAK,WACL,aAAa,GACX,MAAM,CAsBlB;;;yBAjKY,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;4BACpC,OAAO,cAAc,EAAE,aAAa;sBAPrB,YAAY"}
|
package/types/lib/bl.d.ts
CHANGED
|
@@ -23,4 +23,29 @@ export class Bl {
|
|
|
23
23
|
*/
|
|
24
24
|
toBytes(reset?: boolean): Uint8Array;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* U8Bl is a buffer list that writes directly to a user-provided Uint8Array.
|
|
28
|
+
* It provides the same interface as Bl but writes to a fixed destination.
|
|
29
|
+
*/
|
|
30
|
+
export class U8Bl {
|
|
31
|
+
/**
|
|
32
|
+
* @param {Uint8Array} dest
|
|
33
|
+
*/
|
|
34
|
+
constructor(dest: Uint8Array);
|
|
35
|
+
dest: Uint8Array<ArrayBufferLike>;
|
|
36
|
+
/** @type {number} */
|
|
37
|
+
cursor: number;
|
|
38
|
+
/** @type {Uint8Array[]} */
|
|
39
|
+
chunks: Uint8Array[];
|
|
40
|
+
reset(): void;
|
|
41
|
+
/**
|
|
42
|
+
* @param {Uint8Array|number[]} bytes
|
|
43
|
+
*/
|
|
44
|
+
push(bytes: Uint8Array | number[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* @param {boolean} [reset]
|
|
47
|
+
* @returns {Uint8Array}
|
|
48
|
+
*/
|
|
49
|
+
toBytes(reset?: boolean): Uint8Array;
|
|
50
|
+
}
|
|
26
51
|
//# sourceMappingURL=bl.d.ts.map
|
package/types/lib/bl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bl.d.ts","sourceRoot":"","sources":["../../lib/bl.js"],"names":[],"mappings":"AA0BA;IACE;;OAEG;IACH,wBAFW,MAAM,EAahB;IAVC,kBAA0B;IAC1B,qBAAqB;IACrB,QADW,MAAM,CACF;IACf,qBAAqB;IACrB,WADW,MAAM,CACE;IACnB,sCAAsC;IACtC,QADW,CAAC,UAAU,GAAC,MAAM,EAAE,CAAC,EAAE,CAClB;IAEhB,uCAAuC;IACvC,iBADW,UAAU,GAAC,MAAM,EAAE,GAAC,IAAI,CACR;IAG7B,cAUC;IAED;;OAEG;IACH,YAFW,UAAU,GAAC,MAAM,EAAE,QAsC7B;IAED;;;OAGG;IACH,gBAHW,OAAO,GACL,UAAU,CAwBtB;CACF"}
|
|
1
|
+
{"version":3,"file":"bl.d.ts","sourceRoot":"","sources":["../../lib/bl.js"],"names":[],"mappings":"AA0BA;IACE;;OAEG;IACH,wBAFW,MAAM,EAahB;IAVC,kBAA0B;IAC1B,qBAAqB;IACrB,QADW,MAAM,CACF;IACf,qBAAqB;IACrB,WADW,MAAM,CACE;IACnB,sCAAsC;IACtC,QADW,CAAC,UAAU,GAAC,MAAM,EAAE,CAAC,EAAE,CAClB;IAEhB,uCAAuC;IACvC,iBADW,UAAU,GAAC,MAAM,EAAE,GAAC,IAAI,CACR;IAG7B,cAUC;IAED;;OAEG;IACH,YAFW,UAAU,GAAC,MAAM,EAAE,QAsC7B;IAED;;;OAGG;IACH,gBAHW,OAAO,GACL,UAAU,CAwBtB;CACF;AAED;;;GAGG;AACH;IACE;;OAEG;IACH,kBAFW,UAAU,EAUpB;IAPC,kCAAgB;IAChB,qBAAqB;IACrB,QADW,MAAM,CACF;IAGf,2BAA2B;IAC3B,QADW,UAAU,EAAE,CACH;IAGtB,cAEC;IAED;;OAEG;IACH,YAFW,UAAU,GAAC,MAAM,EAAE,QAQ7B;IAED;;;OAGG;IACH,gBAHW,OAAO,GACL,UAAU,CAQtB;CACF"}
|
package/types/lib/encode.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type Reference = import("../interface").Reference;
|
|
|
11
11
|
export type StrictTypeEncoder = import("../interface").StrictTypeEncoder;
|
|
12
12
|
export type TokenTypeEncoder = import("../interface").TokenTypeEncoder;
|
|
13
13
|
export type TokenOrNestedTokens = import("../interface").TokenOrNestedTokens;
|
|
14
|
+
export type ByteWriter = import("../interface").ByteWriter;
|
|
14
15
|
/**
|
|
15
16
|
* @param {any} obj
|
|
16
17
|
* @param {EncodeOptions} [options]
|
|
@@ -28,9 +29,19 @@ export function encode(data: any, options?: EncodeOptions): Uint8Array;
|
|
|
28
29
|
* @param {any} data
|
|
29
30
|
* @param {TokenTypeEncoder[]} encoders
|
|
30
31
|
* @param {EncodeOptions} options
|
|
32
|
+
* @param {Uint8Array} [destination]
|
|
31
33
|
* @returns {Uint8Array}
|
|
32
34
|
*/
|
|
33
|
-
export function encodeCustom(data: any, encoders: TokenTypeEncoder[], options: EncodeOptions): Uint8Array;
|
|
35
|
+
export function encodeCustom(data: any, encoders: TokenTypeEncoder[], options: EncodeOptions, destination?: Uint8Array): Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* @param {any} data
|
|
38
|
+
* @param {Uint8Array} destination
|
|
39
|
+
* @param {EncodeOptions} [options]
|
|
40
|
+
* @returns {{ written: number }}
|
|
41
|
+
*/
|
|
42
|
+
export function encodeInto(data: any, destination: Uint8Array, options?: EncodeOptions): {
|
|
43
|
+
written: number;
|
|
44
|
+
};
|
|
34
45
|
/** @implements {Reference} */
|
|
35
46
|
export class Ref implements Reference {
|
|
36
47
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../lib/encode.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../lib/encode.js"],"names":[],"mappings":"AAwCA,oCAAoC;AACpC,oCADc,gBAAgB,EAAE,CAY/B;AAnBD,4BAA4B;AAC5B,mCADW,aAAa,CAKtB;sBA+XW,KAAK,GAAG;IAAE,SAAS,CAAC,EAAE,UAAU,CAAA;CAAE;4BApZlC,OAAO,cAAc,EAAE,aAAa;kCACpC,OAAO,cAAc,EAAE,mBAAmB;wBAC1C,OAAO,cAAc,EAAE,SAAS;gCAChC,OAAO,cAAc,EAAE,iBAAiB;+BACxC,OAAO,cAAc,EAAE,gBAAgB;kCACvC,OAAO,cAAc,EAAE,mBAAmB;yBAC1C,OAAO,cAAc,EAAE,UAAU;AA0R9C;;;;;GAKG;AACH,oCALW,GAAG,YACH,aAAa,aACb,SAAS,GACP,mBAAmB,CAgB/B;AA4LD;;;;GAIG;AACH,6BAJW,GAAG,YACH,aAAa,GACX,UAAU,CAKtB;AAnDD;;;;;;GAMG;AACH,mCANW,GAAG,YACH,gBAAgB,EAAE,WAClB,aAAa,gBACb,UAAU,GACR,UAAU,CAoCtB;AAYD;;;;;GAKG;AACH,iCALW,GAAG,eACH,UAAU,YACV,aAAa,GACX;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAM/B;AA3dD,8BAA8B;AAC9B,4BADiB,SAAS;IA0BxB;;;;OAIG;IACH,0BAJW,SAAS,GAAC,SAAS,OACnB,MAAM,GAAC,GAAG,EAAE,GACV,SAAS,CAOrB;IAlCD;;;OAGG;IACH,iBAHW,MAAM,GAAC,GAAG,EAAE,UACZ,SAAS,GAAC,SAAS,EAK7B;IAFC,oBAAc;IACd,qDAAoB;IAGtB;;;OAGG;IACH,cAHW,MAAM,GAAC,GAAG,EAAE,GACV,OAAO,CAWnB;CAaF;sBA9F2B,YAAY"}
|
package/types/lib/is.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../lib/is.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../lib/is.js"],"names":[],"mappings":"AAkCA;;;GAGG;AACH,0BAHW,GAAG,GACD,MAAM,CAqClB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type EncodeOptions = import("../../interface").EncodeOptions;
|
|
2
|
+
export type ByteWriter = import("../../interface").ByteWriter;
|
|
2
3
|
export type Token = import("../token").Token;
|
|
3
|
-
export type Bl = import("../bl").Bl;
|
|
4
4
|
/**
|
|
5
5
|
* @param {any} data
|
|
6
6
|
* @param {EncodeOptions} [options]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../lib/json/encode.js"],"names":[],"mappings":"4BAMa,OAAO,iBAAiB,EAAE,aAAa;
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../lib/json/encode.js"],"names":[],"mappings":"4BAMa,OAAO,iBAAiB,EAAE,aAAa;yBACvC,OAAO,iBAAiB,EAAE,UAAU;oBACpC,OAAO,UAAU,EAAE,KAAK;AAoSrC;;;;GAIG;AACH,6BAJW,GAAG,YACH,aAAa,GACX,UAAU,CAMtB"}
|