@cloudpss/ubjson 0.3.0-alpha.21
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/README.md +21 -0
- package/benchmark.js +34 -0
- package/coverage/tmp/coverage-10076-1636302982396-0.json +1 -0
- package/coverage/tmp/coverage-21868-1636302982372-0.json +1 -0
- package/coverage/tmp/coverage-4180-1636302982472-0.json +1 -0
- package/coverage/tmp/coverage-8980-1636302982493-0.json +1 -0
- package/dist/constants.d.ts +20 -0
- package/dist/constants.js +21 -0
- package/dist/constants.js.map +1 -0
- package/dist/decoder.d.ts +2 -0
- package/dist/decoder.js +270 -0
- package/dist/decoder.js.map +1 -0
- package/dist/encoder.d.ts +2 -0
- package/dist/encoder.js +314 -0
- package/dist/encoder.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
- package/src/constants.ts +22 -0
- package/src/decoder.ts +278 -0
- package/src/encoder.ts +340 -0
- package/src/index.ts +2 -0
- package/test/decode.js +423 -0
- package/test/e2e.js +134 -0
- package/test/encode.js +338 -0
- package/tsconfig.json +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @cloudpss/ubjson
|
|
2
|
+
|
|
3
|
+
Opinionated UBJSON encoder/decoder for CloudPSS.
|
|
4
|
+
|
|
5
|
+
Inspired by https://bitbucket.org/shelacek/ubjson, optimized for huge objects.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
### encode(value: unknown): Uint8Array
|
|
10
|
+
|
|
11
|
+
Encode object to ubjson binary data.
|
|
12
|
+
|
|
13
|
+
`Uint8Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Float32Array`, `Float64Array` is recognized and encoded as optimized object format.
|
|
14
|
+
Other type of typed arrays is not supported.
|
|
15
|
+
|
|
16
|
+
### decode(value: Uint8Array): unknown
|
|
17
|
+
|
|
18
|
+
Decode ubjson binary data.
|
|
19
|
+
|
|
20
|
+
Numeric array of optimized object format will be decoded into corresponding typed arrays.
|
|
21
|
+
Int64 (`L`) and high-precision number (`H`) are not supported.
|
package/benchmark.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import prettyBytes from 'pretty-bytes';
|
|
2
|
+
import files from '../../benchmark-files/index.js';
|
|
3
|
+
import { load, dump } from '@cloudpss/yaml';
|
|
4
|
+
import { encode, decode } from './dist/index.js';
|
|
5
|
+
|
|
6
|
+
const LOOP = 1;
|
|
7
|
+
|
|
8
|
+
const t = (time) => time.toFixed(2) + 'ms';
|
|
9
|
+
const pb = (size) => prettyBytes(size, { binary: true });
|
|
10
|
+
|
|
11
|
+
/* eslint-disable no-console */
|
|
12
|
+
(async function () {
|
|
13
|
+
const testData = [];
|
|
14
|
+
for await (const { file, data } of files()) {
|
|
15
|
+
const obj = load(data.toString());
|
|
16
|
+
testData.push({ file, data, obj });
|
|
17
|
+
}
|
|
18
|
+
for (const { file, data, obj } of testData) {
|
|
19
|
+
console.log(`File: ${file} \tRaw: ${pb(data.length)}`);
|
|
20
|
+
let encodeTime = 0;
|
|
21
|
+
let decodeTime = 0;
|
|
22
|
+
let obj2;
|
|
23
|
+
for (let i = 0; i < LOOP; i++) {
|
|
24
|
+
let start = performance.now();
|
|
25
|
+
const encoded = encode(obj);
|
|
26
|
+
encodeTime += performance.now() - start;
|
|
27
|
+
start = performance.now();
|
|
28
|
+
obj2 = decode(encoded);
|
|
29
|
+
decodeTime += performance.now() - start;
|
|
30
|
+
}
|
|
31
|
+
console.assert(dump(obj2) === dump(obj));
|
|
32
|
+
console.log(` encode: \t${t(encodeTime / LOOP)}\tdecode: \t${t(decodeTime / LOOP)}`);
|
|
33
|
+
}
|
|
34
|
+
})();
|