@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.1
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 +21 -1
- package/dist/cjs/binary-encoding.js +402 -410
- package/dist/cjs/descriptor-registry.js +407 -449
- package/dist/cjs/descriptor-set.js +416 -513
- package/dist/cjs/field.js +30 -30
- package/dist/cjs/google/protobuf/any_pb.js +122 -140
- package/dist/cjs/google/protobuf/api_pb.js +177 -224
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
- package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
- package/dist/cjs/google/protobuf/duration_pb.js +72 -88
- package/dist/cjs/google/protobuf/empty_pb.js +17 -17
- package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
- package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
- package/dist/cjs/google/protobuf/struct_pb.js +144 -181
- package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
- package/dist/cjs/google/protobuf/type_pb.js +406 -462
- package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
- package/dist/cjs/index.js +24 -122
- package/dist/cjs/message.js +81 -89
- package/dist/cjs/private/assert.js +20 -26
- package/dist/cjs/private/base64.js +79 -78
- package/dist/cjs/private/binary-format-common.js +195 -208
- package/dist/cjs/private/binary-format-proto2.js +75 -109
- package/dist/cjs/private/binary-format-proto3.js +57 -90
- package/dist/cjs/private/enum.js +38 -43
- package/dist/cjs/private/field-list.js +51 -50
- package/dist/cjs/private/field-wrapper.js +8 -10
- package/dist/cjs/private/field.js +22 -25
- package/dist/cjs/private/goog-varint.js +275 -0
- package/dist/cjs/private/json-format-common.js +414 -440
- package/dist/cjs/private/json-format-proto2.js +78 -89
- package/dist/cjs/private/json-format-proto3.js +69 -93
- package/dist/cjs/private/message-type.js +26 -27
- package/dist/cjs/private/names.js +58 -62
- package/dist/cjs/private/proto-runtime.js +11 -16
- package/dist/cjs/private/scalars.js +100 -103
- package/dist/cjs/private/util-common.js +180 -210
- package/dist/cjs/proto-int64.js +111 -112
- package/dist/cjs/proto2.js +50 -63
- package/dist/cjs/proto3.js +61 -74
- package/dist/cjs/service-type.js +14 -17
- package/dist/cjs/type-registry.js +33 -31
- package/dist/esm/binary-encoding.js +401 -414
- package/dist/esm/descriptor-registry.js +409 -458
- package/dist/esm/descriptor-set.js +417 -478
- package/dist/esm/field.js +29 -29
- package/dist/esm/google/protobuf/any_pb.js +122 -140
- package/dist/esm/google/protobuf/api_pb.js +177 -197
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
- package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
- package/dist/esm/google/protobuf/duration_pb.js +72 -88
- package/dist/esm/google/protobuf/empty_pb.js +17 -17
- package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
- package/dist/esm/google/protobuf/source_context_pb.js +25 -25
- package/dist/esm/google/protobuf/struct_pb.js +143 -180
- package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
- package/dist/esm/google/protobuf/type_pb.js +401 -421
- package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
- package/dist/esm/index.js +1 -1
- package/dist/esm/message.js +81 -89
- package/dist/esm/private/assert.js +19 -21
- package/dist/esm/private/base64.js +79 -78
- package/dist/esm/private/binary-format-common.js +196 -207
- package/dist/esm/private/binary-format-proto2.js +76 -81
- package/dist/esm/private/binary-format-proto3.js +58 -67
- package/dist/esm/private/enum.js +38 -43
- package/dist/esm/private/field-list.js +51 -50
- package/dist/esm/private/field-wrapper.js +8 -10
- package/dist/esm/private/field.js +22 -22
- package/dist/esm/private/goog-varint.js +266 -0
- package/dist/esm/private/json-format-common.js +414 -435
- package/dist/esm/private/json-format-proto2.js +76 -81
- package/dist/esm/private/json-format-proto3.js +66 -80
- package/dist/esm/private/message-type.js +27 -28
- package/dist/esm/private/names.js +57 -57
- package/dist/esm/private/proto-runtime.js +11 -11
- package/dist/esm/private/scalars.js +99 -99
- package/dist/esm/private/util-common.js +180 -192
- package/dist/esm/proto-int64.js +111 -112
- package/dist/esm/proto2.js +50 -57
- package/dist/esm/proto3.js +61 -68
- package/dist/esm/service-type.js +12 -12
- package/dist/esm/type-registry.js +33 -31
- package/dist/types/binary-encoding.d.ts +398 -398
- package/dist/types/binary-format.d.ts +69 -91
- package/dist/types/descriptor-registry.d.ts +23 -29
- package/dist/types/descriptor-set.d.ts +107 -128
- package/dist/types/enum.d.ts +21 -21
- package/dist/types/field-list.d.ts +21 -21
- package/dist/types/field.d.ts +191 -231
- package/dist/types/google/protobuf/any_pb.d.ts +56 -77
- package/dist/types/google/protobuf/api_pb.d.ts +144 -187
- package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
- package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
- package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
- package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
- package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
- package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
- package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
- package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
- package/dist/types/google/protobuf/type_pb.d.ts +355 -422
- package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
- package/dist/types/index.d.ts +4 -27
- package/dist/types/json-format.d.ts +70 -89
- package/dist/types/message-type.d.ts +38 -46
- package/dist/types/message.d.ts +73 -99
- package/dist/types/private/assert.d.ts +1 -4
- package/dist/types/private/binary-format-common.d.ts +6 -32
- package/dist/types/private/enum.d.ts +4 -11
- package/dist/types/private/field-list.d.ts +14 -21
- package/dist/types/private/field-wrapper.d.ts +5 -11
- package/dist/types/private/field.d.ts +12 -12
- package/dist/types/{google/varint.d.ts → private/goog-varint.d.ts} +6 -13
- package/dist/types/private/json-format-common.d.ts +5 -27
- package/dist/types/private/message-type.d.ts +3 -8
- package/dist/types/private/names.d.ts +1 -4
- package/dist/types/private/options-map.d.ts +1 -1
- package/dist/types/private/proto-runtime.d.ts +29 -42
- package/dist/types/private/scalars.d.ts +5 -12
- package/dist/types/private/util-common.d.ts +1 -4
- package/dist/types/private/util.d.ts +29 -41
- package/dist/types/proto-int64.d.ts +42 -42
- package/dist/types/service-type.d.ts +37 -57
- package/dist/types/type-registry.d.ts +13 -15
- package/package.json +2 -2
- package/dist/cjs/google/varint.js +0 -280
- package/dist/esm/google/varint.js +0 -265
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BinaryReader = exports.BinaryWriter = exports.WireType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const goog_varint_js_1 = require("./private/goog-varint.js");
|
|
5
5
|
const assert_js_1 = require("./private/assert.js");
|
|
6
6
|
const proto_int64_js_1 = require("./proto-int64.js");
|
|
7
7
|
/* eslint-disable prefer-const,no-case-declarations,@typescript-eslint/restrict-plus-operands */
|
|
@@ -15,420 +15,412 @@ const proto_int64_js_1 = require("./proto-int64.js");
|
|
|
15
15
|
*/
|
|
16
16
|
var WireType;
|
|
17
17
|
(function (WireType) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})(
|
|
18
|
+
/**
|
|
19
|
+
* Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum
|
|
20
|
+
*/
|
|
21
|
+
WireType[WireType["Varint"] = 0] = "Varint";
|
|
22
|
+
/**
|
|
23
|
+
* Used for fixed64, sfixed64, double.
|
|
24
|
+
* Always 8 bytes with little-endian byte order.
|
|
25
|
+
*/
|
|
26
|
+
WireType[WireType["Bit64"] = 1] = "Bit64";
|
|
27
|
+
/**
|
|
28
|
+
* Used for string, bytes, embedded messages, packed repeated fields
|
|
29
|
+
*
|
|
30
|
+
* Only repeated numeric types (types which use the varint, 32-bit,
|
|
31
|
+
* or 64-bit wire types) can be packed. In proto3, such fields are
|
|
32
|
+
* packed by default.
|
|
33
|
+
*/
|
|
34
|
+
WireType[WireType["LengthDelimited"] = 2] = "LengthDelimited";
|
|
35
|
+
/**
|
|
36
|
+
* Used for groups
|
|
37
|
+
* @deprecated
|
|
38
|
+
*/
|
|
39
|
+
WireType[WireType["StartGroup"] = 3] = "StartGroup";
|
|
40
|
+
/**
|
|
41
|
+
* Used for groups
|
|
42
|
+
* @deprecated
|
|
43
|
+
*/
|
|
44
|
+
WireType[WireType["EndGroup"] = 4] = "EndGroup";
|
|
45
|
+
/**
|
|
46
|
+
* Used for fixed32, sfixed32, float.
|
|
47
|
+
* Always 4 bytes with little-endian byte order.
|
|
48
|
+
*/
|
|
49
|
+
WireType[WireType["Bit32"] = 5] = "Bit32";
|
|
50
|
+
})(WireType = exports.WireType || (exports.WireType = {}));
|
|
51
51
|
class BinaryWriter {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
let tc = proto_int64_js_1.protoInt64.uEnc(value);
|
|
261
|
-
(0, varint_js_1.varint64write)(tc.lo, tc.hi, this.buf);
|
|
262
|
-
return this;
|
|
263
|
-
}
|
|
52
|
+
constructor(textEncoder) {
|
|
53
|
+
/**
|
|
54
|
+
* Previous fork states.
|
|
55
|
+
*/
|
|
56
|
+
this.stack = [];
|
|
57
|
+
this.textEncoder = textEncoder ?? new TextEncoder();
|
|
58
|
+
this.chunks = [];
|
|
59
|
+
this.buf = [];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Return all bytes written and reset this writer.
|
|
63
|
+
*/
|
|
64
|
+
finish() {
|
|
65
|
+
this.chunks.push(new Uint8Array(this.buf)); // flush the buffer
|
|
66
|
+
let len = 0;
|
|
67
|
+
for (let i = 0; i < this.chunks.length; i++)
|
|
68
|
+
len += this.chunks[i].length;
|
|
69
|
+
let bytes = new Uint8Array(len);
|
|
70
|
+
let offset = 0;
|
|
71
|
+
for (let i = 0; i < this.chunks.length; i++) {
|
|
72
|
+
bytes.set(this.chunks[i], offset);
|
|
73
|
+
offset += this.chunks[i].length;
|
|
74
|
+
}
|
|
75
|
+
this.chunks = [];
|
|
76
|
+
return bytes;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Start a new fork for length-delimited data like a message
|
|
80
|
+
* or a packed repeated field.
|
|
81
|
+
*
|
|
82
|
+
* Must be joined later with `join()`.
|
|
83
|
+
*/
|
|
84
|
+
fork() {
|
|
85
|
+
this.stack.push({ chunks: this.chunks, buf: this.buf });
|
|
86
|
+
this.chunks = [];
|
|
87
|
+
this.buf = [];
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Join the last fork. Write its length and bytes, then
|
|
92
|
+
* return to the previous state.
|
|
93
|
+
*/
|
|
94
|
+
join() {
|
|
95
|
+
// get chunk of fork
|
|
96
|
+
let chunk = this.finish();
|
|
97
|
+
// restore previous state
|
|
98
|
+
let prev = this.stack.pop();
|
|
99
|
+
if (!prev)
|
|
100
|
+
throw new Error("invalid state, fork stack empty");
|
|
101
|
+
this.chunks = prev.chunks;
|
|
102
|
+
this.buf = prev.buf;
|
|
103
|
+
// write length of chunk as varint
|
|
104
|
+
this.uint32(chunk.byteLength);
|
|
105
|
+
return this.raw(chunk);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Writes a tag (field number and wire type).
|
|
109
|
+
*
|
|
110
|
+
* Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`.
|
|
111
|
+
*
|
|
112
|
+
* Generated code should compute the tag ahead of time and call `uint32()`.
|
|
113
|
+
*/
|
|
114
|
+
tag(fieldNo, type) {
|
|
115
|
+
return this.uint32(((fieldNo << 3) | type) >>> 0);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Write a chunk of raw bytes.
|
|
119
|
+
*/
|
|
120
|
+
raw(chunk) {
|
|
121
|
+
if (this.buf.length) {
|
|
122
|
+
this.chunks.push(new Uint8Array(this.buf));
|
|
123
|
+
this.buf = [];
|
|
124
|
+
}
|
|
125
|
+
this.chunks.push(chunk);
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Write a `uint32` value, an unsigned 32 bit varint.
|
|
130
|
+
*/
|
|
131
|
+
uint32(value) {
|
|
132
|
+
(0, assert_js_1.assertUInt32)(value);
|
|
133
|
+
// write value as varint 32, inlined for speed
|
|
134
|
+
while (value > 0x7f) {
|
|
135
|
+
this.buf.push((value & 0x7f) | 0x80);
|
|
136
|
+
value = value >>> 7;
|
|
137
|
+
}
|
|
138
|
+
this.buf.push(value);
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Write a `int32` value, a signed 32 bit varint.
|
|
143
|
+
*/
|
|
144
|
+
int32(value) {
|
|
145
|
+
(0, assert_js_1.assertInt32)(value);
|
|
146
|
+
(0, goog_varint_js_1.varint32write)(value, this.buf);
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Write a `bool` value, a variant.
|
|
151
|
+
*/
|
|
152
|
+
bool(value) {
|
|
153
|
+
this.buf.push(value ? 1 : 0);
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Write a `bytes` value, length-delimited arbitrary data.
|
|
158
|
+
*/
|
|
159
|
+
bytes(value) {
|
|
160
|
+
this.uint32(value.byteLength); // write length of chunk as varint
|
|
161
|
+
return this.raw(value);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Write a `string` value, length-delimited data converted to UTF-8 text.
|
|
165
|
+
*/
|
|
166
|
+
string(value) {
|
|
167
|
+
let chunk = this.textEncoder.encode(value);
|
|
168
|
+
this.uint32(chunk.byteLength); // write length of chunk as varint
|
|
169
|
+
return this.raw(chunk);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Write a `float` value, 32-bit floating point number.
|
|
173
|
+
*/
|
|
174
|
+
float(value) {
|
|
175
|
+
(0, assert_js_1.assertFloat32)(value);
|
|
176
|
+
let chunk = new Uint8Array(4);
|
|
177
|
+
new DataView(chunk.buffer).setFloat32(0, value, true);
|
|
178
|
+
return this.raw(chunk);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Write a `double` value, a 64-bit floating point number.
|
|
182
|
+
*/
|
|
183
|
+
double(value) {
|
|
184
|
+
let chunk = new Uint8Array(8);
|
|
185
|
+
new DataView(chunk.buffer).setFloat64(0, value, true);
|
|
186
|
+
return this.raw(chunk);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
|
|
190
|
+
*/
|
|
191
|
+
fixed32(value) {
|
|
192
|
+
(0, assert_js_1.assertUInt32)(value);
|
|
193
|
+
let chunk = new Uint8Array(4);
|
|
194
|
+
new DataView(chunk.buffer).setUint32(0, value, true);
|
|
195
|
+
return this.raw(chunk);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
|
|
199
|
+
*/
|
|
200
|
+
sfixed32(value) {
|
|
201
|
+
(0, assert_js_1.assertInt32)(value);
|
|
202
|
+
let chunk = new Uint8Array(4);
|
|
203
|
+
new DataView(chunk.buffer).setInt32(0, value, true);
|
|
204
|
+
return this.raw(chunk);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
|
|
208
|
+
*/
|
|
209
|
+
sint32(value) {
|
|
210
|
+
(0, assert_js_1.assertInt32)(value);
|
|
211
|
+
// zigzag encode
|
|
212
|
+
value = ((value << 1) ^ (value >> 31)) >>> 0;
|
|
213
|
+
(0, goog_varint_js_1.varint32write)(value, this.buf);
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Write a `fixed64` value, a signed, fixed-length 64-bit integer.
|
|
218
|
+
*/
|
|
219
|
+
sfixed64(value) {
|
|
220
|
+
let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc = proto_int64_js_1.protoInt64.enc(value);
|
|
221
|
+
view.setInt32(0, tc.lo, true);
|
|
222
|
+
view.setInt32(4, tc.hi, true);
|
|
223
|
+
return this.raw(chunk);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
|
|
227
|
+
*/
|
|
228
|
+
fixed64(value) {
|
|
229
|
+
let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc = proto_int64_js_1.protoInt64.uEnc(value);
|
|
230
|
+
view.setInt32(0, tc.lo, true);
|
|
231
|
+
view.setInt32(4, tc.hi, true);
|
|
232
|
+
return this.raw(chunk);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Write a `int64` value, a signed 64-bit varint.
|
|
236
|
+
*/
|
|
237
|
+
int64(value) {
|
|
238
|
+
let tc = proto_int64_js_1.protoInt64.enc(value);
|
|
239
|
+
(0, goog_varint_js_1.varint64write)(tc.lo, tc.hi, this.buf);
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
|
|
244
|
+
*/
|
|
245
|
+
sint64(value) {
|
|
246
|
+
let tc = proto_int64_js_1.protoInt64.enc(value),
|
|
247
|
+
// zigzag encode
|
|
248
|
+
sign = tc.hi >> 31, lo = (tc.lo << 1) ^ sign, hi = ((tc.hi << 1) | (tc.lo >>> 31)) ^ sign;
|
|
249
|
+
(0, goog_varint_js_1.varint64write)(lo, hi, this.buf);
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Write a `uint64` value, an unsigned 64-bit varint.
|
|
254
|
+
*/
|
|
255
|
+
uint64(value) {
|
|
256
|
+
let tc = proto_int64_js_1.protoInt64.uEnc(value);
|
|
257
|
+
(0, goog_varint_js_1.varint64write)(tc.lo, tc.hi, this.buf);
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
264
260
|
}
|
|
265
261
|
exports.BinaryWriter = BinaryWriter;
|
|
266
262
|
class BinaryReader {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
263
|
+
constructor(buf, textDecoder) {
|
|
264
|
+
this.varint64 = goog_varint_js_1.varint64read; // dirty cast for `this`
|
|
265
|
+
/**
|
|
266
|
+
* Read a `uint32` field, an unsigned 32 bit varint.
|
|
267
|
+
*/
|
|
268
|
+
this.uint32 = goog_varint_js_1.varint32read; // dirty cast for `this` and access to protected `buf`
|
|
269
|
+
this.buf = buf;
|
|
270
|
+
this.len = buf.length;
|
|
271
|
+
this.pos = 0;
|
|
272
|
+
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
273
|
+
this.textDecoder = textDecoder ?? new TextDecoder();
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Reads a tag - field number and wire type.
|
|
277
|
+
*/
|
|
278
|
+
tag() {
|
|
279
|
+
let tag = this.uint32(), fieldNo = tag >>> 3, wireType = tag & 7;
|
|
280
|
+
if (fieldNo <= 0 || wireType < 0 || wireType > 5)
|
|
281
|
+
throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
|
|
282
|
+
return [fieldNo, wireType];
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Skip one element on the wire and return the skipped data.
|
|
286
|
+
* Supports WireType.StartGroup since v2.0.0-alpha.23.
|
|
287
|
+
*/
|
|
288
|
+
skip(wireType) {
|
|
289
|
+
let start = this.pos;
|
|
290
|
+
switch (wireType) {
|
|
291
|
+
case WireType.Varint:
|
|
292
|
+
while (this.buf[this.pos++] & 0x80) {
|
|
293
|
+
// ignore
|
|
294
|
+
}
|
|
295
|
+
break;
|
|
296
|
+
// eslint-disable-next-line
|
|
297
|
+
// @ts-ignore TS7029: Fallthrough case in switch
|
|
298
|
+
case WireType.Bit64:
|
|
299
|
+
this.pos += 4;
|
|
300
|
+
// eslint-disable-next-line
|
|
301
|
+
// @ts-ignore TS7029: Fallthrough case in switch
|
|
302
|
+
case WireType.Bit32:
|
|
303
|
+
this.pos += 4;
|
|
304
|
+
break;
|
|
305
|
+
case WireType.LengthDelimited:
|
|
306
|
+
let len = this.uint32();
|
|
307
|
+
this.pos += len;
|
|
308
|
+
break;
|
|
309
|
+
case WireType.StartGroup:
|
|
310
|
+
// From descriptor.proto: Group type is deprecated, not supported in proto3.
|
|
311
|
+
// But we must still be able to parse and treat as unknown.
|
|
312
|
+
let t;
|
|
313
|
+
while ((t = this.tag()[1]) !== WireType.EndGroup) {
|
|
314
|
+
this.skip(t);
|
|
315
|
+
}
|
|
316
|
+
break;
|
|
317
|
+
default:
|
|
318
|
+
throw new Error("cant skip wire type " + wireType);
|
|
302
319
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
320
|
+
this.assertBounds();
|
|
321
|
+
return this.buf.subarray(start, this.pos);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Throws error if position in byte array is out of range.
|
|
325
|
+
*/
|
|
326
|
+
assertBounds() {
|
|
327
|
+
if (this.pos > this.len)
|
|
328
|
+
throw new RangeError("premature EOF");
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Read a `int32` field, a signed 32 bit varint.
|
|
332
|
+
*/
|
|
333
|
+
int32() {
|
|
334
|
+
return this.uint32() | 0;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
|
|
338
|
+
*/
|
|
339
|
+
sint32() {
|
|
340
|
+
let zze = this.uint32();
|
|
341
|
+
// decode zigzag
|
|
342
|
+
return (zze >>> 1) ^ -(zze & 1);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Read a `int64` field, a signed 64-bit varint.
|
|
346
|
+
*/
|
|
347
|
+
int64() {
|
|
348
|
+
return proto_int64_js_1.protoInt64.dec(...this.varint64());
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Read a `uint64` field, an unsigned 64-bit varint.
|
|
352
|
+
*/
|
|
353
|
+
uint64() {
|
|
354
|
+
return proto_int64_js_1.protoInt64.uDec(...this.varint64());
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
|
|
358
|
+
*/
|
|
359
|
+
sint64() {
|
|
360
|
+
let [lo, hi] = this.varint64();
|
|
361
|
+
// decode zig zag
|
|
362
|
+
let s = -(lo & 1);
|
|
363
|
+
lo = ((lo >>> 1) | ((hi & 1) << 31)) ^ s;
|
|
364
|
+
hi = (hi >>> 1) ^ s;
|
|
365
|
+
return proto_int64_js_1.protoInt64.dec(lo, hi);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Read a `bool` field, a variant.
|
|
369
|
+
*/
|
|
370
|
+
bool() {
|
|
371
|
+
let [lo, hi] = this.varint64();
|
|
372
|
+
return lo !== 0 || hi !== 0;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
|
|
376
|
+
*/
|
|
377
|
+
fixed32() {
|
|
378
|
+
return this.view.getUint32((this.pos += 4) - 4, true);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
|
|
382
|
+
*/
|
|
383
|
+
sfixed32() {
|
|
384
|
+
return this.view.getInt32((this.pos += 4) - 4, true);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
|
|
388
|
+
*/
|
|
389
|
+
fixed64() {
|
|
390
|
+
return proto_int64_js_1.protoInt64.uDec(this.sfixed32(), this.sfixed32());
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Read a `fixed64` field, a signed, fixed-length 64-bit integer.
|
|
394
|
+
*/
|
|
395
|
+
sfixed64() {
|
|
396
|
+
return proto_int64_js_1.protoInt64.dec(this.sfixed32(), this.sfixed32());
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Read a `float` field, 32-bit floating point number.
|
|
400
|
+
*/
|
|
401
|
+
float() {
|
|
402
|
+
return this.view.getFloat32((this.pos += 4) - 4, true);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Read a `double` field, a 64-bit floating point number.
|
|
406
|
+
*/
|
|
407
|
+
double() {
|
|
408
|
+
return this.view.getFloat64((this.pos += 8) - 8, true);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Read a `bytes` field, length-delimited arbitrary data.
|
|
412
|
+
*/
|
|
413
|
+
bytes() {
|
|
414
|
+
let len = this.uint32(), start = this.pos;
|
|
315
415
|
this.pos += len;
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
default:
|
|
326
|
-
throw new Error("cant skip wire type " + wireType);
|
|
327
|
-
}
|
|
328
|
-
this.assertBounds();
|
|
329
|
-
return this.buf.subarray(start, this.pos);
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Throws error if position in byte array is out of range.
|
|
333
|
-
*/
|
|
334
|
-
assertBounds() {
|
|
335
|
-
if (this.pos > this.len) throw new RangeError("premature EOF");
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Read a `int32` field, a signed 32 bit varint.
|
|
339
|
-
*/
|
|
340
|
-
int32() {
|
|
341
|
-
return this.uint32() | 0;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
|
|
345
|
-
*/
|
|
346
|
-
sint32() {
|
|
347
|
-
let zze = this.uint32();
|
|
348
|
-
// decode zigzag
|
|
349
|
-
return (zze >>> 1) ^ -(zze & 1);
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Read a `int64` field, a signed 64-bit varint.
|
|
353
|
-
*/
|
|
354
|
-
int64() {
|
|
355
|
-
return proto_int64_js_1.protoInt64.dec(...this.varint64());
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Read a `uint64` field, an unsigned 64-bit varint.
|
|
359
|
-
*/
|
|
360
|
-
uint64() {
|
|
361
|
-
return proto_int64_js_1.protoInt64.uDec(...this.varint64());
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
|
|
365
|
-
*/
|
|
366
|
-
sint64() {
|
|
367
|
-
let [lo, hi] = this.varint64();
|
|
368
|
-
// decode zig zag
|
|
369
|
-
let s = -(lo & 1);
|
|
370
|
-
lo = ((lo >>> 1) | ((hi & 1) << 31)) ^ s;
|
|
371
|
-
hi = (hi >>> 1) ^ s;
|
|
372
|
-
return proto_int64_js_1.protoInt64.dec(lo, hi);
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Read a `bool` field, a variant.
|
|
376
|
-
*/
|
|
377
|
-
bool() {
|
|
378
|
-
let [lo, hi] = this.varint64();
|
|
379
|
-
return lo !== 0 || hi !== 0;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
|
|
383
|
-
*/
|
|
384
|
-
fixed32() {
|
|
385
|
-
return this.view.getUint32((this.pos += 4) - 4, true);
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
|
|
389
|
-
*/
|
|
390
|
-
sfixed32() {
|
|
391
|
-
return this.view.getInt32((this.pos += 4) - 4, true);
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
|
|
395
|
-
*/
|
|
396
|
-
fixed64() {
|
|
397
|
-
return proto_int64_js_1.protoInt64.uDec(this.sfixed32(), this.sfixed32());
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Read a `fixed64` field, a signed, fixed-length 64-bit integer.
|
|
401
|
-
*/
|
|
402
|
-
sfixed64() {
|
|
403
|
-
return proto_int64_js_1.protoInt64.dec(this.sfixed32(), this.sfixed32());
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Read a `float` field, 32-bit floating point number.
|
|
407
|
-
*/
|
|
408
|
-
float() {
|
|
409
|
-
return this.view.getFloat32((this.pos += 4) - 4, true);
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Read a `double` field, a 64-bit floating point number.
|
|
413
|
-
*/
|
|
414
|
-
double() {
|
|
415
|
-
return this.view.getFloat64((this.pos += 8) - 8, true);
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Read a `bytes` field, length-delimited arbitrary data.
|
|
419
|
-
*/
|
|
420
|
-
bytes() {
|
|
421
|
-
let len = this.uint32(),
|
|
422
|
-
start = this.pos;
|
|
423
|
-
this.pos += len;
|
|
424
|
-
this.assertBounds();
|
|
425
|
-
return this.buf.subarray(start, start + len);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Read a `string` field, length-delimited data converted to UTF-8 text.
|
|
429
|
-
*/
|
|
430
|
-
string() {
|
|
431
|
-
return this.textDecoder.decode(this.bytes());
|
|
432
|
-
}
|
|
416
|
+
this.assertBounds();
|
|
417
|
+
return this.buf.subarray(start, start + len);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Read a `string` field, length-delimited data converted to UTF-8 text.
|
|
421
|
+
*/
|
|
422
|
+
string() {
|
|
423
|
+
return this.textDecoder.decode(this.bytes());
|
|
424
|
+
}
|
|
433
425
|
}
|
|
434
426
|
exports.BinaryReader = BinaryReader;
|