@omnibuf/core 0.0.8 → 0.1.2
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 +201 -21
- package/dist/blind.d.ts +3 -3
- package/dist/blind.d.ts.map +1 -1
- package/dist/blind.js +191 -31
- package/dist/blind.js.map +1 -1
- package/dist/encoder.d.ts +5 -5
- package/dist/encoder.d.ts.map +1 -1
- package/dist/encoder.js +25 -4
- package/dist/encoder.js.map +1 -1
- package/dist/protobuf-es.d.ts +2 -0
- package/dist/protobuf-es.d.ts.map +1 -1
- package/dist/protobuf-es.js +40 -8
- package/dist/protobuf-es.js.map +1 -1
- package/dist/readers.d.ts +4 -3
- package/dist/readers.d.ts.map +1 -1
- package/dist/readers.js +411 -120
- package/dist/readers.js.map +1 -1
- package/dist/schema.d.ts +15 -5
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +585 -205
- package/dist/schema.js.map +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +16 -14
- package/dist/validation.js.map +1 -1
- package/dist/wire.d.ts +16 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +441 -23
- package/dist/wire.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kevin McDonald
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/blind.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function encodeField0SchemaMeta(meta: SchemaMeta | null | undefin
|
|
|
24
24
|
export declare function mergeSchemaMeta(base: SchemaMeta | null | undefined, next: SchemaMeta | null | undefined): SchemaMeta | null;
|
|
25
25
|
export declare function decodeSchemaMeta(data: Uint8Array, depth?: number, limit?: number): SchemaMeta;
|
|
26
26
|
/**
|
|
27
|
-
* Decodes and merges all Field #0 (`Tag =
|
|
27
|
+
* Decodes and merges all Field #0 (`Tag = 0x19`, `WireSubMsg = 12`) SchemaMeta blocks in `packet`.
|
|
28
28
|
*/
|
|
29
29
|
export declare function readField0SchemaMeta(packet: Uint8Array): [meta: SchemaMeta | null, ok: boolean];
|
|
30
30
|
export interface DecodeBlindOptions {
|
|
@@ -34,7 +34,7 @@ export interface DecodeBlindOptions {
|
|
|
34
34
|
*/
|
|
35
35
|
bytesAsBase64?: boolean;
|
|
36
36
|
/**
|
|
37
|
-
* When true (default), `
|
|
37
|
+
* When true (default), `WireFloat32` values are rounded to their shortest 32-bit IEEE-754 decimal representation.
|
|
38
38
|
*/
|
|
39
39
|
roundFloat32?: boolean;
|
|
40
40
|
/**
|
|
@@ -44,7 +44,7 @@ export interface DecodeBlindOptions {
|
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* Decodes any OmniBuf packet without a compile-time schema.
|
|
47
|
-
* If Field #0 (`Tag =
|
|
47
|
+
* If Field #0 (`Tag = 0x19`, `WireSubMsg = 12`, `omnibuf.v1.SchemaMeta`) is present, its field names
|
|
48
48
|
* (and any nested children schemas) are used to decode human-readable keys.
|
|
49
49
|
* Otherwise, synthetic field names (`"field_1"`, `"field_2"`, ...) are used.
|
|
50
50
|
*/
|
package/dist/blind.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blind.d.ts","sourceRoot":"","sources":["../src/blind.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAwCvC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACvC;AAOD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CA0B5D;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CA0B1D;
|
|
1
|
+
{"version":3,"file":"blind.d.ts","sourceRoot":"","sources":["../src/blind.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAwCvC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACvC;AAOD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CA0B5D;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CA0B1D;AAmED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACnC,aAAa,UAAQ,GACpB,IAAI,CAMN;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACnC,aAAa,UAAO,GACnB,UAAU,CAKZ;AAmCD;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACnC,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GAClC,UAAU,GAAG,IAAI,CAuCnB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,SAAI,EAAE,KAAK,SAAkB,GAAG,UAAU,CAmHjG;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAe/F;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;OAEG;IACH,eAAe,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;CACrC;AAsJD;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGzB;AAypBD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,MAAM,EACf,mBAAmB,UAAQ,GAC1B,MAAM,CAmFR;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3D,MAAM,CAGR"}
|
package/dist/blind.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// ============================================================================
|
|
2
2
|
// Field #0 (omnibuf.v1.SchemaMeta) & Schema-Less Inspection (DecodeBlind)
|
|
3
3
|
// ============================================================================
|
|
4
|
-
import { validateMapTypes, validateValue } from './validation.js';
|
|
4
|
+
import { validateMapTypes, validateMessage, validateValue } from './validation.js';
|
|
5
5
|
import { Encoder } from './encoder.js';
|
|
6
6
|
import { appendBoolArrBody, appendSintArrAutoBody, appendStringArrBody, appendUintArrAutoBody, countSubMsgArrElems, } from './readers.js';
|
|
7
7
|
import { MaxNestingDepth, WireArray, WireBoolFalse, WireBoolTrue, WireBytes, WireExtended, WireFixed32, WireFixed64, WireFloat32, WireFloat64, WireMap, WireSfixed32, WireSfixed64, WireSint, WireString, WireSubMsg, WireUint, decodeUTF8, decodeVarintAuto, decodeVarintBigInt, decodeZigZagAuto, float32FromBits, float64FromBits, nextContainerField, parseArrayHeader, parseMapHeader, readLenSlice, roundFloat32Shortest, skipValue, } from './wire.js';
|
|
@@ -81,6 +81,11 @@ function writeSchemaMetaBody(enc, meta, deterministic) {
|
|
|
81
81
|
if (meta.fields) {
|
|
82
82
|
const keys = Object.keys(meta.fields).map(Number);
|
|
83
83
|
if (keys.length > 0) {
|
|
84
|
+
for (const k of keys) {
|
|
85
|
+
if (!Number.isInteger(k) || k < 1 || k > 536870911) {
|
|
86
|
+
throw new Error(`omnibuf: invalid SchemaMeta field number ${k}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
84
89
|
if (deterministic) {
|
|
85
90
|
keys.sort((a, b) => a - b);
|
|
86
91
|
}
|
|
@@ -101,6 +106,11 @@ function writeSchemaMetaBody(enc, meta, deterministic) {
|
|
|
101
106
|
if (meta.children) {
|
|
102
107
|
const keys = Object.keys(meta.children).map(Number);
|
|
103
108
|
if (keys.length > 0) {
|
|
109
|
+
for (const k of keys) {
|
|
110
|
+
if (!Number.isInteger(k) || k < 1 || k > 536870911) {
|
|
111
|
+
throw new Error(`omnibuf: invalid SchemaMeta child field number ${k}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
104
114
|
if (deterministic) {
|
|
105
115
|
keys.sort((a, b) => a - b);
|
|
106
116
|
}
|
|
@@ -141,20 +151,57 @@ export function encodeField0SchemaMeta(meta, deterministic = true) {
|
|
|
141
151
|
writeField0SchemaMeta(enc, meta, deterministic);
|
|
142
152
|
return enc.finish();
|
|
143
153
|
}
|
|
154
|
+
function hasAnyOwnKey(obj) {
|
|
155
|
+
if (!obj)
|
|
156
|
+
return false;
|
|
157
|
+
for (const _ in obj) {
|
|
158
|
+
if (Object.hasOwn(obj, _))
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
function mergeSchemaMetaInPlace(target, next) {
|
|
164
|
+
if (next.typeName) {
|
|
165
|
+
target.typeName = next.typeName;
|
|
166
|
+
}
|
|
167
|
+
if (next.fields) {
|
|
168
|
+
if (!target.fields) {
|
|
169
|
+
target.fields = next.fields;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
Object.assign(target.fields, next.fields);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (next.children) {
|
|
176
|
+
if (!target.children) {
|
|
177
|
+
target.children = next.children;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
for (const [k, c] of Object.entries(next.children)) {
|
|
181
|
+
const numK = Number(k);
|
|
182
|
+
const existing = target.children[numK];
|
|
183
|
+
target.children[numK] = existing ? mergeSchemaMetaInPlace(existing, c) : c;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return target;
|
|
188
|
+
}
|
|
144
189
|
/**
|
|
145
190
|
* Merges two `SchemaMeta` definitions (later fields and children override/extend earlier ones).
|
|
146
191
|
*/
|
|
147
192
|
export function mergeSchemaMeta(base, next) {
|
|
148
193
|
if (!next)
|
|
149
194
|
return base ?? null;
|
|
195
|
+
const nextHasFields = hasAnyOwnKey(next.fields);
|
|
196
|
+
const nextHasChildren = hasAnyOwnKey(next.children);
|
|
150
197
|
if (!base) {
|
|
151
198
|
const cp = {};
|
|
152
199
|
if (next.typeName)
|
|
153
200
|
cp.typeName = next.typeName;
|
|
154
|
-
if (
|
|
201
|
+
if (nextHasFields) {
|
|
155
202
|
cp.fields = { ...next.fields };
|
|
156
203
|
}
|
|
157
|
-
if (
|
|
204
|
+
if (nextHasChildren) {
|
|
158
205
|
cp.children = {};
|
|
159
206
|
for (const [k, c] of Object.entries(next.children)) {
|
|
160
207
|
const mergedChild = mergeSchemaMeta(null, c);
|
|
@@ -164,15 +211,18 @@ export function mergeSchemaMeta(base, next) {
|
|
|
164
211
|
}
|
|
165
212
|
return cp;
|
|
166
213
|
}
|
|
214
|
+
if (!next.typeName && !nextHasFields && !nextHasChildren) {
|
|
215
|
+
return base;
|
|
216
|
+
}
|
|
167
217
|
const out = {
|
|
168
218
|
typeName: next.typeName || base.typeName,
|
|
169
219
|
};
|
|
170
|
-
if (base.fields ||
|
|
220
|
+
if (base.fields || nextHasFields) {
|
|
171
221
|
out.fields = { ...(base.fields ?? {}), ...(next.fields ?? {}) };
|
|
172
222
|
}
|
|
173
|
-
if (base.children ||
|
|
223
|
+
if (base.children || nextHasChildren) {
|
|
174
224
|
out.children = { ...(base.children ?? {}) };
|
|
175
|
-
if (
|
|
225
|
+
if (nextHasChildren) {
|
|
176
226
|
for (const [k, c] of Object.entries(next.children)) {
|
|
177
227
|
const numK = Number(k);
|
|
178
228
|
const mergedChild = mergeSchemaMeta(out.children[numK], c);
|
|
@@ -185,7 +235,7 @@ export function mergeSchemaMeta(base, next) {
|
|
|
185
235
|
}
|
|
186
236
|
export function decodeSchemaMeta(data, depth = 0, limit = MaxNestingDepth) {
|
|
187
237
|
if (depth > limit) {
|
|
188
|
-
throw new Error(`omnibuf: SchemaMeta nesting depth ${depth} exceeds MaxNestingDepth (${
|
|
238
|
+
throw new Error(`omnibuf: SchemaMeta nesting depth ${depth} exceeds MaxNestingDepth (${limit})`);
|
|
189
239
|
}
|
|
190
240
|
const meta = {};
|
|
191
241
|
let pos = 0;
|
|
@@ -212,6 +262,9 @@ export function decodeSchemaMeta(data, depth = 0, limit = MaxNestingDepth) {
|
|
|
212
262
|
if (wt !== WireMap) {
|
|
213
263
|
throw new Error(`omnibuf: SchemaMeta field #2 (fields) must be WireMap, got ${wt}`);
|
|
214
264
|
}
|
|
265
|
+
if (depth + 1 > limit) {
|
|
266
|
+
throw new Error(`omnibuf: SchemaMeta fields map nesting depth ${depth + 1} exceeds MaxNestingDepth (${limit})`);
|
|
267
|
+
}
|
|
215
268
|
const [body, nextPos] = readLenSlice(data, pos, 3);
|
|
216
269
|
pos = nextPos;
|
|
217
270
|
const [keyWT, valWT, c, startP, ok] = parseMapHeader(body);
|
|
@@ -240,14 +293,16 @@ export function decodeSchemaMeta(data, depth = 0, limit = MaxNestingDepth) {
|
|
|
240
293
|
if (wt !== WireMap) {
|
|
241
294
|
throw new Error(`omnibuf: SchemaMeta field #3 (children) must be WireMap, got ${wt}`);
|
|
242
295
|
}
|
|
296
|
+
if (depth + 1 > limit) {
|
|
297
|
+
throw new Error(`omnibuf: SchemaMeta children map nesting depth ${depth + 1} exceeds MaxNestingDepth (${limit})`);
|
|
298
|
+
}
|
|
243
299
|
const [body, nextPos] = readLenSlice(data, pos, 3);
|
|
244
300
|
pos = nextPos;
|
|
245
301
|
const [keyWT, valWT, c, startP, ok] = parseMapHeader(body);
|
|
246
302
|
if (!ok || keyWT !== WireUint || valWT !== WireSubMsg) {
|
|
247
303
|
throw new Error('omnibuf: invalid SchemaMeta children map header');
|
|
248
304
|
}
|
|
249
|
-
|
|
250
|
-
meta.children = {};
|
|
305
|
+
const mapChildren = {};
|
|
251
306
|
let p = startP;
|
|
252
307
|
for (let i = 0; i < c; i++) {
|
|
253
308
|
const [k64, kn] = decodeVarintBigInt(body, p);
|
|
@@ -256,14 +311,21 @@ export function decodeSchemaMeta(data, depth = 0, limit = MaxNestingDepth) {
|
|
|
256
311
|
}
|
|
257
312
|
p += kn;
|
|
258
313
|
const [childBytes, nextP] = readLenSlice(body, p, 0);
|
|
259
|
-
const childMeta = decodeSchemaMeta(childBytes, depth +
|
|
260
|
-
|
|
261
|
-
|
|
314
|
+
const childMeta = decodeSchemaMeta(childBytes, depth + 2, limit);
|
|
315
|
+
// Duplicate key inside a single WireMap replaces prior entry (Spec 6.6).
|
|
316
|
+
mapChildren[Number(k64)] = childMeta;
|
|
262
317
|
p = nextP;
|
|
263
318
|
}
|
|
264
319
|
if (p !== body.length) {
|
|
265
320
|
throw new Error(`omnibuf: SchemaMeta children map trailing bytes (parsed ${p}, body ${body.length})`);
|
|
266
321
|
}
|
|
322
|
+
// Merge across separate children WireMap fields (Spec 8.2).
|
|
323
|
+
if (!meta.children)
|
|
324
|
+
meta.children = {};
|
|
325
|
+
for (const [k, childMeta] of Object.entries(mapChildren)) {
|
|
326
|
+
const numK = Number(k);
|
|
327
|
+
meta.children[numK] = mergeSchemaMeta(meta.children[numK], childMeta) ?? childMeta;
|
|
328
|
+
}
|
|
267
329
|
break;
|
|
268
330
|
}
|
|
269
331
|
default: {
|
|
@@ -278,7 +340,7 @@ export function decodeSchemaMeta(data, depth = 0, limit = MaxNestingDepth) {
|
|
|
278
340
|
return meta;
|
|
279
341
|
}
|
|
280
342
|
/**
|
|
281
|
-
* Decodes and merges all Field #0 (`Tag =
|
|
343
|
+
* Decodes and merges all Field #0 (`Tag = 0x19`, `WireSubMsg = 12`) SchemaMeta blocks in `packet`.
|
|
282
344
|
*/
|
|
283
345
|
export function readField0SchemaMeta(packet) {
|
|
284
346
|
let merged = null;
|
|
@@ -291,8 +353,8 @@ export function readField0SchemaMeta(packet) {
|
|
|
291
353
|
return [merged, merged !== null];
|
|
292
354
|
pos = nextPos;
|
|
293
355
|
try {
|
|
294
|
-
const m = decodeSchemaMeta(body,
|
|
295
|
-
merged =
|
|
356
|
+
const m = decodeSchemaMeta(body, 1);
|
|
357
|
+
merged = merged ? mergeSchemaMetaInPlace(merged, m) : m;
|
|
296
358
|
}
|
|
297
359
|
catch {
|
|
298
360
|
return [null, false];
|
|
@@ -321,9 +383,106 @@ function blindChildSchema(schema, fieldNum) {
|
|
|
321
383
|
: undefined;
|
|
322
384
|
return wrapBlindSchema(child, parent);
|
|
323
385
|
}
|
|
386
|
+
function unifyBlindShapes(a, b) {
|
|
387
|
+
if (!a)
|
|
388
|
+
return [b ?? null, true];
|
|
389
|
+
if (!b)
|
|
390
|
+
return [a, true];
|
|
391
|
+
if (a.wt !== b.wt)
|
|
392
|
+
return [null, false];
|
|
393
|
+
if (a.wt === WireMap) {
|
|
394
|
+
if (a.anyMap)
|
|
395
|
+
return [b, true];
|
|
396
|
+
if (b.anyMap)
|
|
397
|
+
return [a, true];
|
|
398
|
+
if (a.keyWT !== b.keyWT)
|
|
399
|
+
return [null, false];
|
|
400
|
+
}
|
|
401
|
+
if (a.wt !== WireArray && a.wt !== WireMap) {
|
|
402
|
+
return [a, true];
|
|
403
|
+
}
|
|
404
|
+
const [u, ok] = unifyBlindShapes(a.elem, b.elem);
|
|
405
|
+
if (!ok)
|
|
406
|
+
return [null, false];
|
|
407
|
+
return [{ wt: a.wt, keyWT: a.keyWT, elem: u }, true];
|
|
408
|
+
}
|
|
409
|
+
function parseBlindContainerShape(data, pos, wt, depth) {
|
|
410
|
+
if (depth + 1 > MaxNestingDepth) {
|
|
411
|
+
throw new Error(`omnibuf: container nesting depth ${depth + 1} exceeds MaxNestingDepth (${MaxNestingDepth})`);
|
|
412
|
+
}
|
|
413
|
+
if (wt === WireArray) {
|
|
414
|
+
const [body, nextPos] = readLenSlice(data, pos, 2);
|
|
415
|
+
const [elemWT, count, startP, ok] = parseArrayHeader(body);
|
|
416
|
+
if (!ok) {
|
|
417
|
+
throw new Error('omnibuf: invalid WireArray header');
|
|
418
|
+
}
|
|
419
|
+
if (elemWT !== WireArray && elemWT !== WireMap) {
|
|
420
|
+
return [{ wt: WireArray, elem: { wt: elemWT } }, nextPos];
|
|
421
|
+
}
|
|
422
|
+
if (count === 0) {
|
|
423
|
+
if (elemWT === WireArray) {
|
|
424
|
+
return [{ wt: WireArray, elem: { wt: WireArray } }, nextPos];
|
|
425
|
+
}
|
|
426
|
+
return [{ wt: WireArray, elem: { wt: WireMap, anyMap: true } }, nextPos];
|
|
427
|
+
}
|
|
428
|
+
let merged = null;
|
|
429
|
+
let p = startP;
|
|
430
|
+
for (let i = 0; i < count; i++) {
|
|
431
|
+
const [elemShape, nextP] = parseBlindContainerShape(body, p, elemWT, depth + 1);
|
|
432
|
+
const [u, compat] = unifyBlindShapes(merged, elemShape);
|
|
433
|
+
if (!compat) {
|
|
434
|
+
throw new Error('omnibuf: inconsistent nested container element shapes in WireArray');
|
|
435
|
+
}
|
|
436
|
+
merged = u;
|
|
437
|
+
p = nextP;
|
|
438
|
+
}
|
|
439
|
+
if (p !== body.length) {
|
|
440
|
+
throw new Error('omnibuf: WireArray count/length mismatch');
|
|
441
|
+
}
|
|
442
|
+
return [{ wt: WireArray, elem: merged }, nextPos];
|
|
443
|
+
}
|
|
444
|
+
const [body, nextPos] = readLenSlice(data, pos, 3);
|
|
445
|
+
const [keyWT, valWT, count, startP, ok] = parseMapHeader(body);
|
|
446
|
+
if (!ok) {
|
|
447
|
+
throw new Error(`omnibuf: invalid WireMap header at ${pos}`);
|
|
448
|
+
}
|
|
449
|
+
validateMapTypes(keyWT, valWT);
|
|
450
|
+
if (valWT !== WireArray && valWT !== WireMap) {
|
|
451
|
+
return [{ wt: WireMap, keyWT, elem: { wt: valWT } }, nextPos];
|
|
452
|
+
}
|
|
453
|
+
if (count === 0) {
|
|
454
|
+
if (valWT === WireArray) {
|
|
455
|
+
return [{ wt: WireMap, keyWT, elem: { wt: WireArray } }, nextPos];
|
|
456
|
+
}
|
|
457
|
+
return [{ wt: WireMap, keyWT, elem: { wt: WireMap, anyMap: true } }, nextPos];
|
|
458
|
+
}
|
|
459
|
+
let merged = null;
|
|
460
|
+
let p = startP;
|
|
461
|
+
for (let i = 0; i < count; i++) {
|
|
462
|
+
p = skipValue(body, p, keyWT);
|
|
463
|
+
const [valShape, nextP] = parseBlindContainerShape(body, p, valWT, depth + 1);
|
|
464
|
+
const [u, compat] = unifyBlindShapes(merged, valShape);
|
|
465
|
+
if (!compat) {
|
|
466
|
+
throw new Error('omnibuf: inconsistent nested container value shapes in WireMap');
|
|
467
|
+
}
|
|
468
|
+
merged = u;
|
|
469
|
+
p = nextP;
|
|
470
|
+
}
|
|
471
|
+
if (p !== body.length) {
|
|
472
|
+
throw new Error('omnibuf: WireMap count/length mismatch');
|
|
473
|
+
}
|
|
474
|
+
return [{ wt: WireMap, keyWT, elem: merged }, nextPos];
|
|
475
|
+
}
|
|
476
|
+
function parseBlindFieldShape(data, pos, wt, depth) {
|
|
477
|
+
const normWT = wt === WireBoolTrue ? WireBoolFalse : wt;
|
|
478
|
+
if (normWT !== WireArray && normWT !== WireMap) {
|
|
479
|
+
return { wt: normWT };
|
|
480
|
+
}
|
|
481
|
+
return parseBlindContainerShape(data, pos, normWT, depth)[0];
|
|
482
|
+
}
|
|
324
483
|
/**
|
|
325
484
|
* Decodes any OmniBuf packet without a compile-time schema.
|
|
326
|
-
* If Field #0 (`Tag =
|
|
485
|
+
* If Field #0 (`Tag = 0x19`, `WireSubMsg = 12`, `omnibuf.v1.SchemaMeta`) is present, its field names
|
|
327
486
|
* (and any nested children schemas) are used to decode human-readable keys.
|
|
328
487
|
* Otherwise, synthetic field names (`"field_1"`, `"field_2"`, ...) are used.
|
|
329
488
|
*/
|
|
@@ -359,7 +518,7 @@ function decodeBlindWithSchema(data, inherited, depth, options, target) {
|
|
|
359
518
|
const [f0Body, nextPos] = readLenSlice(data, scanPos, 0);
|
|
360
519
|
scanPos = nextPos;
|
|
361
520
|
const parsedMeta = decodeSchemaMeta(f0Body, depth + 1);
|
|
362
|
-
localSchema =
|
|
521
|
+
localSchema = localSchema ? mergeSchemaMetaInPlace(localSchema, parsedMeta) : parsedMeta;
|
|
363
522
|
continue;
|
|
364
523
|
}
|
|
365
524
|
scanPos = skipValue(data, scanPos, wt);
|
|
@@ -385,18 +544,13 @@ function decodeBlindWithSchema(data, inherited, depth, options, target) {
|
|
|
385
544
|
throw new Error(`omnibuf: fields ${previousField} and ${fieldNum} share name ${name}`);
|
|
386
545
|
}
|
|
387
546
|
fieldNames.set(name, fieldNum);
|
|
388
|
-
|
|
389
|
-
if (wt === WireArray || wt === WireMap) {
|
|
390
|
-
const [body] = readLenSlice(data, pos, wt === WireArray ? 2 : 3);
|
|
391
|
-
shape |= body[0] << 8;
|
|
392
|
-
if (wt === WireMap)
|
|
393
|
-
shape |= body[1] << 16;
|
|
394
|
-
}
|
|
547
|
+
const shape = parseBlindFieldShape(data, pos, wt, depth);
|
|
395
548
|
const previousShape = fieldShapes.get(fieldNum);
|
|
396
|
-
|
|
549
|
+
const [unifiedShape, shapeOk] = unifyBlindShapes(previousShape, shape);
|
|
550
|
+
if (!shapeOk || !unifiedShape) {
|
|
397
551
|
throw new Error(`omnibuf: field ${fieldNum} changes wire shape within one message`);
|
|
398
552
|
}
|
|
399
|
-
fieldShapes.set(fieldNum,
|
|
553
|
+
fieldShapes.set(fieldNum, unifiedShape);
|
|
400
554
|
if (!Object.hasOwn(out, name) && wt !== WireSubMsg)
|
|
401
555
|
setOwn(out, name, undefined);
|
|
402
556
|
switch (wt) {
|
|
@@ -438,6 +592,7 @@ function decodeBlindWithSchema(data, inherited, depth, options, target) {
|
|
|
438
592
|
}
|
|
439
593
|
case WireSubMsg: {
|
|
440
594
|
const [subBytes, nextPos] = readLenSlice(data, pos, 0);
|
|
595
|
+
validateMessage(subBytes, depth + 1);
|
|
441
596
|
let chunks = subPackets.get(fieldNum);
|
|
442
597
|
if (!chunks) {
|
|
443
598
|
chunks = [];
|
|
@@ -455,7 +610,7 @@ function decodeBlindWithSchema(data, inherited, depth, options, target) {
|
|
|
455
610
|
}
|
|
456
611
|
const childSchema = blindChildSchema(activeSchema, fieldNum);
|
|
457
612
|
const prev = Array.isArray(out[name]) ? out[name] : [];
|
|
458
|
-
out[name] = decodeArrayBodyBlind(prev, body, childSchema, depth, options);
|
|
613
|
+
out[name] = decodeArrayBodyBlind(prev, body, childSchema, depth + 1, options);
|
|
459
614
|
pos = nextPos;
|
|
460
615
|
break;
|
|
461
616
|
}
|
|
@@ -470,7 +625,7 @@ function decodeBlindWithSchema(data, inherited, depth, options, target) {
|
|
|
470
625
|
const m = prev && typeof prev === 'object' && !Array.isArray(prev) && !(prev instanceof Uint8Array)
|
|
471
626
|
? prev
|
|
472
627
|
: {};
|
|
473
|
-
out[name] = decodeMapBodyBlind(m, body, childSchema, depth, options);
|
|
628
|
+
out[name] = decodeMapBodyBlind(m, body, childSchema, depth + 1, options);
|
|
474
629
|
pos = nextPos;
|
|
475
630
|
break;
|
|
476
631
|
}
|
|
@@ -1022,13 +1177,18 @@ export function stringifyBlindJSON(value, indent, fallbackOnNonFinite = false) {
|
|
|
1022
1177
|
continue;
|
|
1023
1178
|
parts.push(`${nextIndent}${JSON.stringify(k)}: ${serialize(v, nextIndent)}`);
|
|
1024
1179
|
}
|
|
1180
|
+
if (parts.length === 0)
|
|
1181
|
+
return '{}';
|
|
1025
1182
|
return `{\n${parts.join(',\n')}\n${currentIndent}}`;
|
|
1026
1183
|
}
|
|
1027
1184
|
return 'null';
|
|
1028
1185
|
}
|
|
1029
1186
|
const out = serialize(value, '');
|
|
1030
|
-
if (hasNonFinite
|
|
1031
|
-
|
|
1187
|
+
if (hasNonFinite) {
|
|
1188
|
+
if (fallbackOnNonFinite) {
|
|
1189
|
+
return '{}';
|
|
1190
|
+
}
|
|
1191
|
+
throw new Error('omnibuf: non-finite float (NaN or Infinity) cannot be represented in JSON');
|
|
1032
1192
|
}
|
|
1033
1193
|
return out;
|
|
1034
1194
|
}
|
|
@@ -1037,7 +1197,7 @@ export function stringifyBlindJSON(value, indent, fallbackOnNonFinite = false) {
|
|
|
1037
1197
|
*/
|
|
1038
1198
|
export function decodeBlindJSON(packet, options) {
|
|
1039
1199
|
const m = decodeBlind(packet, { bytesAsBase64: true, roundFloat32: true });
|
|
1040
|
-
return stringifyBlindJSON(m, options?.indent, options?.fallbackOnNonFinite ??
|
|
1200
|
+
return stringifyBlindJSON(m, options?.indent, options?.fallbackOnNonFinite ?? false);
|
|
1041
1201
|
}
|
|
1042
1202
|
function setOwn(object, key, value) {
|
|
1043
1203
|
Object.defineProperty(object, key, {
|