@bufbuild/protobuf 1.4.2 → 1.5.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/dist/cjs/create-descriptor-set.d.ts +19 -5
- package/dist/cjs/create-descriptor-set.js +157 -223
- package/dist/cjs/descriptor-set.d.ts +47 -5
- package/dist/cjs/google/protobuf/any_pb.js +1 -1
- package/dist/cjs/google/protobuf/descriptor_pb.js +1 -1
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/private/feature-set.d.ts +21 -0
- package/dist/cjs/private/feature-set.js +107 -0
- package/dist/cjs/private/text-format.d.ts +4 -0
- package/dist/cjs/private/text-format.js +189 -0
- package/dist/esm/create-descriptor-set.d.ts +19 -5
- package/dist/esm/create-descriptor-set.js +157 -222
- package/dist/esm/descriptor-set.d.ts +47 -5
- package/dist/esm/google/protobuf/any_pb.js +1 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +1 -1
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/private/feature-set.d.ts +21 -0
- package/dist/esm/private/feature-set.js +103 -0
- package/dist/esm/private/text-format.d.ts +4 -0
- package/dist/esm/private/text-format.js +184 -0
- package/package.json +5 -5
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { DescriptorProto, EnumDescriptorProto, EnumValueDescriptorProto, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, OneofDescriptorProto, ServiceDescriptorProto } from "./google/protobuf/descriptor_pb.js";
|
|
2
|
-
import type {
|
|
1
|
+
import type { DescriptorProto, Edition, EnumDescriptorProto, EnumValueDescriptorProto, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, OneofDescriptorProto, ServiceDescriptorProto } from "./google/protobuf/descriptor_pb.js";
|
|
2
|
+
import type { LongType, ScalarType } from "./field.js";
|
|
3
3
|
import type { MethodIdempotency, MethodKind } from "./service-type.js";
|
|
4
|
+
import type { MergedFeatureSet } from "./private/feature-set.js";
|
|
4
5
|
/**
|
|
5
6
|
* DescriptorSet provides a convenient interface for working with a set
|
|
6
7
|
* of google.protobuf.FileDescriptorProto.
|
|
@@ -50,7 +51,12 @@ export interface DescFile {
|
|
|
50
51
|
/**
|
|
51
52
|
* The syntax specified in the protobuf source.
|
|
52
53
|
*/
|
|
53
|
-
readonly syntax: "proto3" | "proto2";
|
|
54
|
+
readonly syntax: "proto3" | "proto2" | "editions";
|
|
55
|
+
/**
|
|
56
|
+
* The edition of the protobuf file. Will be EDITION_PROTO2 for syntax="proto2",
|
|
57
|
+
* EDITION_PROTO3 for syntax="proto3";
|
|
58
|
+
*/
|
|
59
|
+
readonly edition: Exclude<Edition, Edition.EDITION_1_TEST_ONLY | Edition.EDITION_2_TEST_ONLY | Edition.EDITION_99997_TEST_ONLY | Edition.EDITION_99998_TEST_ONLY | Edition.EDITION_99999_TEST_ONLY>;
|
|
54
60
|
/**
|
|
55
61
|
* The name of the file, excluding the .proto suffix.
|
|
56
62
|
* For a protobuf file `foo/bar.proto`, this is `foo/bar`.
|
|
@@ -91,6 +97,10 @@ export interface DescFile {
|
|
|
91
97
|
* Get comments on the package element in the protobuf source.
|
|
92
98
|
*/
|
|
93
99
|
getPackageComments(): DescComments;
|
|
100
|
+
/**
|
|
101
|
+
* Get the edition features for this protobuf element.
|
|
102
|
+
*/
|
|
103
|
+
getFeatures(): MergedFeatureSet;
|
|
94
104
|
toString(): string;
|
|
95
105
|
}
|
|
96
106
|
/**
|
|
@@ -135,6 +145,10 @@ export interface DescEnum {
|
|
|
135
145
|
* Get comments on the element in the protobuf source.
|
|
136
146
|
*/
|
|
137
147
|
getComments(): DescComments;
|
|
148
|
+
/**
|
|
149
|
+
* Get the edition features for this protobuf element.
|
|
150
|
+
*/
|
|
151
|
+
getFeatures(): MergedFeatureSet;
|
|
138
152
|
toString(): string;
|
|
139
153
|
}
|
|
140
154
|
/**
|
|
@@ -171,6 +185,10 @@ export interface DescEnumValue {
|
|
|
171
185
|
* Get comments on the element in the protobuf source.
|
|
172
186
|
*/
|
|
173
187
|
getComments(): DescComments;
|
|
188
|
+
/**
|
|
189
|
+
* Get the edition features for this protobuf element.
|
|
190
|
+
*/
|
|
191
|
+
getFeatures(): MergedFeatureSet;
|
|
174
192
|
toString(): string;
|
|
175
193
|
}
|
|
176
194
|
/**
|
|
@@ -234,6 +252,10 @@ export interface DescMessage {
|
|
|
234
252
|
* Get comments on the element in the protobuf source.
|
|
235
253
|
*/
|
|
236
254
|
getComments(): DescComments;
|
|
255
|
+
/**
|
|
256
|
+
* Get the edition features for this protobuf element.
|
|
257
|
+
*/
|
|
258
|
+
getFeatures(): MergedFeatureSet;
|
|
237
259
|
toString(): string;
|
|
238
260
|
}
|
|
239
261
|
/**
|
|
@@ -290,10 +312,14 @@ interface DescFieldCommon {
|
|
|
290
312
|
*/
|
|
291
313
|
readonly packed: boolean;
|
|
292
314
|
/**
|
|
293
|
-
* Is this field packed by default? Only valid for enum fields, and
|
|
294
|
-
* scalar fields except BYTES and STRING.
|
|
315
|
+
* Is this field packed by default? Only valid for repeated enum fields, and
|
|
316
|
+
* for repeated scalar fields except BYTES and STRING.
|
|
317
|
+
*
|
|
295
318
|
* In proto3 syntax, fields are packed by default. In proto2 syntax, fields
|
|
296
319
|
* are unpacked by default.
|
|
320
|
+
*
|
|
321
|
+
* With editions, the default is whatever the edition specifies as a default.
|
|
322
|
+
* In edition 2023, fields are packed by default.
|
|
297
323
|
*/
|
|
298
324
|
readonly packedByDefault: boolean;
|
|
299
325
|
/**
|
|
@@ -318,6 +344,10 @@ interface DescFieldCommon {
|
|
|
318
344
|
* protobuf source.
|
|
319
345
|
*/
|
|
320
346
|
declarationString(): string;
|
|
347
|
+
/**
|
|
348
|
+
* Get the edition features for this protobuf element.
|
|
349
|
+
*/
|
|
350
|
+
getFeatures(): MergedFeatureSet;
|
|
321
351
|
toString(): string;
|
|
322
352
|
}
|
|
323
353
|
interface DescFieldScalar {
|
|
@@ -534,6 +564,10 @@ export interface DescOneof {
|
|
|
534
564
|
* Get comments on the element in the protobuf source.
|
|
535
565
|
*/
|
|
536
566
|
getComments(): DescComments;
|
|
567
|
+
/**
|
|
568
|
+
* Get the edition features for this protobuf element.
|
|
569
|
+
*/
|
|
570
|
+
getFeatures(): MergedFeatureSet;
|
|
537
571
|
toString(): string;
|
|
538
572
|
}
|
|
539
573
|
/**
|
|
@@ -569,6 +603,10 @@ export interface DescService {
|
|
|
569
603
|
* Get comments on the element in the protobuf source.
|
|
570
604
|
*/
|
|
571
605
|
getComments(): DescComments;
|
|
606
|
+
/**
|
|
607
|
+
* Get the edition features for this protobuf element.
|
|
608
|
+
*/
|
|
609
|
+
getFeatures(): MergedFeatureSet;
|
|
572
610
|
toString(): string;
|
|
573
611
|
}
|
|
574
612
|
/**
|
|
@@ -612,6 +650,10 @@ export interface DescMethod {
|
|
|
612
650
|
* Get comments on the element in the protobuf source.
|
|
613
651
|
*/
|
|
614
652
|
getComments(): DescComments;
|
|
653
|
+
/**
|
|
654
|
+
* Get the edition features for this protobuf element.
|
|
655
|
+
*/
|
|
656
|
+
getFeatures(): MergedFeatureSet;
|
|
615
657
|
toString(): string;
|
|
616
658
|
}
|
|
617
659
|
/**
|
|
@@ -240,7 +240,7 @@ class Any extends message_js_1.Message {
|
|
|
240
240
|
throw new Error(`invalid type url: ${url}`);
|
|
241
241
|
}
|
|
242
242
|
const slash = url.lastIndexOf("/");
|
|
243
|
-
const name = slash
|
|
243
|
+
const name = slash >= 0 ? url.substring(slash + 1) : url;
|
|
244
244
|
if (!name.length) {
|
|
245
245
|
throw new Error(`invalid type url: ${url}`);
|
|
246
246
|
}
|
|
@@ -21,7 +21,7 @@ exports.GeneratedCodeInfo_Annotation_Semantic = exports.GeneratedCodeInfo_Annota
|
|
|
21
21
|
// The messages in this file describe the definitions found in .proto files.
|
|
22
22
|
// A valid .proto file can be translated directly to a FileDescriptorProto
|
|
23
23
|
// without any other information (e.g. without reading its imports).
|
|
24
|
-
// @generated by protoc-gen-es v1.
|
|
24
|
+
// @generated by protoc-gen-es v1.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
25
25
|
// @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
|
|
26
26
|
/* eslint-disable */
|
|
27
27
|
const proto2_js_1 = require("../../proto2.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v1.
|
|
17
|
+
// @generated by protoc-gen-es v1.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v1.
|
|
17
|
+
// @generated by protoc-gen-es v1.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Edition, FeatureSet, FeatureSetDefaults } from "../google/protobuf/descriptor_pb.js";
|
|
2
|
+
/**
|
|
3
|
+
* Static edition feature defaults supported by @bufbuild/protobuf.
|
|
4
|
+
*/
|
|
5
|
+
export declare const featureSetDefaults: FeatureSetDefaults;
|
|
6
|
+
/**
|
|
7
|
+
* A merged google.protobuf.FeaturesSet, with all fields guaranteed to be set.
|
|
8
|
+
*/
|
|
9
|
+
export type MergedFeatureSet = FeatureSet & Required<FeatureSet>;
|
|
10
|
+
/**
|
|
11
|
+
* A function that resolves features for the given edition.
|
|
12
|
+
*
|
|
13
|
+
* If no feature set is provided, the default feature set for the edition is
|
|
14
|
+
* returned. If features are provided, they are merged into the edition default
|
|
15
|
+
* features.
|
|
16
|
+
*/
|
|
17
|
+
export type FeatureResolverFn = (edition: Edition, a?: FeatureSet, b?: FeatureSet) => MergedFeatureSet;
|
|
18
|
+
/**
|
|
19
|
+
* Create an edition feature resolver with the given feature set defaults.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createFeatureResolver(compiledFeatureSetDefaults: FeatureSetDefaults): FeatureResolverFn;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.createFeatureResolver = exports.featureSetDefaults = void 0;
|
|
17
|
+
const descriptor_pb_js_1 = require("../google/protobuf/descriptor_pb.js");
|
|
18
|
+
const proto_base64_js_1 = require("../proto-base64.js");
|
|
19
|
+
/**
|
|
20
|
+
* Static edition feature defaults supported by @bufbuild/protobuf.
|
|
21
|
+
*/
|
|
22
|
+
exports.featureSetDefaults = descriptor_pb_js_1.FeatureSetDefaults.fromBinary(proto_base64_js_1.protoBase64.dec(
|
|
23
|
+
/*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiABKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/));
|
|
24
|
+
/**
|
|
25
|
+
* Create an edition feature resolver with the given feature set defaults.
|
|
26
|
+
*/
|
|
27
|
+
function createFeatureResolver(compiledFeatureSetDefaults) {
|
|
28
|
+
const min = compiledFeatureSetDefaults.minimumEdition;
|
|
29
|
+
const max = compiledFeatureSetDefaults.maximumEdition;
|
|
30
|
+
if (min === undefined ||
|
|
31
|
+
max === undefined ||
|
|
32
|
+
compiledFeatureSetDefaults.defaults.some((d) => d.edition === undefined)) {
|
|
33
|
+
throw new Error("Invalid FeatureSetDefaults");
|
|
34
|
+
}
|
|
35
|
+
const defaultsBinByEdition = new Map();
|
|
36
|
+
return (edition, ...rest) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
let defaultsBin = defaultsBinByEdition.get(edition);
|
|
39
|
+
if (defaultsBin === undefined) {
|
|
40
|
+
if (edition < min) {
|
|
41
|
+
throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is earlier than the minimum supported edition ${descriptor_pb_js_1.Edition[min]}`);
|
|
42
|
+
}
|
|
43
|
+
if (max < edition) {
|
|
44
|
+
throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is later than the maximum supported edition ${descriptor_pb_js_1.Edition[max]}`);
|
|
45
|
+
}
|
|
46
|
+
let highestMatch = undefined;
|
|
47
|
+
for (const c of compiledFeatureSetDefaults.defaults) {
|
|
48
|
+
const e = (_a = c.edition) !== null && _a !== void 0 ? _a : 0;
|
|
49
|
+
if (e > edition) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (highestMatch !== undefined && highestMatch.e > e) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
highestMatch = {
|
|
56
|
+
e,
|
|
57
|
+
f: (_b = c.features) !== null && _b !== void 0 ? _b : new descriptor_pb_js_1.FeatureSet(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (highestMatch === undefined) {
|
|
61
|
+
throw new Error(`No valid default found for edition ${descriptor_pb_js_1.Edition[edition]}`);
|
|
62
|
+
}
|
|
63
|
+
defaultsBin = highestMatch.f.toBinary();
|
|
64
|
+
defaultsBinByEdition.set(edition, defaultsBin);
|
|
65
|
+
}
|
|
66
|
+
const f = descriptor_pb_js_1.FeatureSet.fromBinary(defaultsBin);
|
|
67
|
+
for (const c of rest) {
|
|
68
|
+
if (c !== undefined) {
|
|
69
|
+
f.fromBinary(c.toBinary());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!validateMergedFeatures(f)) {
|
|
73
|
+
throw new Error(`Invalid FeatureSet for edition ${descriptor_pb_js_1.Edition[edition]}`);
|
|
74
|
+
}
|
|
75
|
+
return f;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.createFeatureResolver = createFeatureResolver;
|
|
79
|
+
// When protoc generates google.protobuf.FeatureSetDefaults, it ensures that
|
|
80
|
+
// fields are not repeated or required, do not use oneof, and have a default
|
|
81
|
+
// value.
|
|
82
|
+
//
|
|
83
|
+
// When features for an element are resolved, features of the element and its
|
|
84
|
+
// parents are merged into the default FeatureSet for the edition. Because unset
|
|
85
|
+
// fields in the FeatureSet of an element do not unset the default FeatureSet
|
|
86
|
+
// values, a resolved FeatureSet is guaranteed to have all fields set. This is
|
|
87
|
+
// also the case for extensions to FeatureSet that a user might provide, and for
|
|
88
|
+
// features from the future.
|
|
89
|
+
//
|
|
90
|
+
// We cannot exhaustively validate correctness of FeatureSetDefaults at runtime
|
|
91
|
+
// without knowing the schema: If no value for a feature is provided, we do not
|
|
92
|
+
// know that it exists at all.
|
|
93
|
+
//
|
|
94
|
+
// As a sanity check, we validate that all fields known to our version of
|
|
95
|
+
// FeatureSet are set.
|
|
96
|
+
function validateMergedFeatures(featureSet) {
|
|
97
|
+
for (const fi of descriptor_pb_js_1.FeatureSet.fields.list()) {
|
|
98
|
+
const v = featureSet[fi.localName];
|
|
99
|
+
if (v === undefined) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (fi.kind == "enum" && v === 0) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DescEnum } from "../descriptor-set.js";
|
|
2
|
+
import { ScalarType } from "../field.js";
|
|
3
|
+
export declare function parseTextFormatEnumValue(descEnum: DescEnum, value: string): number;
|
|
4
|
+
export declare function parseTextFormatScalarValue(type: ScalarType, value: string): number | boolean | string | bigint | Uint8Array;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-2023 Buf Technologies, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.parseTextFormatScalarValue = exports.parseTextFormatEnumValue = void 0;
|
|
17
|
+
const assert_js_1 = require("./assert.js");
|
|
18
|
+
const field_js_1 = require("../field.js");
|
|
19
|
+
const proto_int64_js_1 = require("../proto-int64.js");
|
|
20
|
+
function parseTextFormatEnumValue(descEnum, value) {
|
|
21
|
+
const enumValue = descEnum.values.find((v) => v.name === value);
|
|
22
|
+
(0, assert_js_1.assert)(enumValue, `cannot parse ${descEnum.name} default value: ${value}`);
|
|
23
|
+
return enumValue.number;
|
|
24
|
+
}
|
|
25
|
+
exports.parseTextFormatEnumValue = parseTextFormatEnumValue;
|
|
26
|
+
function parseTextFormatScalarValue(type, value) {
|
|
27
|
+
switch (type) {
|
|
28
|
+
case field_js_1.ScalarType.STRING:
|
|
29
|
+
return value;
|
|
30
|
+
case field_js_1.ScalarType.BYTES: {
|
|
31
|
+
const u = unescapeBytesDefaultValue(value);
|
|
32
|
+
if (u === false) {
|
|
33
|
+
throw new Error(`cannot parse ${field_js_1.ScalarType[type]} default value: ${value}`);
|
|
34
|
+
}
|
|
35
|
+
return u;
|
|
36
|
+
}
|
|
37
|
+
case field_js_1.ScalarType.INT64:
|
|
38
|
+
case field_js_1.ScalarType.SFIXED64:
|
|
39
|
+
case field_js_1.ScalarType.SINT64:
|
|
40
|
+
return proto_int64_js_1.protoInt64.parse(value);
|
|
41
|
+
case field_js_1.ScalarType.UINT64:
|
|
42
|
+
case field_js_1.ScalarType.FIXED64:
|
|
43
|
+
return proto_int64_js_1.protoInt64.uParse(value);
|
|
44
|
+
case field_js_1.ScalarType.DOUBLE:
|
|
45
|
+
case field_js_1.ScalarType.FLOAT:
|
|
46
|
+
switch (value) {
|
|
47
|
+
case "inf":
|
|
48
|
+
return Number.POSITIVE_INFINITY;
|
|
49
|
+
case "-inf":
|
|
50
|
+
return Number.NEGATIVE_INFINITY;
|
|
51
|
+
case "nan":
|
|
52
|
+
return Number.NaN;
|
|
53
|
+
default:
|
|
54
|
+
return parseFloat(value);
|
|
55
|
+
}
|
|
56
|
+
case field_js_1.ScalarType.BOOL:
|
|
57
|
+
return value === "true";
|
|
58
|
+
case field_js_1.ScalarType.INT32:
|
|
59
|
+
case field_js_1.ScalarType.UINT32:
|
|
60
|
+
case field_js_1.ScalarType.SINT32:
|
|
61
|
+
case field_js_1.ScalarType.FIXED32:
|
|
62
|
+
case field_js_1.ScalarType.SFIXED32:
|
|
63
|
+
return parseInt(value, 10);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.parseTextFormatScalarValue = parseTextFormatScalarValue;
|
|
67
|
+
/**
|
|
68
|
+
* Parses a text-encoded default value (proto2) of a BYTES field.
|
|
69
|
+
*/
|
|
70
|
+
function unescapeBytesDefaultValue(str) {
|
|
71
|
+
const b = [];
|
|
72
|
+
const input = {
|
|
73
|
+
tail: str,
|
|
74
|
+
c: "",
|
|
75
|
+
next() {
|
|
76
|
+
if (this.tail.length == 0) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
this.c = this.tail[0];
|
|
80
|
+
this.tail = this.tail.substring(1);
|
|
81
|
+
return true;
|
|
82
|
+
},
|
|
83
|
+
take(n) {
|
|
84
|
+
if (this.tail.length >= n) {
|
|
85
|
+
const r = this.tail.substring(0, n);
|
|
86
|
+
this.tail = this.tail.substring(n);
|
|
87
|
+
return r;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
while (input.next()) {
|
|
93
|
+
switch (input.c) {
|
|
94
|
+
case "\\":
|
|
95
|
+
if (input.next()) {
|
|
96
|
+
switch (input.c) {
|
|
97
|
+
case "\\":
|
|
98
|
+
b.push(input.c.charCodeAt(0));
|
|
99
|
+
break;
|
|
100
|
+
case "b":
|
|
101
|
+
b.push(0x08);
|
|
102
|
+
break;
|
|
103
|
+
case "f":
|
|
104
|
+
b.push(0x0c);
|
|
105
|
+
break;
|
|
106
|
+
case "n":
|
|
107
|
+
b.push(0x0a);
|
|
108
|
+
break;
|
|
109
|
+
case "r":
|
|
110
|
+
b.push(0x0d);
|
|
111
|
+
break;
|
|
112
|
+
case "t":
|
|
113
|
+
b.push(0x09);
|
|
114
|
+
break;
|
|
115
|
+
case "v":
|
|
116
|
+
b.push(0x0b);
|
|
117
|
+
break;
|
|
118
|
+
case "0":
|
|
119
|
+
case "1":
|
|
120
|
+
case "2":
|
|
121
|
+
case "3":
|
|
122
|
+
case "4":
|
|
123
|
+
case "5":
|
|
124
|
+
case "6":
|
|
125
|
+
case "7": {
|
|
126
|
+
const s = input.c;
|
|
127
|
+
const t = input.take(2);
|
|
128
|
+
if (t === false) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const n = parseInt(s + t, 8);
|
|
132
|
+
if (isNaN(n)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
b.push(n);
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case "x": {
|
|
139
|
+
const s = input.c;
|
|
140
|
+
const t = input.take(2);
|
|
141
|
+
if (t === false) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
const n = parseInt(s + t, 16);
|
|
145
|
+
if (isNaN(n)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
b.push(n);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case "u": {
|
|
152
|
+
const s = input.c;
|
|
153
|
+
const t = input.take(4);
|
|
154
|
+
if (t === false) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const n = parseInt(s + t, 16);
|
|
158
|
+
if (isNaN(n)) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
const chunk = new Uint8Array(4);
|
|
162
|
+
const view = new DataView(chunk.buffer);
|
|
163
|
+
view.setInt32(0, n, true);
|
|
164
|
+
b.push(chunk[0], chunk[1], chunk[2], chunk[3]);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case "U": {
|
|
168
|
+
const s = input.c;
|
|
169
|
+
const t = input.take(8);
|
|
170
|
+
if (t === false) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const tc = proto_int64_js_1.protoInt64.uEnc(s + t);
|
|
174
|
+
const chunk = new Uint8Array(8);
|
|
175
|
+
const view = new DataView(chunk.buffer);
|
|
176
|
+
view.setInt32(0, tc.lo, true);
|
|
177
|
+
view.setInt32(4, tc.hi, true);
|
|
178
|
+
b.push(chunk[0], chunk[1], chunk[2], chunk[3], chunk[4], chunk[5], chunk[6], chunk[7]);
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
b.push(input.c.charCodeAt(0));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return new Uint8Array(b);
|
|
189
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FileDescriptorProto, FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
|
|
1
|
+
import { FeatureSetDefaults, FileDescriptorProto, FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
|
|
3
2
|
import type { DescriptorSet } from "./descriptor-set.js";
|
|
4
3
|
/**
|
|
5
4
|
* Create a DescriptorSet, a convenient interface for working with a set of
|
|
@@ -9,8 +8,23 @@ import type { DescriptorSet } from "./descriptor-set.js";
|
|
|
9
8
|
* before any file that imports it. Protocol buffer compilers always produce
|
|
10
9
|
* files in topological order.
|
|
11
10
|
*/
|
|
12
|
-
export declare function createDescriptorSet(input: FileDescriptorProto[] | FileDescriptorSet | Uint8Array): DescriptorSet;
|
|
11
|
+
export declare function createDescriptorSet(input: FileDescriptorProto[] | FileDescriptorSet | Uint8Array, options?: CreateDescriptorSetOptions): DescriptorSet;
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Options to createDescriptorSet()
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
interface CreateDescriptorSetOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Editions support language-specific features with extensions to
|
|
18
|
+
* google.protobuf.FeatureSet. They can define defaults, and specify on
|
|
19
|
+
* which targets the features can be set.
|
|
20
|
+
*
|
|
21
|
+
* To create a DescriptorSet that provides your language-specific features,
|
|
22
|
+
* you have to provide a google.protobuf.FeatureSetDefaults message in this
|
|
23
|
+
* option.
|
|
24
|
+
*
|
|
25
|
+
* The defaults can be generated with `protoc` - see the flag
|
|
26
|
+
* `--experimental_edition_defaults_out`.
|
|
27
|
+
*/
|
|
28
|
+
featureSetDefaults?: FeatureSetDefaults;
|
|
29
|
+
}
|
|
30
|
+
export {};
|