microcbor 0.2.1 → 0.3.0
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 +0 -1
- package/lib/decode.d.ts +18 -0
- package/lib/decode.js +33 -15
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
package/lib/decode.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
import type { CBORValue } from "./types.js";
|
|
2
|
+
export declare class Decoder {
|
|
3
|
+
#private;
|
|
4
|
+
private readonly data;
|
|
5
|
+
constructor(data: Uint8Array);
|
|
6
|
+
getOffset(): number;
|
|
7
|
+
private constant;
|
|
8
|
+
private float16;
|
|
9
|
+
private float32;
|
|
10
|
+
private float64;
|
|
11
|
+
private uint8;
|
|
12
|
+
private uint16;
|
|
13
|
+
private uint32;
|
|
14
|
+
private uint64;
|
|
15
|
+
private decodeBytes;
|
|
16
|
+
private decodeString;
|
|
17
|
+
private getArgument;
|
|
18
|
+
decodeValue(): CBORValue;
|
|
19
|
+
}
|
|
2
20
|
export declare function decode(data: Uint8Array): CBORValue;
|
package/lib/decode.js
CHANGED
|
@@ -1,32 +1,49 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _Decoder_offset, _Decoder_view;
|
|
1
13
|
import { getFloat16 } from "fp16";
|
|
2
14
|
import { UnsafeIntegerError, maxSafeInteger, minSafeInteger } from "./utils.js";
|
|
3
|
-
class Decoder {
|
|
15
|
+
export class Decoder {
|
|
4
16
|
constructor(data) {
|
|
5
17
|
this.data = data;
|
|
18
|
+
_Decoder_offset.set(this, void 0);
|
|
19
|
+
_Decoder_view.set(this, void 0);
|
|
6
20
|
this.constant = (size, f) => () => {
|
|
7
21
|
const value = f();
|
|
8
|
-
this
|
|
22
|
+
__classPrivateFieldSet(this, _Decoder_offset, __classPrivateFieldGet(this, _Decoder_offset, "f") + size, "f");
|
|
9
23
|
return value;
|
|
10
24
|
};
|
|
11
|
-
this.float16 = this.constant(2, () => getFloat16(this
|
|
12
|
-
this.float32 = this.constant(4, () => this.
|
|
13
|
-
this.float64 = this.constant(8, () => this.
|
|
14
|
-
this.uint8 = this.constant(1, () => this.
|
|
15
|
-
this.uint16 = this.constant(2, () => this.
|
|
16
|
-
this.uint32 = this.constant(4, () => this.
|
|
17
|
-
this.uint64 = this.constant(8, () => this.
|
|
18
|
-
this
|
|
19
|
-
this
|
|
25
|
+
this.float16 = this.constant(2, () => getFloat16(__classPrivateFieldGet(this, _Decoder_view, "f"), __classPrivateFieldGet(this, _Decoder_offset, "f")));
|
|
26
|
+
this.float32 = this.constant(4, () => __classPrivateFieldGet(this, _Decoder_view, "f").getFloat32(__classPrivateFieldGet(this, _Decoder_offset, "f")));
|
|
27
|
+
this.float64 = this.constant(8, () => __classPrivateFieldGet(this, _Decoder_view, "f").getFloat64(__classPrivateFieldGet(this, _Decoder_offset, "f")));
|
|
28
|
+
this.uint8 = this.constant(1, () => __classPrivateFieldGet(this, _Decoder_view, "f").getUint8(__classPrivateFieldGet(this, _Decoder_offset, "f")));
|
|
29
|
+
this.uint16 = this.constant(2, () => __classPrivateFieldGet(this, _Decoder_view, "f").getUint16(__classPrivateFieldGet(this, _Decoder_offset, "f")));
|
|
30
|
+
this.uint32 = this.constant(4, () => __classPrivateFieldGet(this, _Decoder_view, "f").getUint32(__classPrivateFieldGet(this, _Decoder_offset, "f")));
|
|
31
|
+
this.uint64 = this.constant(8, () => __classPrivateFieldGet(this, _Decoder_view, "f").getBigUint64(__classPrivateFieldGet(this, _Decoder_offset, "f")));
|
|
32
|
+
__classPrivateFieldSet(this, _Decoder_offset, 0, "f");
|
|
33
|
+
__classPrivateFieldSet(this, _Decoder_view, new DataView(data.buffer, data.byteOffset, data.byteLength), "f");
|
|
34
|
+
}
|
|
35
|
+
getOffset() {
|
|
36
|
+
return __classPrivateFieldGet(this, _Decoder_offset, "f");
|
|
20
37
|
}
|
|
21
38
|
decodeBytes(length) {
|
|
22
39
|
const value = new Uint8Array(length);
|
|
23
|
-
value.set(this.data.subarray(this
|
|
24
|
-
this
|
|
40
|
+
value.set(this.data.subarray(__classPrivateFieldGet(this, _Decoder_offset, "f"), __classPrivateFieldGet(this, _Decoder_offset, "f") + length), 0);
|
|
41
|
+
__classPrivateFieldSet(this, _Decoder_offset, __classPrivateFieldGet(this, _Decoder_offset, "f") + length, "f");
|
|
25
42
|
return value;
|
|
26
43
|
}
|
|
27
44
|
decodeString(length) {
|
|
28
|
-
const value = new TextDecoder().decode(this.data.subarray(this
|
|
29
|
-
this
|
|
45
|
+
const value = new TextDecoder().decode(this.data.subarray(__classPrivateFieldGet(this, _Decoder_offset, "f"), __classPrivateFieldGet(this, _Decoder_offset, "f") + length));
|
|
46
|
+
__classPrivateFieldSet(this, _Decoder_offset, __classPrivateFieldGet(this, _Decoder_offset, "f") + length, "f");
|
|
30
47
|
return value;
|
|
31
48
|
}
|
|
32
49
|
getArgument(additionalInformation) {
|
|
@@ -136,6 +153,7 @@ class Decoder {
|
|
|
136
153
|
}
|
|
137
154
|
}
|
|
138
155
|
}
|
|
156
|
+
_Decoder_offset = new WeakMap(), _Decoder_view = new WeakMap();
|
|
139
157
|
export function decode(data) {
|
|
140
158
|
return new Decoder(data).decodeValue();
|
|
141
159
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { CBORValue, CBORMap, CBORArray } from "./types.js";
|
|
2
2
|
export { encode, Encoder } from "./encode.js";
|
|
3
|
-
export { decode } from "./decode.js";
|
|
3
|
+
export { decode, Decoder } from "./decode.js";
|
|
4
4
|
export { encodeStream } from "./encodeStream.js";
|
|
5
5
|
export { decodeStream } from "./decodeStream.js";
|
|
6
6
|
export { encodingLength } from "./encodingLength.js";
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { encode, Encoder } from "./encode.js";
|
|
2
|
-
export { decode } from "./decode.js";
|
|
2
|
+
export { decode, Decoder } from "./decode.js";
|
|
3
3
|
export { encodeStream } from "./encodeStream.js";
|
|
4
4
|
export { decodeStream } from "./decodeStream.js";
|
|
5
5
|
export { encodingLength } from "./encodingLength.js";
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type CBORValue = undefined | null | boolean | number | string | Uint8Array | CBORArray | CBORMap;
|
|
2
2
|
export interface CBORArray extends Array<CBORValue> {
|
|
3
3
|
}
|
|
4
4
|
export interface CBORMap {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "microcbor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Encode JavaScript values as canonical CBOR",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/joeltg/microcbor#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"ava": "^
|
|
31
|
-
"cbor": "^8.0
|
|
32
|
-
"typescript": "^
|
|
30
|
+
"ava": "^5.3.1",
|
|
31
|
+
"cbor": "^8.1.0",
|
|
32
|
+
"typescript": "^5.1.6"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"fp16": "^0.2.0"
|