@aptre/protobuf-es-lite 0.2.10 → 0.2.11
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/bin/protoc-gen-es-lite +2 -2
- package/dist/assert.js +4 -11
- package/dist/binary-encoding.js +30 -35
- package/dist/binary.js +84 -96
- package/dist/codegen-info.js +12 -15
- package/dist/create-descriptor-set.js +113 -117
- package/dist/descriptor-set.js +1 -2
- package/dist/enum.js +2 -7
- package/dist/feature-set.js +16 -20
- package/dist/field-wrapper.js +12 -17
- package/dist/field.js +18 -27
- package/dist/google/index.js +9 -41
- package/dist/google/protobuf/any.pb.d.ts +2 -2
- package/dist/google/protobuf/any.pb.js +3 -6
- package/dist/google/protobuf/api.pb.d.ts +2 -2
- package/dist/google/protobuf/api.pb.js +14 -17
- package/dist/google/protobuf/compiler/plugin.pb.d.ts +2 -2
- package/dist/google/protobuf/compiler/plugin.pb.js +15 -18
- package/dist/google/protobuf/descriptor.pb.d.ts +19 -19
- package/dist/google/protobuf/descriptor.pb.js +156 -160
- package/dist/google/protobuf/duration.pb.d.ts +2 -2
- package/dist/google/protobuf/duration.pb.js +3 -6
- package/dist/google/protobuf/empty.pb.d.ts +2 -2
- package/dist/google/protobuf/empty.pb.js +3 -6
- package/dist/google/protobuf/source_context.pb.d.ts +2 -2
- package/dist/google/protobuf/source_context.pb.js +3 -6
- package/dist/google/protobuf/struct.pb.d.ts +3 -3
- package/dist/google/protobuf/struct.pb.js +13 -16
- package/dist/google/protobuf/timestamp.pb.d.ts +2 -2
- package/dist/google/protobuf/timestamp.pb.js +3 -6
- package/dist/google/protobuf/type.pb.d.ts +5 -5
- package/dist/google/protobuf/type.pb.js +31 -34
- package/dist/google/protobuf/wrappers.pb.d.ts +2 -2
- package/dist/google/protobuf/wrappers.pb.js +11 -14
- package/dist/index.js +12 -60
- package/dist/is-message.js +9 -16
- package/dist/json.js +72 -80
- package/dist/message.js +48 -55
- package/dist/names.js +12 -23
- package/dist/partial.js +13 -17
- package/dist/proto-base64.js +1 -4
- package/dist/proto-double.js +1 -4
- package/dist/proto-int64.js +9 -12
- package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js +4 -7
- package/dist/protoc-gen-es-lite/typescript.js +27 -36
- package/dist/protoplugin/create-es-plugin.js +13 -17
- package/dist/protoplugin/ecmascript/file-preamble.js +5 -9
- package/dist/protoplugin/ecmascript/generated-file.js +16 -20
- package/dist/protoplugin/ecmascript/import-path.js +13 -20
- package/dist/protoplugin/ecmascript/import-symbol.js +1 -5
- package/dist/protoplugin/ecmascript/index.js +2 -7
- package/dist/protoplugin/ecmascript/jsdoc.js +1 -5
- package/dist/protoplugin/ecmascript/opaque-printables.js +1 -2
- package/dist/protoplugin/ecmascript/parameter.js +10 -14
- package/dist/protoplugin/ecmascript/reify-wkt.js +12 -16
- package/dist/protoplugin/ecmascript/runtime-imports.js +5 -9
- package/dist/protoplugin/ecmascript/schema.js +16 -20
- package/dist/protoplugin/ecmascript/target.js +1 -2
- package/dist/protoplugin/ecmascript/transpile.js +15 -42
- package/dist/protoplugin/error.js +3 -9
- package/dist/protoplugin/index.js +2 -7
- package/dist/protoplugin/plugin.js +1 -2
- package/dist/protoplugin/run-node.js +6 -10
- package/dist/scalar.js +9 -15
- package/dist/service-type.js +4 -7
- package/dist/text-format.js +25 -30
- package/dist/type-registry.js +1 -2
- package/dist/unknown.js +7 -12
- package/dist/util.d.ts +1 -1
- package/dist/util.js +49 -55
- package/dist/varint.js +7 -17
- package/package.json +10 -7
- package/tsconfig.base.json +2 -2
package/dist/is-message.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCompleteField = exports.isCompleteMessage = exports.isField = exports.isMessage = void 0;
|
|
4
|
-
const field_js_1 = require("./field.js");
|
|
1
|
+
import { resolveMessageType } from "./field.js";
|
|
5
2
|
/**
|
|
6
3
|
* Check whether the given partial is a valid message.
|
|
7
4
|
*/
|
|
8
|
-
function isMessage(arg, fields) {
|
|
5
|
+
export function isMessage(arg, fields) {
|
|
9
6
|
if (arg == null || typeof arg !== "object") {
|
|
10
7
|
return false;
|
|
11
8
|
}
|
|
@@ -24,11 +21,10 @@ function isMessage(arg, fields) {
|
|
|
24
21
|
}
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
|
-
exports.isMessage = isMessage;
|
|
28
24
|
/**
|
|
29
25
|
* Check whether the given partial field is a valid field value.
|
|
30
26
|
*/
|
|
31
|
-
function isField(value, field) {
|
|
27
|
+
export function isField(value, field) {
|
|
32
28
|
if (value == null) {
|
|
33
29
|
return false;
|
|
34
30
|
}
|
|
@@ -46,7 +42,7 @@ function isField(value, field) {
|
|
|
46
42
|
case "scalar":
|
|
47
43
|
return true;
|
|
48
44
|
case "message":
|
|
49
|
-
const messageType =
|
|
45
|
+
const messageType = resolveMessageType(field.T);
|
|
50
46
|
return isMessage(value, messageType.fields.list());
|
|
51
47
|
case "enum":
|
|
52
48
|
return typeof value === "number";
|
|
@@ -59,7 +55,7 @@ function isField(value, field) {
|
|
|
59
55
|
case "enum":
|
|
60
56
|
return typeof val === "number";
|
|
61
57
|
case "message":
|
|
62
|
-
const messageType =
|
|
58
|
+
const messageType = resolveMessageType(field.V.T);
|
|
63
59
|
return isMessage(val, messageType.fields.list());
|
|
64
60
|
default:
|
|
65
61
|
return valueKind;
|
|
@@ -69,11 +65,10 @@ function isField(value, field) {
|
|
|
69
65
|
return fieldKind;
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
|
-
exports.isField = isField;
|
|
73
68
|
/**
|
|
74
69
|
* Check whether the given partial has all fields present recursively.
|
|
75
70
|
*/
|
|
76
|
-
function isCompleteMessage(arg, fields) {
|
|
71
|
+
export function isCompleteMessage(arg, fields) {
|
|
77
72
|
// arg is CompleteMessage<T> {
|
|
78
73
|
if (arg == null || typeof arg !== "object") {
|
|
79
74
|
return false;
|
|
@@ -89,11 +84,10 @@ function isCompleteMessage(arg, fields) {
|
|
|
89
84
|
}
|
|
90
85
|
});
|
|
91
86
|
}
|
|
92
|
-
exports.isCompleteMessage = isCompleteMessage;
|
|
93
87
|
/**
|
|
94
88
|
* Check whether the given partial field has a full value present recursively.
|
|
95
89
|
*/
|
|
96
|
-
function isCompleteField(value, field) {
|
|
90
|
+
export function isCompleteField(value, field) {
|
|
97
91
|
// value is CompleteField<F> {
|
|
98
92
|
if (field.oneof) {
|
|
99
93
|
// For oneof fields, only one field should be set
|
|
@@ -109,7 +103,7 @@ function isCompleteField(value, field) {
|
|
|
109
103
|
case "scalar":
|
|
110
104
|
return true;
|
|
111
105
|
case "message":
|
|
112
|
-
const messageType =
|
|
106
|
+
const messageType = resolveMessageType(field.T);
|
|
113
107
|
return isCompleteMessage(value, messageType.fields.list());
|
|
114
108
|
case "enum":
|
|
115
109
|
return typeof value === "number";
|
|
@@ -122,7 +116,7 @@ function isCompleteField(value, field) {
|
|
|
122
116
|
case "enum":
|
|
123
117
|
return typeof val === "number";
|
|
124
118
|
case "message":
|
|
125
|
-
const messageType =
|
|
119
|
+
const messageType = resolveMessageType(field.V.T);
|
|
126
120
|
return isCompleteMessage(val, messageType.fields.list());
|
|
127
121
|
default:
|
|
128
122
|
return valueKind;
|
|
@@ -132,4 +126,3 @@ function isCompleteField(value, field) {
|
|
|
132
126
|
return fieldKind;
|
|
133
127
|
}
|
|
134
128
|
}
|
|
135
|
-
exports.isCompleteField = isCompleteField;
|
package/dist/json.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const field_wrapper_js_1 = require("./field-wrapper.js");
|
|
8
|
-
const proto_int64_js_1 = require("./proto-int64.js");
|
|
9
|
-
const proto_base64_js_1 = require("./proto-base64.js");
|
|
1
|
+
import { isFieldSet, resolveMessageType, } from "./field.js";
|
|
2
|
+
import { assert, assertFloat32, assertInt32, assertUInt32 } from "./assert.js";
|
|
3
|
+
import { LongType, ScalarType, scalarZeroValue, } from "./scalar.js";
|
|
4
|
+
import { wrapField } from "./field-wrapper.js";
|
|
5
|
+
import { protoInt64 } from "./proto-int64.js";
|
|
6
|
+
import { protoBase64 } from "./proto-base64.js";
|
|
10
7
|
// Default options for parsing JSON.
|
|
11
8
|
const jsonReadDefaults = {
|
|
12
9
|
ignoreUnknownFields: false,
|
|
@@ -18,14 +15,12 @@ const jsonWriteDefaults = {
|
|
|
18
15
|
useProtoFieldName: false,
|
|
19
16
|
prettySpaces: 0,
|
|
20
17
|
};
|
|
21
|
-
function makeReadOptions(options) {
|
|
18
|
+
export function makeReadOptions(options) {
|
|
22
19
|
return options ? { ...jsonReadDefaults, ...options } : jsonReadDefaults;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
function makeWriteOptions(options) {
|
|
21
|
+
export function makeWriteOptions(options) {
|
|
26
22
|
return options ? { ...jsonWriteDefaults, ...options } : jsonWriteDefaults;
|
|
27
23
|
}
|
|
28
|
-
exports.makeWriteOptions = makeWriteOptions;
|
|
29
24
|
function debugJsonValue(json) {
|
|
30
25
|
if (json === null) {
|
|
31
26
|
return "null";
|
|
@@ -39,7 +34,7 @@ function debugJsonValue(json) {
|
|
|
39
34
|
return String(json);
|
|
40
35
|
}
|
|
41
36
|
}
|
|
42
|
-
function readMessage(fields, typeName, json, options, message) {
|
|
37
|
+
export function readMessage(fields, typeName, json, options, message) {
|
|
43
38
|
if (json == null || Array.isArray(json) || typeof json != "object") {
|
|
44
39
|
throw new Error(`cannot decode message ${typeName} from JSON: ${debugJsonValue(json)}`);
|
|
45
40
|
}
|
|
@@ -69,13 +64,12 @@ function readMessage(fields, typeName, json, options, message) {
|
|
|
69
64
|
}
|
|
70
65
|
return message;
|
|
71
66
|
}
|
|
72
|
-
|
|
73
|
-
function writeMessage(message, fields, options) {
|
|
67
|
+
export function writeMessage(message, fields, options) {
|
|
74
68
|
const json = {};
|
|
75
69
|
let field;
|
|
76
70
|
try {
|
|
77
71
|
for (field of fields.byNumber()) {
|
|
78
|
-
if (!
|
|
72
|
+
if (!isFieldSet(field, message)) {
|
|
79
73
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
80
74
|
if (field.req) {
|
|
81
75
|
throw `required field not set`;
|
|
@@ -128,13 +122,12 @@ function writeMessage(message, fields, options) {
|
|
|
128
122
|
}
|
|
129
123
|
return json;
|
|
130
124
|
}
|
|
131
|
-
exports.writeMessage = writeMessage;
|
|
132
125
|
// Read a JSON value for a field.
|
|
133
126
|
// The "parentType" argument is only used to provide context in errors.
|
|
134
127
|
function readField(target, jsonValue, field, options) {
|
|
135
128
|
let localName = field.localName;
|
|
136
129
|
if (field.repeated) {
|
|
137
|
-
|
|
130
|
+
assert(field.kind != "map");
|
|
138
131
|
if (jsonValue === null) {
|
|
139
132
|
return;
|
|
140
133
|
}
|
|
@@ -151,7 +144,7 @@ function readField(target, jsonValue, field, options) {
|
|
|
151
144
|
}
|
|
152
145
|
switch (field.kind) {
|
|
153
146
|
case "message":
|
|
154
|
-
const messageType =
|
|
147
|
+
const messageType = resolveMessageType(field.T);
|
|
155
148
|
targetArray.push(messageType.fromJson(jsonItem, options));
|
|
156
149
|
break;
|
|
157
150
|
case "enum":
|
|
@@ -203,7 +196,7 @@ function readField(target, jsonValue, field, options) {
|
|
|
203
196
|
}
|
|
204
197
|
switch (field.V.kind) {
|
|
205
198
|
case "message":
|
|
206
|
-
const messageType =
|
|
199
|
+
const messageType = resolveMessageType(field.V.T);
|
|
207
200
|
targetMap[key] = messageType.fromJson(jsonMapValue, options);
|
|
208
201
|
break;
|
|
209
202
|
case "enum":
|
|
@@ -214,7 +207,7 @@ function readField(target, jsonValue, field, options) {
|
|
|
214
207
|
break;
|
|
215
208
|
case "scalar":
|
|
216
209
|
try {
|
|
217
|
-
targetMap[key] = readScalar(field.V.T, jsonMapValue,
|
|
210
|
+
targetMap[key] = readScalar(field.V.T, jsonMapValue, LongType.BIGINT, true);
|
|
218
211
|
}
|
|
219
212
|
catch (e) {
|
|
220
213
|
let m = `cannot decode map value for field ${field.name} from JSON: ${debugJsonValue(jsonValue)}`;
|
|
@@ -234,7 +227,7 @@ function readField(target, jsonValue, field, options) {
|
|
|
234
227
|
}
|
|
235
228
|
switch (field.kind) {
|
|
236
229
|
case "message":
|
|
237
|
-
const messageType =
|
|
230
|
+
const messageType = resolveMessageType(field.T);
|
|
238
231
|
if (jsonValue === null &&
|
|
239
232
|
messageType.typeName != "google.protobuf.Value") {
|
|
240
233
|
return;
|
|
@@ -312,7 +305,7 @@ function readEnum(type, json, ignoreUnknownFields, nullAsZeroValue) {
|
|
|
312
305
|
function readScalar(type, json, longType, nullAsZeroValue) {
|
|
313
306
|
if (json === null) {
|
|
314
307
|
if (nullAsZeroValue) {
|
|
315
|
-
return
|
|
308
|
+
return scalarZeroValue(type, longType);
|
|
316
309
|
}
|
|
317
310
|
return tokenNull;
|
|
318
311
|
}
|
|
@@ -321,8 +314,8 @@ function readScalar(type, json, longType, nullAsZeroValue) {
|
|
|
321
314
|
switch (type) {
|
|
322
315
|
// float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
|
|
323
316
|
// Either numbers or strings are accepted. Exponent notation is also accepted.
|
|
324
|
-
case
|
|
325
|
-
case
|
|
317
|
+
case ScalarType.DOUBLE:
|
|
318
|
+
case ScalarType.FLOAT:
|
|
326
319
|
if (json === "NaN")
|
|
327
320
|
return Number.NaN;
|
|
328
321
|
if (json === "Infinity")
|
|
@@ -349,15 +342,15 @@ function readScalar(type, json, longType, nullAsZeroValue) {
|
|
|
349
342
|
// infinity and -infinity are handled by string representation above, so this is an error
|
|
350
343
|
break;
|
|
351
344
|
}
|
|
352
|
-
if (type ==
|
|
353
|
-
|
|
345
|
+
if (type == ScalarType.FLOAT)
|
|
346
|
+
assertFloat32(float);
|
|
354
347
|
return float;
|
|
355
348
|
// int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
|
|
356
|
-
case
|
|
357
|
-
case
|
|
358
|
-
case
|
|
359
|
-
case
|
|
360
|
-
case
|
|
349
|
+
case ScalarType.INT32:
|
|
350
|
+
case ScalarType.FIXED32:
|
|
351
|
+
case ScalarType.SFIXED32:
|
|
352
|
+
case ScalarType.SINT32:
|
|
353
|
+
case ScalarType.UINT32:
|
|
361
354
|
let int32;
|
|
362
355
|
if (typeof json == "number")
|
|
363
356
|
int32 = json;
|
|
@@ -367,34 +360,34 @@ function readScalar(type, json, longType, nullAsZeroValue) {
|
|
|
367
360
|
}
|
|
368
361
|
if (int32 === undefined)
|
|
369
362
|
break;
|
|
370
|
-
if (type ==
|
|
371
|
-
|
|
363
|
+
if (type == ScalarType.UINT32 || type == ScalarType.FIXED32)
|
|
364
|
+
assertUInt32(int32);
|
|
372
365
|
else
|
|
373
|
-
|
|
366
|
+
assertInt32(int32);
|
|
374
367
|
return int32;
|
|
375
368
|
// int64, fixed64, uint64: JSON value will be a decimal string. Either numbers or strings are accepted.
|
|
376
|
-
case
|
|
377
|
-
case
|
|
378
|
-
case
|
|
369
|
+
case ScalarType.INT64:
|
|
370
|
+
case ScalarType.SFIXED64:
|
|
371
|
+
case ScalarType.SINT64:
|
|
379
372
|
if (typeof json != "number" && typeof json != "string")
|
|
380
373
|
break;
|
|
381
|
-
const long =
|
|
374
|
+
const long = protoInt64.parse(json);
|
|
382
375
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
383
376
|
return longType ? long.toString() : long;
|
|
384
|
-
case
|
|
385
|
-
case
|
|
377
|
+
case ScalarType.FIXED64:
|
|
378
|
+
case ScalarType.UINT64:
|
|
386
379
|
if (typeof json != "number" && typeof json != "string")
|
|
387
380
|
break;
|
|
388
|
-
const uLong =
|
|
381
|
+
const uLong = protoInt64.uParse(json);
|
|
389
382
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
390
383
|
return longType ? uLong.toString() : uLong;
|
|
391
384
|
// bool:
|
|
392
|
-
case
|
|
385
|
+
case ScalarType.BOOL:
|
|
393
386
|
if (typeof json !== "boolean")
|
|
394
387
|
break;
|
|
395
388
|
return json;
|
|
396
389
|
// string:
|
|
397
|
-
case
|
|
390
|
+
case ScalarType.STRING:
|
|
398
391
|
if (typeof json !== "string") {
|
|
399
392
|
break;
|
|
400
393
|
}
|
|
@@ -409,17 +402,17 @@ function readScalar(type, json, longType, nullAsZeroValue) {
|
|
|
409
402
|
return json;
|
|
410
403
|
// bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
|
|
411
404
|
// Either standard or URL-safe base64 encoding with/without paddings are accepted.
|
|
412
|
-
case
|
|
405
|
+
case ScalarType.BYTES:
|
|
413
406
|
if (json === "")
|
|
414
407
|
return new Uint8Array(0);
|
|
415
408
|
if (typeof json !== "string")
|
|
416
409
|
break;
|
|
417
|
-
return
|
|
410
|
+
return protoBase64.dec(json);
|
|
418
411
|
}
|
|
419
412
|
throw new Error();
|
|
420
413
|
}
|
|
421
414
|
function readMapKey(type, json) {
|
|
422
|
-
if (type ===
|
|
415
|
+
if (type === ScalarType.BOOL) {
|
|
423
416
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
424
417
|
switch (json) {
|
|
425
418
|
case "true":
|
|
@@ -430,12 +423,12 @@ function readMapKey(type, json) {
|
|
|
430
423
|
break;
|
|
431
424
|
}
|
|
432
425
|
}
|
|
433
|
-
return readScalar(type, json,
|
|
426
|
+
return readScalar(type, json, LongType.BIGINT, true).toString();
|
|
434
427
|
}
|
|
435
428
|
/**
|
|
436
429
|
* Resets the field, so that isFieldSet() will return false.
|
|
437
430
|
*/
|
|
438
|
-
function clearField(field, target) {
|
|
431
|
+
export function clearField(field, target) {
|
|
439
432
|
const localName = field.localName;
|
|
440
433
|
const implicitPresence = !field.opt && !field.req;
|
|
441
434
|
if (field.repeated) {
|
|
@@ -454,7 +447,7 @@ function clearField(field, target) {
|
|
|
454
447
|
break;
|
|
455
448
|
case "scalar":
|
|
456
449
|
target[localName] =
|
|
457
|
-
implicitPresence ?
|
|
450
|
+
implicitPresence ? scalarZeroValue(field.T, field.L) : undefined;
|
|
458
451
|
break;
|
|
459
452
|
case "message":
|
|
460
453
|
target[localName] = undefined;
|
|
@@ -462,7 +455,6 @@ function clearField(field, target) {
|
|
|
462
455
|
}
|
|
463
456
|
}
|
|
464
457
|
}
|
|
465
|
-
exports.clearField = clearField;
|
|
466
458
|
// Decide whether an unset field should be emitted with JSON write option `emitDefaultValues`
|
|
467
459
|
function canEmitFieldDefaultValue(field) {
|
|
468
460
|
if (field.repeated || field.kind == "map") {
|
|
@@ -486,7 +478,7 @@ function canEmitFieldDefaultValue(field) {
|
|
|
486
478
|
}
|
|
487
479
|
function writeField(field, value, options) {
|
|
488
480
|
if (field.kind == "map") {
|
|
489
|
-
|
|
481
|
+
assert(typeof value == "object" && value != null);
|
|
490
482
|
const jsonObj = {};
|
|
491
483
|
const entries = Object.entries(value);
|
|
492
484
|
switch (field.V.kind) {
|
|
@@ -498,7 +490,7 @@ function writeField(field, value, options) {
|
|
|
498
490
|
case "message":
|
|
499
491
|
for (const [entryKey, entryValue] of entries) {
|
|
500
492
|
// JSON standard allows only (double quoted) string as property key
|
|
501
|
-
const messageType =
|
|
493
|
+
const messageType = resolveMessageType(field.V.T);
|
|
502
494
|
jsonObj[entryKey.toString()] = messageType.toJson(entryValue, options);
|
|
503
495
|
}
|
|
504
496
|
break;
|
|
@@ -515,7 +507,7 @@ function writeField(field, value, options) {
|
|
|
515
507
|
: undefined;
|
|
516
508
|
}
|
|
517
509
|
if (field.repeated) {
|
|
518
|
-
|
|
510
|
+
assert(Array.isArray(value));
|
|
519
511
|
const jsonArr = [];
|
|
520
512
|
switch (field.kind) {
|
|
521
513
|
case "scalar":
|
|
@@ -544,26 +536,26 @@ function writeField(field, value, options) {
|
|
|
544
536
|
case "enum":
|
|
545
537
|
return writeEnum(field.T, value, options.enumAsInteger);
|
|
546
538
|
case "message":
|
|
547
|
-
const messageType =
|
|
548
|
-
return messageType.toJson(
|
|
539
|
+
const messageType = resolveMessageType(field.T);
|
|
540
|
+
return messageType.toJson(wrapField(messageType.fieldWrapper, value));
|
|
549
541
|
}
|
|
550
542
|
}
|
|
551
543
|
function writeScalar(type, value) {
|
|
552
544
|
switch (type) {
|
|
553
545
|
// int32, fixed32, uint32: JSON value will be a decimal number. Either numbers or strings are accepted.
|
|
554
|
-
case
|
|
555
|
-
case
|
|
556
|
-
case
|
|
557
|
-
case
|
|
558
|
-
case
|
|
559
|
-
|
|
546
|
+
case ScalarType.INT32:
|
|
547
|
+
case ScalarType.SFIXED32:
|
|
548
|
+
case ScalarType.SINT32:
|
|
549
|
+
case ScalarType.FIXED32:
|
|
550
|
+
case ScalarType.UINT32:
|
|
551
|
+
assert(typeof value == "number");
|
|
560
552
|
return value;
|
|
561
553
|
// float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
|
|
562
554
|
// Either numbers or strings are accepted. Exponent notation is also accepted.
|
|
563
|
-
case
|
|
555
|
+
case ScalarType.FLOAT:
|
|
564
556
|
// assertFloat32(value);
|
|
565
|
-
case
|
|
566
|
-
|
|
557
|
+
case ScalarType.DOUBLE: // eslint-disable-line no-fallthrough
|
|
558
|
+
assert(typeof value == "number");
|
|
567
559
|
if (Number.isNaN(value))
|
|
568
560
|
return "NaN";
|
|
569
561
|
if (value === Number.POSITIVE_INFINITY)
|
|
@@ -572,32 +564,32 @@ function writeScalar(type, value) {
|
|
|
572
564
|
return "-Infinity";
|
|
573
565
|
return value;
|
|
574
566
|
// string:
|
|
575
|
-
case
|
|
576
|
-
|
|
567
|
+
case ScalarType.STRING:
|
|
568
|
+
assert(typeof value == "string");
|
|
577
569
|
return value;
|
|
578
570
|
// bool:
|
|
579
|
-
case
|
|
580
|
-
|
|
571
|
+
case ScalarType.BOOL:
|
|
572
|
+
assert(typeof value == "boolean");
|
|
581
573
|
return value;
|
|
582
574
|
// JSON value will be a decimal string. Either numbers or strings are accepted.
|
|
583
|
-
case
|
|
584
|
-
case
|
|
585
|
-
case
|
|
586
|
-
case
|
|
587
|
-
case
|
|
588
|
-
|
|
575
|
+
case ScalarType.UINT64:
|
|
576
|
+
case ScalarType.FIXED64:
|
|
577
|
+
case ScalarType.INT64:
|
|
578
|
+
case ScalarType.SFIXED64:
|
|
579
|
+
case ScalarType.SINT64:
|
|
580
|
+
assert(typeof value == "bigint" ||
|
|
589
581
|
typeof value == "string" ||
|
|
590
582
|
typeof value == "number");
|
|
591
583
|
return value.toString();
|
|
592
584
|
// bytes: JSON value will be the data encoded as a string using standard base64 encoding with paddings.
|
|
593
585
|
// Either standard or URL-safe base64 encoding with/without paddings are accepted.
|
|
594
|
-
case
|
|
595
|
-
|
|
596
|
-
return
|
|
586
|
+
case ScalarType.BYTES:
|
|
587
|
+
assert(value instanceof Uint8Array);
|
|
588
|
+
return protoBase64.enc(value);
|
|
597
589
|
}
|
|
598
590
|
}
|
|
599
591
|
function writeEnum(type, value, enumAsInteger) {
|
|
600
|
-
|
|
592
|
+
assert(typeof value == "number");
|
|
601
593
|
if (type.typeName == "google.protobuf.NullValue") {
|
|
602
594
|
return null;
|
|
603
595
|
}
|