@bitspark/ontos-codec 0.13.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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/src/index.d.ts +50 -0
- package/dist/src/index.js +271 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type BytesLike, type Value } from "@bitspark/ontos-core";
|
|
2
|
+
export interface DecodeOptions {
|
|
3
|
+
readonly maxDepth?: number;
|
|
4
|
+
readonly maxAtomBytes?: number;
|
|
5
|
+
readonly maxTupleArity?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Rejection categories (ontos-codec.md §4). The five byte-contract codes
|
|
9
|
+
* (`unexpected_eof`, `trailing_bytes`, `unknown_tag`, `non_canonical_uvarint`,
|
|
10
|
+
* `uvarint_overflow`) are normative and pinned by vectors/codec.json.
|
|
11
|
+
* `limit_exceeded` is not: it reports that decoding stopped at an operational
|
|
12
|
+
* bound, says nothing about whether the input is a valid encoding, and carries a
|
|
13
|
+
* `limitKind` naming the bound (§4.2).
|
|
14
|
+
*/
|
|
15
|
+
export type DecodeErrorCode = "unexpected_eof" | "trailing_bytes" | "unknown_tag" | "non_canonical_uvarint" | "uvarint_overflow" | "limit_exceeded";
|
|
16
|
+
/**
|
|
17
|
+
* The operational bounds a `limit_exceeded` can name (ontos-codec.md §4.2). The
|
|
18
|
+
* vocabulary is append-only: a name never changes meaning, but a later version may
|
|
19
|
+
* add names, which is why {@link DecodeLimitKind} the type is open.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DecodeLimitKind: {
|
|
22
|
+
/** The value about to be read is nested deeper than `maxDepth` (the root is depth 0). */
|
|
23
|
+
readonly DecodeDepth: "decode_depth";
|
|
24
|
+
/** A declared atom byte length exceeds `maxAtomBytes`. */
|
|
25
|
+
readonly AtomBytes: "atom_bytes";
|
|
26
|
+
/** A declared tuple arity exceeds `maxTupleArity`. */
|
|
27
|
+
readonly TupleArity: "tuple_arity";
|
|
28
|
+
/** A valid uvarint length or arity exceeds `Number.MAX_SAFE_INTEGER` (2^53 - 1). */
|
|
29
|
+
readonly NativeWidth: "native_width";
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A limit kind. Open on purpose: treat a string outside {@link DecodeLimitKind} as
|
|
33
|
+
* the generic `limit_exceeded`, never as malformed input.
|
|
34
|
+
*/
|
|
35
|
+
export type DecodeLimitKind = (typeof DecodeLimitKind)[keyof typeof DecodeLimitKind] | (string & {});
|
|
36
|
+
export declare class DecodeError extends Error {
|
|
37
|
+
readonly code: DecodeErrorCode;
|
|
38
|
+
/**
|
|
39
|
+
* The bound that stopped decoding, present only when `code` is
|
|
40
|
+
* `limit_exceeded` (a non-limit error has no `limitKind` property at all). It is
|
|
41
|
+
* observational: it names the check that stopped this decode, and another
|
|
42
|
+
* implementation may name a different bound for the same input (§4.2). An absent
|
|
43
|
+
* or unrecognized kind carries no more than the generic `limit_exceeded`.
|
|
44
|
+
*/
|
|
45
|
+
readonly limitKind?: DecodeLimitKind;
|
|
46
|
+
constructor(code: DecodeErrorCode, message: string, limitKind?: DecodeLimitKind);
|
|
47
|
+
}
|
|
48
|
+
export declare function encode(value: Value): Uint8Array;
|
|
49
|
+
export declare function decode(input: BytesLike, options?: DecodeOptions): Value;
|
|
50
|
+
export declare function encodeUvarint(n: number): Uint8Array;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ontos canonical binary codec — ontos-codec-v1 (frozen).
|
|
3
|
+
*
|
|
4
|
+
* Atom(bytes) = 0x00 || uvarint(len(bytes)) || bytes
|
|
5
|
+
* Tuple(values) = 0x01 || uvarint(arity) || encode(each child)
|
|
6
|
+
*
|
|
7
|
+
* uvarint is unsigned LEB128 in shortest/canonical form over the u64 domain
|
|
8
|
+
* [0, 2^64 - 1] (ontos-codec.md §3.1 / §4). The decoder rejects unknown tags,
|
|
9
|
+
* trailing bytes, non-canonical uvarints, uvarints outside the u64 domain
|
|
10
|
+
* (uvarint_overflow), and inputs exceeding the configured/native limits
|
|
11
|
+
* (limit_exceeded, whose DecodeError.limitKind names the bound; §4.2).
|
|
12
|
+
*
|
|
13
|
+
* This codec is kept beside the model (it depends on ontos-core, never the
|
|
14
|
+
* reverse). The byte mapping is frozen (any change ships as a new version).
|
|
15
|
+
* Conformance is pinned by vectors/codec.json (codec: ontos-codec-v1).
|
|
16
|
+
*
|
|
17
|
+
* This imports the model from "@bitspark/ontos-core". In the monorepo that name
|
|
18
|
+
* resolves to core/ts via npm workspaces, so the source and the published build
|
|
19
|
+
* carry the identical import (see docs/design/0006-distribution.md).
|
|
20
|
+
*/
|
|
21
|
+
import { Atom, atom, tuple, copyBytes, bytesEqual } from "@bitspark/ontos-core";
|
|
22
|
+
const TAG_ATOM = 0x00;
|
|
23
|
+
const TAG_TUPLE = 0x01;
|
|
24
|
+
const DEFAULT_MAX_DEPTH = 1024;
|
|
25
|
+
// uvarint integer domain (spec: ontos-codec.md §3.1 / §4): unsigned values in
|
|
26
|
+
// [0, 2^64 - 1]. A canonical uvarint is shortest-form and at most 10 bytes.
|
|
27
|
+
const MAX_UVARINT_BYTES = 10;
|
|
28
|
+
const UVARINT_CEILING = 1n << 64n; // 2^64: exclusive upper bound of the u64 domain.
|
|
29
|
+
// A valid u64 above this cannot be materialized as a JS number without precision
|
|
30
|
+
// loss, so it is rejected as limit_exceeded (a resource-limit class).
|
|
31
|
+
const MAX_SAFE_INTEGER_BIG = BigInt(Number.MAX_SAFE_INTEGER);
|
|
32
|
+
/**
|
|
33
|
+
* The operational bounds a `limit_exceeded` can name (ontos-codec.md §4.2). The
|
|
34
|
+
* vocabulary is append-only: a name never changes meaning, but a later version may
|
|
35
|
+
* add names, which is why {@link DecodeLimitKind} the type is open.
|
|
36
|
+
*/
|
|
37
|
+
export const DecodeLimitKind = {
|
|
38
|
+
/** The value about to be read is nested deeper than `maxDepth` (the root is depth 0). */
|
|
39
|
+
DecodeDepth: "decode_depth",
|
|
40
|
+
/** A declared atom byte length exceeds `maxAtomBytes`. */
|
|
41
|
+
AtomBytes: "atom_bytes",
|
|
42
|
+
/** A declared tuple arity exceeds `maxTupleArity`. */
|
|
43
|
+
TupleArity: "tuple_arity",
|
|
44
|
+
/** A valid uvarint length or arity exceeds `Number.MAX_SAFE_INTEGER` (2^53 - 1). */
|
|
45
|
+
NativeWidth: "native_width",
|
|
46
|
+
};
|
|
47
|
+
export class DecodeError extends Error {
|
|
48
|
+
code;
|
|
49
|
+
constructor(code, message, limitKind) {
|
|
50
|
+
super(message);
|
|
51
|
+
this.name = "DecodeError";
|
|
52
|
+
this.code = code;
|
|
53
|
+
if (limitKind !== undefined)
|
|
54
|
+
this.limitKind = limitKind;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function encode(value) {
|
|
58
|
+
// Two passes over an explicit stack (ontos-internal#343), so depth is never a JS-stack property, and one
|
|
59
|
+
// output buffer (ontos-internal#362), so nothing is allocated per value except Atom#bytes()'s defensive
|
|
60
|
+
// copy. Pass 1 visits the values in pre-order, which is the order they are written, records
|
|
61
|
+
// them, and sums the exact output size from the lengths alone. Pass 2 writes them in that
|
|
62
|
+
// order. The bytes are the ones the per-piece encoder produced, value for value.
|
|
63
|
+
const order = [];
|
|
64
|
+
const stack = [value];
|
|
65
|
+
let size = 0;
|
|
66
|
+
while (stack.length > 0) {
|
|
67
|
+
const v = stack.pop();
|
|
68
|
+
order.push(v);
|
|
69
|
+
if (v instanceof Atom) {
|
|
70
|
+
const n = v.length;
|
|
71
|
+
size += 1 + uvarintLength(n) + n;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const items = v.items();
|
|
75
|
+
size += 1 + uvarintLength(items.length);
|
|
76
|
+
for (let i = items.length - 1; i >= 0; i -= 1)
|
|
77
|
+
stack.push(items[i]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const out = new Uint8Array(size);
|
|
81
|
+
let at = 0;
|
|
82
|
+
for (const v of order) {
|
|
83
|
+
if (v instanceof Atom) {
|
|
84
|
+
const b = v.bytes();
|
|
85
|
+
out[at++] = TAG_ATOM;
|
|
86
|
+
at = writeUvarint(out, at, b.length);
|
|
87
|
+
out.set(b, at);
|
|
88
|
+
at += b.length;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
out[at++] = TAG_TUPLE;
|
|
92
|
+
at = writeUvarint(out, at, v.length);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
// The shortest-form uvarint of a safe integer, in plain arithmetic: no BigInt (ontos-internal#362). Every
|
|
98
|
+
// length and arity this encoder writes is a safe integer, so this covers all of them. Division
|
|
99
|
+
// and remainder by 128 are exact for safe integers, which bitwise operators (32-bit) are not.
|
|
100
|
+
function uvarintLength(n) {
|
|
101
|
+
let len = 1;
|
|
102
|
+
while (n >= 0x80) {
|
|
103
|
+
n = Math.floor(n / 0x80);
|
|
104
|
+
len += 1;
|
|
105
|
+
}
|
|
106
|
+
return len;
|
|
107
|
+
}
|
|
108
|
+
function writeUvarint(out, at, n) {
|
|
109
|
+
while (n >= 0x80) {
|
|
110
|
+
out[at++] = (n % 0x80) | 0x80;
|
|
111
|
+
n = Math.floor(n / 0x80);
|
|
112
|
+
}
|
|
113
|
+
out[at++] = n;
|
|
114
|
+
return at;
|
|
115
|
+
}
|
|
116
|
+
export function decode(input, options = {}) {
|
|
117
|
+
const bytes = copyBytes(input);
|
|
118
|
+
const state = { pos: 0 };
|
|
119
|
+
const limits = normalizeDecodeOptions(options);
|
|
120
|
+
const value = readValue(bytes, state, 0, limits);
|
|
121
|
+
if (state.pos !== bytes.length) {
|
|
122
|
+
throw new DecodeError("trailing_bytes", `trailing bytes at offset ${state.pos}`);
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
export function encodeUvarint(n) {
|
|
127
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
128
|
+
throw new RangeError(`uvarint requires a non-negative safe integer, got ${n}`);
|
|
129
|
+
}
|
|
130
|
+
const out = new Uint8Array(uvarintLength(n));
|
|
131
|
+
writeUvarint(out, 0, n);
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
// Shortest-form LEB128 encoding of a bigint in the u64 domain. Shared by the
|
|
135
|
+
// public encoder and the decoder's canonicality check so both agree byte-for-byte.
|
|
136
|
+
function encodeUvarintBig(value) {
|
|
137
|
+
if (value < 0n || value >= UVARINT_CEILING) {
|
|
138
|
+
throw new RangeError(`uvarint requires a value in [0, 2^64 - 1], got ${value}`);
|
|
139
|
+
}
|
|
140
|
+
let v = value;
|
|
141
|
+
const out = [];
|
|
142
|
+
do {
|
|
143
|
+
let byte = Number(v & 0x7fn);
|
|
144
|
+
v >>= 7n;
|
|
145
|
+
if (v !== 0n)
|
|
146
|
+
byte |= 0x80;
|
|
147
|
+
out.push(byte);
|
|
148
|
+
} while (v !== 0n);
|
|
149
|
+
return Uint8Array.from(out);
|
|
150
|
+
}
|
|
151
|
+
// With an explicit stack of open tuples (ontos-internal#343), never one call per level. Each value's header is
|
|
152
|
+
// read and checked in the recursive walk's order (depth, then tag, then length or arity, with the
|
|
153
|
+
// same errors at the same offsets), and a completed value is handed to its parent, closing every
|
|
154
|
+
// tuple it fills.
|
|
155
|
+
function readValue(bytes, state, depth, limits) {
|
|
156
|
+
const open = [];
|
|
157
|
+
for (;;) {
|
|
158
|
+
const level = depth + open.length;
|
|
159
|
+
if (level > limits.maxDepth) {
|
|
160
|
+
throw new DecodeError("limit_exceeded", `maximum decode depth exceeded: ${limits.maxDepth}`, DecodeLimitKind.DecodeDepth);
|
|
161
|
+
}
|
|
162
|
+
if (state.pos >= bytes.length) {
|
|
163
|
+
throw new DecodeError("unexpected_eof", "unexpected end of input while reading tag");
|
|
164
|
+
}
|
|
165
|
+
const offset = state.pos;
|
|
166
|
+
const tag = bytes[state.pos];
|
|
167
|
+
state.pos += 1;
|
|
168
|
+
let done;
|
|
169
|
+
if (tag === TAG_ATOM) {
|
|
170
|
+
const length = readUvarint(bytes, state);
|
|
171
|
+
if (length > limits.maxAtomBytes) {
|
|
172
|
+
throw new DecodeError("limit_exceeded", `atom byte length ${length} exceeds limit ${limits.maxAtomBytes}`, DecodeLimitKind.AtomBytes);
|
|
173
|
+
}
|
|
174
|
+
if (state.pos + length > bytes.length) {
|
|
175
|
+
throw new DecodeError("unexpected_eof", "unexpected end of input while reading atom bytes");
|
|
176
|
+
}
|
|
177
|
+
const start = state.pos;
|
|
178
|
+
state.pos += length;
|
|
179
|
+
done = atom(bytes.subarray(start, state.pos));
|
|
180
|
+
}
|
|
181
|
+
else if (tag === TAG_TUPLE) {
|
|
182
|
+
const arity = readUvarint(bytes, state);
|
|
183
|
+
if (arity > limits.maxTupleArity) {
|
|
184
|
+
throw new DecodeError("limit_exceeded", `tuple arity ${arity} exceeds limit ${limits.maxTupleArity}`, DecodeLimitKind.TupleArity);
|
|
185
|
+
}
|
|
186
|
+
// Every encoded value is at least two bytes (tag + zero uvarint), so an arity
|
|
187
|
+
// larger than half the remaining bytes is impossible. Guards malformed input.
|
|
188
|
+
const maxPossibleChildren = Math.floor((bytes.length - state.pos) / 2);
|
|
189
|
+
if (arity > maxPossibleChildren) {
|
|
190
|
+
throw new DecodeError("unexpected_eof", "unexpected end of input while reading tuple items");
|
|
191
|
+
}
|
|
192
|
+
if (arity > 0) {
|
|
193
|
+
open.push({ items: [], arity });
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
done = tuple([]);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
throw new DecodeError("unknown_tag", `unknown value tag 0x${(tag ?? 0).toString(16).padStart(2, "0")} at offset ${offset}`);
|
|
200
|
+
}
|
|
201
|
+
for (;;) {
|
|
202
|
+
const top = open[open.length - 1];
|
|
203
|
+
if (top === undefined)
|
|
204
|
+
return done;
|
|
205
|
+
top.items.push(done);
|
|
206
|
+
if (top.items.length < top.arity)
|
|
207
|
+
break;
|
|
208
|
+
open.pop();
|
|
209
|
+
done = tuple(top.items);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function readUvarint(bytes, state) {
|
|
214
|
+
const start = state.pos;
|
|
215
|
+
// Accumulate in bigint so the full u64 domain [0, 2^64 - 1] is representable
|
|
216
|
+
// during decode without precision loss (spec: ontos-codec.md §3.1 / §4).
|
|
217
|
+
let result = 0n;
|
|
218
|
+
let shift = 0n;
|
|
219
|
+
let length = 0;
|
|
220
|
+
while (true) {
|
|
221
|
+
if (state.pos >= bytes.length) {
|
|
222
|
+
throw new DecodeError("unexpected_eof", "unexpected end of input while reading uvarint");
|
|
223
|
+
}
|
|
224
|
+
const byte = bytes[state.pos] ?? 0;
|
|
225
|
+
state.pos += 1;
|
|
226
|
+
length += 1;
|
|
227
|
+
result |= BigInt(byte & 0x7f) << shift;
|
|
228
|
+
// Any decoded value at or above 2^64 is outside the u64 domain. This catches
|
|
229
|
+
// a 10th byte whose high bits push the value past the 64-bit ceiling.
|
|
230
|
+
if (result >= UVARINT_CEILING) {
|
|
231
|
+
throw new DecodeError("uvarint_overflow", `uvarint exceeds the u64 domain at offset ${start}`);
|
|
232
|
+
}
|
|
233
|
+
if ((byte & 0x80) === 0)
|
|
234
|
+
break;
|
|
235
|
+
shift += 7n;
|
|
236
|
+
// A canonical uvarint is at most 10 bytes; an 11th continuation byte can only
|
|
237
|
+
// encode a value >= 2^64, so it is a u64-domain overflow.
|
|
238
|
+
if (length >= MAX_UVARINT_BYTES) {
|
|
239
|
+
throw new DecodeError("uvarint_overflow", `uvarint exceeds 10 bytes at offset ${start}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const canonical = encodeUvarintBig(result);
|
|
243
|
+
const actual = bytes.subarray(start, state.pos);
|
|
244
|
+
if (!bytesEqual(canonical, actual)) {
|
|
245
|
+
throw new DecodeError("non_canonical_uvarint", `non-canonical uvarint at offset ${start}`);
|
|
246
|
+
}
|
|
247
|
+
// result is a valid u64. If it exceeds this implementation's native
|
|
248
|
+
// materialization width (Number.MAX_SAFE_INTEGER) it is a RESOURCE-LIMIT
|
|
249
|
+
// failure (limit_exceeded), NOT an overflow of the u64 domain.
|
|
250
|
+
if (result > MAX_SAFE_INTEGER_BIG) {
|
|
251
|
+
throw new DecodeError("limit_exceeded", `uvarint ${result} exceeds Number.MAX_SAFE_INTEGER at offset ${start}`, DecodeLimitKind.NativeWidth);
|
|
252
|
+
}
|
|
253
|
+
// Safe to materialize as a JS number: guarded by the limit check above.
|
|
254
|
+
return Number(result);
|
|
255
|
+
}
|
|
256
|
+
function normalizeDecodeOptions(options) {
|
|
257
|
+
const maxDepth = options.maxDepth ?? DEFAULT_MAX_DEPTH;
|
|
258
|
+
const maxAtomBytes = options.maxAtomBytes ?? Number.MAX_SAFE_INTEGER;
|
|
259
|
+
const maxTupleArity = options.maxTupleArity ?? Number.MAX_SAFE_INTEGER;
|
|
260
|
+
for (const [name, value] of [
|
|
261
|
+
["maxDepth", maxDepth],
|
|
262
|
+
["maxAtomBytes", maxAtomBytes],
|
|
263
|
+
["maxTupleArity", maxTupleArity],
|
|
264
|
+
]) {
|
|
265
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
266
|
+
throw new RangeError(`${name} must be a non-negative safe integer`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return { maxDepth, maxAtomBytes, maxTupleArity };
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,IAAI,EAAS,IAAI,EAAE,KAAK,EAA8B,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEnH,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,8EAA8E;AAC9E,4EAA4E;AAC5E,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,eAAe,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,iDAAiD;AACpF,iFAAiF;AACjF,sEAAsE;AACtE,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAwB7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,yFAAyF;IACzF,WAAW,EAAE,cAAc;IAC3B,0DAA0D;IAC1D,SAAS,EAAE,YAAY;IACvB,sDAAsD;IACtD,UAAU,EAAE,aAAa;IACzB,oFAAoF;IACpF,WAAW,EAAE,cAAc;CACnB,CAAC;AAQX,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAkB;IAS/B,YAAY,IAAqB,EAAE,OAAe,EAAE,SAA2B;QAC7E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,SAAS,KAAK,SAAS;YAAE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,UAAU,MAAM,CAAC,KAAY;IACjC,yGA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C;QACX,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,sCAAsC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AACnD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitspark/ontos-codec",
|
|
3
|
+
"version": "0.13.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "ontos canonical binary codec (ontos-codec-v1, frozen). Depends on @bitspark/ontos-core.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Bitspark/ontos.git"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org/",
|
|
14
|
+
"provenance": true
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/src",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"NOTICE"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/src/index.js",
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@bitspark/ontos-core": "^0.13.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.json",
|
|
30
|
+
"test": "node --test test/*.test.ts"
|
|
31
|
+
}
|
|
32
|
+
}
|