protobufjs 8.2.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -75
- package/dist/light/protobuf.js +119 -55
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +61 -18
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +138 -60
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/descriptor/index.d.ts +2 -1
- package/ext/descriptor.d.ts +11 -234
- package/ext/descriptor.generated.d.ts +409 -0
- package/ext/descriptor.js +96 -66
- package/ext/textformat.d.ts +2 -13
- package/ext/textformat.generated.d.ts +11 -0
- package/ext/textformat.js +28 -42
- package/index.d.ts +304 -275
- package/package.json +4 -7
- package/src/converter.js +3 -3
- package/src/decoder.js +6 -2
- package/src/enum.js +8 -3
- package/src/field.js +2 -0
- package/src/message.js +3 -6
- package/src/method.js +1 -1
- package/src/namespace.js +10 -2
- package/src/object.js +0 -1
- package/src/oneof.js +1 -0
- package/src/parse.js +19 -5
- package/src/root.js +4 -1
- package/src/service.js +6 -1
- package/src/type.js +12 -3
- package/src/typescript.js +19 -0
- package/src/util/minimal.js +8 -1
- package/src/util/utf8.js +39 -13
- package/src/util.js +2 -14
- package/src/writer.js +6 -1
- package/src/writer_buffer.js +6 -1
- package/tsconfig.json +2 -4
- package/src/typescript.jsdoc +0 -15
package/ext/descriptor.js
CHANGED
|
@@ -221,9 +221,14 @@ var unnamedMessageIndex = 0;
|
|
|
221
221
|
* @param {IDescriptorProto|Reader|Uint8Array} descriptor Descriptor
|
|
222
222
|
* @param {string} [edition="proto2"] The syntax or edition to use
|
|
223
223
|
* @param {boolean} [nested=false] Whether or not this is a nested object
|
|
224
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
224
225
|
* @returns {Type} Type instance
|
|
225
226
|
*/
|
|
226
|
-
Type.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
227
|
+
Type.fromDescriptor = function fromDescriptor(descriptor, edition, nested, depth) {
|
|
228
|
+
if (depth === undefined)
|
|
229
|
+
depth = 0;
|
|
230
|
+
if (depth > $protobuf.util.nestingLimit)
|
|
231
|
+
throw Error("max depth exceeded");
|
|
227
232
|
descriptor = decodeDescriptor(descriptor, exports.DescriptorProto);
|
|
228
233
|
|
|
229
234
|
var type = new Type(descriptor.name.length ? descriptor.name : "Type" + unnamedMessageIndex++, fromDescriptorOptions(descriptor.options, exports.MessageOptions)),
|
|
@@ -255,7 +260,7 @@ Type.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
|
255
260
|
for (i = 0; i < descriptor.nestedType.length; ++i) {
|
|
256
261
|
if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry)
|
|
257
262
|
continue;
|
|
258
|
-
type.add(Type.fromDescriptor(descriptor.nestedType[i], edition, true));
|
|
263
|
+
type.add(Type.fromDescriptor(descriptor.nestedType[i], edition, true, depth + 1));
|
|
259
264
|
}
|
|
260
265
|
/* Nested enums */ if (descriptor.enumType)
|
|
261
266
|
for (i = 0; i < descriptor.enumType.length; ++i)
|
|
@@ -604,6 +609,16 @@ Field.prototype.toDescriptor = function toDescriptor(edition) {
|
|
|
604
609
|
* @property {IEnumValueOptions} [options] Enum value options
|
|
605
610
|
*/
|
|
606
611
|
|
|
612
|
+
/**
|
|
613
|
+
* Properties of an EnumValueOptions message.
|
|
614
|
+
* @interface IEnumValueOptions
|
|
615
|
+
* @property {boolean} [deprecated]
|
|
616
|
+
* @property {IFeatureSet} [features]
|
|
617
|
+
* @property {boolean} [debugRedact]
|
|
618
|
+
* @property {*} [featureSupport]
|
|
619
|
+
* @property {Array.<*>} [uninterpretedOption]
|
|
620
|
+
*/
|
|
621
|
+
|
|
607
622
|
/**
|
|
608
623
|
* Properties of an EnumOptions message.
|
|
609
624
|
* @interface IEnumOptions
|
|
@@ -611,6 +626,19 @@ Field.prototype.toDescriptor = function toDescriptor(edition) {
|
|
|
611
626
|
* @property {boolean} [deprecated]
|
|
612
627
|
*/
|
|
613
628
|
|
|
629
|
+
/**
|
|
630
|
+
* Properties of a FeatureSet message.
|
|
631
|
+
* @interface IFeatureSet
|
|
632
|
+
* @property {number} [fieldPresence]
|
|
633
|
+
* @property {number} [enumType]
|
|
634
|
+
* @property {number} [repeatedFieldEncoding]
|
|
635
|
+
* @property {number} [utf8Validation]
|
|
636
|
+
* @property {number} [messageEncoding]
|
|
637
|
+
* @property {number} [jsonFormat]
|
|
638
|
+
* @property {number} [enforceNamingStyle]
|
|
639
|
+
* @property {number} [defaultSymbolVisibility]
|
|
640
|
+
*/
|
|
641
|
+
|
|
614
642
|
var unnamedEnumIndex = 0;
|
|
615
643
|
|
|
616
644
|
/**
|
|
@@ -687,6 +715,13 @@ Enum.prototype.toDescriptor = function toDescriptor() {
|
|
|
687
715
|
* @property {IOneofOptions} [options] Oneof options
|
|
688
716
|
*/
|
|
689
717
|
|
|
718
|
+
/**
|
|
719
|
+
* Properties of a OneofOptions message.
|
|
720
|
+
* @interface IOneofOptions
|
|
721
|
+
* @property {IFeatureSet} [features]
|
|
722
|
+
* @property {Array.<*>} [uninterpretedOption]
|
|
723
|
+
*/
|
|
724
|
+
|
|
690
725
|
var unnamedOneofIndex = 0;
|
|
691
726
|
|
|
692
727
|
/**
|
|
@@ -1051,186 +1086,181 @@ function editionToDescriptor(edition, fileDescriptor) {
|
|
|
1051
1086
|
/**
|
|
1052
1087
|
* Reflected file descriptor set.
|
|
1053
1088
|
* @name FileDescriptorSet
|
|
1054
|
-
* @type {Type}
|
|
1089
|
+
* @type {$protobuf.Type}
|
|
1055
1090
|
* @const
|
|
1056
|
-
* @tstype $protobuf.Type
|
|
1057
1091
|
*/
|
|
1058
1092
|
|
|
1059
1093
|
/**
|
|
1060
1094
|
* Reflected file descriptor proto.
|
|
1061
1095
|
* @name FileDescriptorProto
|
|
1062
|
-
* @type {Type}
|
|
1096
|
+
* @type {$protobuf.Type}
|
|
1063
1097
|
* @const
|
|
1064
|
-
* @tstype $protobuf.Type
|
|
1065
1098
|
*/
|
|
1066
1099
|
|
|
1067
1100
|
/**
|
|
1068
1101
|
* Reflected descriptor proto.
|
|
1069
1102
|
* @name DescriptorProto
|
|
1070
|
-
* @type {Type
|
|
1071
|
-
* @property {Type} ExtensionRange
|
|
1072
|
-
* @property {Type} ReservedRange
|
|
1073
|
-
* @const
|
|
1074
|
-
* @tstype $protobuf.Type & {
|
|
1103
|
+
* @type {$protobuf.Type & {
|
|
1075
1104
|
* ExtensionRange: $protobuf.Type,
|
|
1076
1105
|
* ReservedRange: $protobuf.Type
|
|
1077
|
-
* }
|
|
1106
|
+
* }}
|
|
1107
|
+
* @const
|
|
1078
1108
|
*/
|
|
1079
1109
|
|
|
1080
1110
|
/**
|
|
1081
1111
|
* Reflected field descriptor proto.
|
|
1082
1112
|
* @name FieldDescriptorProto
|
|
1083
|
-
* @type {Type
|
|
1084
|
-
* @property {Enum} Label
|
|
1085
|
-
* @property {Enum} Type
|
|
1086
|
-
* @const
|
|
1087
|
-
* @tstype $protobuf.Type & {
|
|
1113
|
+
* @type {$protobuf.Type & {
|
|
1088
1114
|
* Label: $protobuf.Enum,
|
|
1089
1115
|
* Type: $protobuf.Enum
|
|
1090
|
-
* }
|
|
1116
|
+
* }}
|
|
1117
|
+
* @const
|
|
1091
1118
|
*/
|
|
1092
1119
|
|
|
1093
1120
|
/**
|
|
1094
1121
|
* Reflected oneof descriptor proto.
|
|
1095
1122
|
* @name OneofDescriptorProto
|
|
1096
|
-
* @type {Type}
|
|
1123
|
+
* @type {$protobuf.Type}
|
|
1097
1124
|
* @const
|
|
1098
|
-
* @tstype $protobuf.Type
|
|
1099
1125
|
*/
|
|
1100
1126
|
|
|
1101
1127
|
/**
|
|
1102
1128
|
* Reflected enum descriptor proto.
|
|
1103
1129
|
* @name EnumDescriptorProto
|
|
1104
|
-
* @type {Type}
|
|
1130
|
+
* @type {$protobuf.Type}
|
|
1105
1131
|
* @const
|
|
1106
|
-
* @tstype $protobuf.Type
|
|
1107
1132
|
*/
|
|
1108
1133
|
|
|
1109
1134
|
/**
|
|
1110
1135
|
* Reflected service descriptor proto.
|
|
1111
1136
|
* @name ServiceDescriptorProto
|
|
1112
|
-
* @type {Type}
|
|
1137
|
+
* @type {$protobuf.Type}
|
|
1113
1138
|
* @const
|
|
1114
|
-
* @tstype $protobuf.Type
|
|
1115
1139
|
*/
|
|
1116
1140
|
|
|
1117
1141
|
/**
|
|
1118
1142
|
* Reflected enum value descriptor proto.
|
|
1119
1143
|
* @name EnumValueDescriptorProto
|
|
1120
|
-
* @type {Type}
|
|
1144
|
+
* @type {$protobuf.Type}
|
|
1121
1145
|
* @const
|
|
1122
|
-
* @tstype $protobuf.Type
|
|
1123
1146
|
*/
|
|
1124
1147
|
|
|
1125
1148
|
/**
|
|
1126
1149
|
* Reflected method descriptor proto.
|
|
1127
1150
|
* @name MethodDescriptorProto
|
|
1128
|
-
* @type {Type}
|
|
1151
|
+
* @type {$protobuf.Type}
|
|
1129
1152
|
* @const
|
|
1130
|
-
* @tstype $protobuf.Type
|
|
1131
1153
|
*/
|
|
1132
1154
|
|
|
1133
1155
|
/**
|
|
1134
1156
|
* Reflected file options.
|
|
1135
1157
|
* @name FileOptions
|
|
1136
|
-
* @type {Type
|
|
1137
|
-
* @property {Enum} OptimizeMode
|
|
1138
|
-
* @const
|
|
1139
|
-
* @tstype $protobuf.Type & {
|
|
1158
|
+
* @type {$protobuf.Type & {
|
|
1140
1159
|
* OptimizeMode: $protobuf.Enum
|
|
1141
|
-
* }
|
|
1160
|
+
* }}
|
|
1161
|
+
* @const
|
|
1142
1162
|
*/
|
|
1143
1163
|
|
|
1144
1164
|
/**
|
|
1145
1165
|
* Reflected message options.
|
|
1146
1166
|
* @name MessageOptions
|
|
1147
|
-
* @type {Type}
|
|
1167
|
+
* @type {$protobuf.Type}
|
|
1148
1168
|
* @const
|
|
1149
|
-
* @tstype $protobuf.Type
|
|
1150
1169
|
*/
|
|
1151
1170
|
|
|
1152
1171
|
/**
|
|
1153
1172
|
* Reflected field options.
|
|
1154
1173
|
* @name FieldOptions
|
|
1155
|
-
* @type {Type
|
|
1156
|
-
* @property {Enum} CType
|
|
1157
|
-
* @property {Enum} JSType
|
|
1158
|
-
* @const
|
|
1159
|
-
* @tstype $protobuf.Type & {
|
|
1174
|
+
* @type {$protobuf.Type & {
|
|
1160
1175
|
* CType: $protobuf.Enum,
|
|
1161
1176
|
* JSType: $protobuf.Enum
|
|
1162
|
-
* }
|
|
1177
|
+
* }}
|
|
1178
|
+
* @const
|
|
1163
1179
|
*/
|
|
1164
1180
|
|
|
1165
1181
|
/**
|
|
1166
1182
|
* Reflected oneof options.
|
|
1167
1183
|
* @name OneofOptions
|
|
1168
|
-
* @type {Type}
|
|
1184
|
+
* @type {$protobuf.Type}
|
|
1169
1185
|
* @const
|
|
1170
|
-
* @tstype $protobuf.Type
|
|
1171
1186
|
*/
|
|
1172
1187
|
|
|
1173
1188
|
/**
|
|
1174
1189
|
* Reflected enum options.
|
|
1175
1190
|
* @name EnumOptions
|
|
1176
|
-
* @type {Type}
|
|
1191
|
+
* @type {$protobuf.Type}
|
|
1177
1192
|
* @const
|
|
1178
|
-
* @tstype $protobuf.Type
|
|
1179
1193
|
*/
|
|
1180
1194
|
|
|
1181
1195
|
/**
|
|
1182
1196
|
* Reflected enum value options.
|
|
1183
1197
|
* @name EnumValueOptions
|
|
1184
|
-
* @type {Type}
|
|
1198
|
+
* @type {$protobuf.Type}
|
|
1185
1199
|
* @const
|
|
1186
|
-
* @tstype $protobuf.Type
|
|
1187
1200
|
*/
|
|
1188
1201
|
|
|
1189
1202
|
/**
|
|
1190
1203
|
* Reflected service options.
|
|
1191
1204
|
* @name ServiceOptions
|
|
1192
|
-
* @type {Type}
|
|
1205
|
+
* @type {$protobuf.Type}
|
|
1193
1206
|
* @const
|
|
1194
|
-
* @tstype $protobuf.Type
|
|
1195
1207
|
*/
|
|
1196
1208
|
|
|
1197
1209
|
/**
|
|
1198
1210
|
* Reflected method options.
|
|
1199
1211
|
* @name MethodOptions
|
|
1200
|
-
* @type {Type}
|
|
1212
|
+
* @type {$protobuf.Type}
|
|
1213
|
+
* @const
|
|
1214
|
+
*/
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* Reflected feature set.
|
|
1218
|
+
* @name FeatureSet
|
|
1219
|
+
* @type {$protobuf.Type & {
|
|
1220
|
+
* FieldPresence: $protobuf.Enum,
|
|
1221
|
+
* EnumType: $protobuf.Enum,
|
|
1222
|
+
* RepeatedFieldEncoding: $protobuf.Enum,
|
|
1223
|
+
* Utf8Validation: $protobuf.Enum,
|
|
1224
|
+
* MessageEncoding: $protobuf.Enum,
|
|
1225
|
+
* JsonFormat: $protobuf.Enum,
|
|
1226
|
+
* EnforceNamingStyle: $protobuf.Enum,
|
|
1227
|
+
* VisibilityFeature: $protobuf.Type
|
|
1228
|
+
* }}
|
|
1229
|
+
* @const
|
|
1230
|
+
*/
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* Reflected feature set defaults.
|
|
1234
|
+
* @name FeatureSetDefaults
|
|
1235
|
+
* @type {$protobuf.Type & {
|
|
1236
|
+
* FeatureSetEditionDefault: $protobuf.Type
|
|
1237
|
+
* }}
|
|
1201
1238
|
* @const
|
|
1202
|
-
* @tstype $protobuf.Type
|
|
1203
1239
|
*/
|
|
1204
1240
|
|
|
1205
1241
|
/**
|
|
1206
1242
|
* Reflected uninterpretet option.
|
|
1207
1243
|
* @name UninterpretedOption
|
|
1208
|
-
* @type {Type
|
|
1209
|
-
* @property {Type} NamePart
|
|
1210
|
-
* @const
|
|
1211
|
-
* @tstype $protobuf.Type & {
|
|
1244
|
+
* @type {$protobuf.Type & {
|
|
1212
1245
|
* NamePart: $protobuf.Type
|
|
1213
|
-
* }
|
|
1246
|
+
* }}
|
|
1247
|
+
* @const
|
|
1214
1248
|
*/
|
|
1215
1249
|
|
|
1216
1250
|
/**
|
|
1217
1251
|
* Reflected source code info.
|
|
1218
1252
|
* @name SourceCodeInfo
|
|
1219
|
-
* @type {Type
|
|
1220
|
-
* @property {Type} Location
|
|
1221
|
-
* @const
|
|
1222
|
-
* @tstype $protobuf.Type & {
|
|
1253
|
+
* @type {$protobuf.Type & {
|
|
1223
1254
|
* Location: $protobuf.Type
|
|
1224
|
-
* }
|
|
1255
|
+
* }}
|
|
1256
|
+
* @const
|
|
1225
1257
|
*/
|
|
1226
1258
|
|
|
1227
1259
|
/**
|
|
1228
1260
|
* Reflected generated code info.
|
|
1229
1261
|
* @name GeneratedCodeInfo
|
|
1230
|
-
* @type {Type
|
|
1231
|
-
* @property {Type} Annotation
|
|
1232
|
-
* @const
|
|
1233
|
-
* @tstype $protobuf.Type & {
|
|
1262
|
+
* @type {$protobuf.Type & {
|
|
1234
1263
|
* Annotation: $protobuf.Type
|
|
1235
|
-
* }
|
|
1264
|
+
* }}
|
|
1265
|
+
* @const
|
|
1236
1266
|
*/
|
package/ext/textformat.d.ts
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import * as $protobuf from "..";
|
|
2
|
+
import { ITextFormatOptions } from "./textformat.generated";
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
/** Also includes and formats unknown fields. */
|
|
5
|
-
unknowns?: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/** Maximum recursion depth for text format parsing and formatting. Defaults to util.recursionLimit. */
|
|
9
|
-
export let recursionLimit: number;
|
|
10
|
-
|
|
11
|
-
/** Maximum recursion depth for formatting length-delimited unknown fields. */
|
|
12
|
-
export let unknownRecursionLimit: number;
|
|
4
|
+
export * from "./textformat.generated";
|
|
13
5
|
|
|
14
6
|
declare module ".." {
|
|
15
7
|
namespace textformat {
|
|
16
|
-
/** Maximum recursion depth for text format parsing and formatting. Defaults to util.recursionLimit. */
|
|
17
|
-
let recursionLimit: number;
|
|
18
|
-
|
|
19
8
|
/** Maximum recursion depth for formatting length-delimited unknown fields. */
|
|
20
9
|
let unknownRecursionLimit: number;
|
|
21
10
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// DO NOT EDIT! This is a generated file. Edit the source file instead and regenerate.
|
|
2
|
+
|
|
3
|
+
/** Maximum recursion depth for formatting length-delimited unknown fields. */
|
|
4
|
+
export let unknownRecursionLimit: number;
|
|
5
|
+
|
|
6
|
+
/** Text format options. */
|
|
7
|
+
export interface ITextFormatOptions {
|
|
8
|
+
|
|
9
|
+
/** Also includes and formats unknown fields. */
|
|
10
|
+
unknowns?: boolean;
|
|
11
|
+
}
|
package/ext/textformat.js
CHANGED
|
@@ -10,23 +10,9 @@ var Type = protobuf.Type,
|
|
|
10
10
|
|
|
11
11
|
var textformat = protobuf.textformat = module.exports = {};
|
|
12
12
|
|
|
13
|
-
var recursionLimit;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Maximum recursion depth for text format parsing and formatting. Defaults to util.recursionLimit.
|
|
17
|
-
* @type {number}
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(textformat, "recursionLimit", {
|
|
20
|
-
get: function get() {
|
|
21
|
-
return recursionLimit === undefined ? util.recursionLimit : recursionLimit;
|
|
22
|
-
},
|
|
23
|
-
set: function set(value) {
|
|
24
|
-
recursionLimit = value == null ? undefined : value;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
13
|
/**
|
|
29
14
|
* Maximum recursion depth for formatting length-delimited unknown fields.
|
|
15
|
+
* @name unknownRecursionLimit
|
|
30
16
|
* @type {number}
|
|
31
17
|
*/
|
|
32
18
|
textformat.unknownRecursionLimit = 10;
|
|
@@ -59,6 +45,7 @@ var identRe = /^[A-Za-z_][A-Za-z0-9_]*$/,
|
|
|
59
45
|
* @param {Type} type Reflected message type
|
|
60
46
|
* @param {string} text Text format input
|
|
61
47
|
* @returns {Message<{}>} Message instance
|
|
48
|
+
* @private
|
|
62
49
|
*/
|
|
63
50
|
function parseText(type, text) {
|
|
64
51
|
if (!(type instanceof Type))
|
|
@@ -75,20 +62,26 @@ function parseText(type, text) {
|
|
|
75
62
|
return message;
|
|
76
63
|
}
|
|
77
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Text format options.
|
|
67
|
+
* @interface ITextFormatOptions
|
|
68
|
+
* @property {boolean} [unknowns=false] Also includes and formats unknown fields.
|
|
69
|
+
*/
|
|
70
|
+
|
|
78
71
|
/**
|
|
79
72
|
* Formats a message as protobuf text format using the specified reflected type.
|
|
80
73
|
* @param {Type} type Reflected message type
|
|
81
74
|
* @param {Message<{}>|Object.<string,*>} message Message instance or plain object
|
|
82
|
-
* @param {
|
|
83
|
-
* @param {boolean} [options.unknowns=false] Includes and formats unknown fields
|
|
75
|
+
* @param {ITextFormatOptions} [options] Text format options
|
|
84
76
|
* @returns {string} Text format output
|
|
77
|
+
* @private
|
|
85
78
|
*/
|
|
86
79
|
function formatText(type, message, options) {
|
|
87
80
|
if (!(type instanceof Type))
|
|
88
81
|
throw TypeError("type must be a Type");
|
|
89
82
|
type.root.resolveAll();
|
|
90
83
|
var lines = [];
|
|
91
|
-
writeMessage(type, message, lines, 0, options || {}, 0
|
|
84
|
+
writeMessage(type, message, lines, 0, options || {}, 0);
|
|
92
85
|
return lines.join("\n");
|
|
93
86
|
}
|
|
94
87
|
|
|
@@ -104,7 +97,7 @@ Type.prototype.fromText = function fromText(text) {
|
|
|
104
97
|
/**
|
|
105
98
|
* Formats a message of this type as protobuf text format.
|
|
106
99
|
* @param {Message<{}>|Object.<string,*>} message Message instance or plain object
|
|
107
|
-
* @param {
|
|
100
|
+
* @param {ITextFormatOptions} [options] Text format options
|
|
108
101
|
* @returns {string} Text format output
|
|
109
102
|
*/
|
|
110
103
|
Type.prototype.toText = function toText(message, options) {
|
|
@@ -318,7 +311,6 @@ Tokenizer.prototype.readCodePoint = function readCodePoint(size) {
|
|
|
318
311
|
|
|
319
312
|
function Parser(source) {
|
|
320
313
|
this.tn = new Tokenizer(source);
|
|
321
|
-
this.recursionLimit = textformat.recursionLimit;
|
|
322
314
|
}
|
|
323
315
|
|
|
324
316
|
Parser.prototype.error = function error(message) {
|
|
@@ -331,13 +323,9 @@ Parser.prototype.expectEnd = function expectEnd() {
|
|
|
331
323
|
this.error("unexpected token '" + token.value + "'");
|
|
332
324
|
};
|
|
333
325
|
|
|
334
|
-
Parser.prototype.checkRecursion = function checkRecursion(depth) {
|
|
335
|
-
if (depth > this.recursionLimit)
|
|
336
|
-
this.error("max depth exceeded");
|
|
337
|
-
};
|
|
338
|
-
|
|
339
326
|
Parser.prototype.parseMessage = function parseMessage(type, end, depth) {
|
|
340
|
-
|
|
327
|
+
if (depth > util.recursionLimit)
|
|
328
|
+
this.error("max depth exceeded");
|
|
341
329
|
var object = {},
|
|
342
330
|
seen = {};
|
|
343
331
|
for (;;) {
|
|
@@ -473,7 +461,8 @@ Parser.prototype.parseMessageFieldDelimiter = function parseMessageFieldDelimite
|
|
|
473
461
|
};
|
|
474
462
|
|
|
475
463
|
Parser.prototype.parseMapEntry = function parseMapEntry(field, depth) {
|
|
476
|
-
|
|
464
|
+
if (depth > util.recursionLimit)
|
|
465
|
+
this.error("max depth exceeded");
|
|
477
466
|
var end;
|
|
478
467
|
if (this.tn.skip("{"))
|
|
479
468
|
end = "}";
|
|
@@ -617,7 +606,7 @@ Parser.prototype.skipBalanced = function skipBalanced(open, close, depth) {
|
|
|
617
606
|
if (!token)
|
|
618
607
|
this.error("expected '" + close + "'");
|
|
619
608
|
if (token.value === open) {
|
|
620
|
-
if (depth + ++balance >
|
|
609
|
+
if (depth + ++balance > util.recursionLimit)
|
|
621
610
|
this.error("max depth exceeded");
|
|
622
611
|
}
|
|
623
612
|
else if (token.value === close)
|
|
@@ -855,13 +844,9 @@ function parseIntegerBigInt(digits, radix, sign, unsigned, bits) {
|
|
|
855
844
|
return Number(value);
|
|
856
845
|
}
|
|
857
846
|
|
|
858
|
-
function
|
|
859
|
-
if (depth > recursionLimit)
|
|
847
|
+
function writeMessage(type, message, lines, indent, options, depth) {
|
|
848
|
+
if (depth > util.recursionLimit)
|
|
860
849
|
throw Error("max depth exceeded");
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
function writeMessage(type, message, lines, indent, options, depth, recursionLimit) {
|
|
864
|
-
checkRecursion(depth, recursionLimit);
|
|
865
850
|
var fields = type.fieldsArray.slice().sort(util.compareFieldsById);
|
|
866
851
|
for (var i = 0; i < fields.length; ++i) {
|
|
867
852
|
var field = fields[i].resolve(),
|
|
@@ -869,25 +854,26 @@ function writeMessage(type, message, lines, indent, options, depth, recursionLim
|
|
|
869
854
|
if (value == null || !Object.prototype.hasOwnProperty.call(message, field.name))
|
|
870
855
|
continue;
|
|
871
856
|
if (field.map)
|
|
872
|
-
writeMapField(field, value, lines, indent, options, depth
|
|
857
|
+
writeMapField(field, value, lines, indent, options, depth);
|
|
873
858
|
else if (field.repeated)
|
|
874
859
|
for (var j = 0; j < value.length; ++j)
|
|
875
|
-
writeField(field, value[j], lines, indent, options, depth
|
|
860
|
+
writeField(field, value[j], lines, indent, options, depth);
|
|
876
861
|
else
|
|
877
|
-
writeField(field, value, lines, indent, options, depth
|
|
862
|
+
writeField(field, value, lines, indent, options, depth);
|
|
878
863
|
}
|
|
879
864
|
if (options.unknowns && message.$unknowns != null && Object.prototype.hasOwnProperty.call(message, "$unknowns"))
|
|
880
865
|
writeUnknowns(message.$unknowns, lines, indent);
|
|
881
866
|
}
|
|
882
867
|
|
|
883
|
-
function writeMapField(field, map, lines, indent, options, depth
|
|
868
|
+
function writeMapField(field, map, lines, indent, options, depth) {
|
|
884
869
|
var keys = Object.keys(map).sort(),
|
|
885
870
|
keyField = mapKeyField(field),
|
|
886
871
|
valueField = mapValueField(field),
|
|
887
872
|
name = formatFieldName(field),
|
|
888
873
|
sp = spaces(indent);
|
|
889
874
|
for (var i = 0; i < keys.length; ++i) {
|
|
890
|
-
|
|
875
|
+
if (depth + 1 > util.recursionLimit)
|
|
876
|
+
throw Error("max depth exceeded");
|
|
891
877
|
var key = keyField.long ? util.longFromKey(keys[i], keyField.type === "uint64" || keyField.type === "fixed64") : keys[i];
|
|
892
878
|
if (keyField.type === "bool")
|
|
893
879
|
key = util.boolFromKey(keys[i]);
|
|
@@ -895,7 +881,7 @@ function writeMapField(field, map, lines, indent, options, depth, recursionLimit
|
|
|
895
881
|
lines.push(spaces(indent + 2) + "key: " + formatScalar(keyField, key));
|
|
896
882
|
if (valueField.resolvedType instanceof Type) {
|
|
897
883
|
lines.push(spaces(indent + 2) + "value {");
|
|
898
|
-
writeMessage(valueField.resolvedType, map[keys[i]], lines, indent + 4, options, depth + 2
|
|
884
|
+
writeMessage(valueField.resolvedType, map[keys[i]], lines, indent + 4, options, depth + 2);
|
|
899
885
|
lines.push(spaces(indent + 2) + "}");
|
|
900
886
|
} else
|
|
901
887
|
lines.push(spaces(indent + 2) + "value: " + formatScalar(valueField, map[keys[i]]));
|
|
@@ -903,12 +889,12 @@ function writeMapField(field, map, lines, indent, options, depth, recursionLimit
|
|
|
903
889
|
}
|
|
904
890
|
}
|
|
905
891
|
|
|
906
|
-
function writeField(field, value, lines, indent, options, depth
|
|
892
|
+
function writeField(field, value, lines, indent, options, depth) {
|
|
907
893
|
var name = formatFieldName(field),
|
|
908
894
|
sp = spaces(indent);
|
|
909
895
|
if (field.resolvedType instanceof Type) {
|
|
910
896
|
lines.push(sp + name + " {");
|
|
911
|
-
writeMessage(field.resolvedType, value, lines, indent + 2, options, depth + 1
|
|
897
|
+
writeMessage(field.resolvedType, value, lines, indent + 2, options, depth + 1);
|
|
912
898
|
lines.push(sp + "}");
|
|
913
899
|
} else
|
|
914
900
|
lines.push(sp + name + ": " + formatScalar(field, value));
|