@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.2-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/binary-encoding.js +414 -409
- package/dist/cjs/binary-format.js +13 -0
- package/dist/cjs/descriptor-registry.js +420 -449
- package/dist/cjs/descriptor-set.js +429 -513
- package/dist/cjs/enum.js +13 -0
- package/dist/cjs/field-list.js +13 -0
- package/dist/cjs/field.js +43 -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/google/varint.js +166 -171
- package/dist/cjs/index.js +41 -122
- package/dist/cjs/json-format.js +13 -0
- package/dist/cjs/message-type.js +13 -0
- package/dist/cjs/message.js +89 -85
- package/dist/cjs/private/assert.js +33 -26
- package/dist/cjs/private/base64.js +93 -79
- package/dist/cjs/private/binary-format-common.js +208 -208
- package/dist/cjs/private/binary-format-proto2.js +88 -109
- package/dist/cjs/private/binary-format-proto3.js +70 -90
- package/dist/cjs/private/enum.js +77 -44
- package/dist/cjs/private/field-list.js +64 -50
- package/dist/cjs/private/field-wrapper.js +21 -10
- package/dist/cjs/private/field.js +35 -25
- package/dist/cjs/private/json-format-common.js +427 -440
- package/dist/cjs/private/json-format-proto2.js +91 -89
- package/dist/cjs/private/json-format-proto3.js +82 -93
- package/dist/cjs/private/message-type.js +39 -27
- package/dist/cjs/private/names.js +71 -62
- package/dist/cjs/private/options-map.js +13 -0
- package/dist/cjs/private/proto-runtime.js +25 -16
- package/dist/cjs/private/scalars.js +113 -103
- package/dist/cjs/private/util-common.js +193 -210
- package/dist/cjs/private/util.js +13 -0
- package/dist/cjs/proto-int64.js +123 -111
- package/dist/cjs/proto2.js +63 -63
- package/dist/cjs/proto3.js +74 -74
- package/dist/cjs/service-type.js +27 -17
- package/dist/cjs/type-registry.js +46 -31
- package/dist/esm/binary-encoding.js +414 -414
- package/dist/esm/binary-format.js +13 -0
- package/dist/esm/descriptor-registry.js +422 -458
- package/dist/esm/descriptor-set.js +430 -478
- package/dist/esm/enum.js +13 -0
- package/dist/esm/field-list.js +13 -0
- package/dist/esm/field.js +42 -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/google/varint.js +165 -164
- package/dist/esm/index.js +14 -1
- package/dist/esm/json-format.js +13 -0
- package/dist/esm/message-type.js +13 -0
- package/dist/esm/message.js +89 -85
- package/dist/esm/private/assert.js +32 -21
- package/dist/esm/private/base64.js +92 -78
- package/dist/esm/private/binary-format-common.js +209 -207
- package/dist/esm/private/binary-format-proto2.js +89 -81
- package/dist/esm/private/binary-format-proto3.js +71 -67
- package/dist/esm/private/enum.js +75 -43
- package/dist/esm/private/field-list.js +64 -50
- package/dist/esm/private/field-wrapper.js +21 -10
- package/dist/esm/private/field.js +35 -22
- package/dist/esm/private/json-format-common.js +427 -435
- package/dist/esm/private/json-format-proto2.js +89 -81
- package/dist/esm/private/json-format-proto3.js +79 -80
- package/dist/esm/private/message-type.js +40 -28
- package/dist/esm/private/names.js +70 -57
- package/dist/esm/private/options-map.js +13 -0
- package/dist/esm/private/proto-runtime.js +26 -12
- package/dist/esm/private/scalars.js +112 -99
- package/dist/esm/private/util-common.js +193 -192
- package/dist/esm/private/util.js +13 -0
- package/dist/esm/proto-int64.js +123 -111
- package/dist/esm/proto2.js +63 -57
- package/dist/esm/proto3.js +74 -68
- package/dist/esm/service-type.js +25 -12
- package/dist/esm/type-registry.js +46 -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/google/varint.d.ts +6 -13
- package/dist/types/index.d.ts +4 -27
- package/dist/types/json-format.d.ts +70 -89
- package/dist/types/message-type.d.ts +37 -45
- package/dist/types/message.d.ts +62 -87
- 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 +13 -11
- package/dist/types/private/field-list.d.ts +14 -21
- package/dist/types/private/field-wrapper.d.ts +4 -10
- package/dist/types/private/field.d.ts +12 -12
- package/dist/types/private/json-format-common.d.ts +5 -27
- package/dist/types/private/message-type.d.ts +12 -7
- 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 +34 -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 +36 -56
- package/dist/types/type-registry.d.ts +13 -15
- package/package.json +2 -3
|
@@ -43,34 +43,34 @@
|
|
|
43
43
|
* See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175
|
|
44
44
|
*/
|
|
45
45
|
export function varint64read() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
let lowBits = 0;
|
|
47
|
+
let highBits = 0;
|
|
48
|
+
for (let shift = 0; shift < 28; shift += 7) {
|
|
49
|
+
let b = this.buf[this.pos++];
|
|
50
|
+
lowBits |= (b & 0x7f) << shift;
|
|
51
|
+
if ((b & 0x80) == 0) {
|
|
52
|
+
this.assertBounds();
|
|
53
|
+
return [lowBits, highBits];
|
|
54
|
+
}
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
let middleByte = this.buf[this.pos++];
|
|
57
|
+
// last four bits of the first 32 bit number
|
|
58
|
+
lowBits |= (middleByte & 0x0f) << 28;
|
|
59
|
+
// 3 upper bits are part of the next 32 bit number
|
|
60
|
+
highBits = (middleByte & 0x70) >> 4;
|
|
61
|
+
if ((middleByte & 0x80) == 0) {
|
|
62
|
+
this.assertBounds();
|
|
63
|
+
return [lowBits, highBits];
|
|
64
|
+
}
|
|
65
|
+
for (let shift = 3; shift <= 31; shift += 7) {
|
|
66
|
+
let b = this.buf[this.pos++];
|
|
67
|
+
highBits |= (b & 0x7f) << shift;
|
|
68
|
+
if ((b & 0x80) == 0) {
|
|
69
|
+
this.assertBounds();
|
|
70
|
+
return [lowBits, highBits];
|
|
71
|
+
}
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
-
throw new Error("invalid varint");
|
|
73
|
+
throw new Error("invalid varint");
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Write a 64 bit varint, given as two JS numbers, to the given bytes array.
|
|
@@ -80,31 +80,31 @@ export function varint64read() {
|
|
|
80
80
|
* See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
|
|
81
81
|
*/
|
|
82
82
|
export function varint64write(lo, hi, bytes) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
for (let i = 0; i < 28; i = i + 7) {
|
|
84
|
+
const shift = lo >>> i;
|
|
85
|
+
const hasNext = !(shift >>> 7 == 0 && hi == 0);
|
|
86
|
+
const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
|
|
87
|
+
bytes.push(byte);
|
|
88
|
+
if (!hasNext) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const splitBits = ((lo >>> 28) & 0x0f) | ((hi & 0x07) << 4);
|
|
93
|
+
const hasMoreBits = !(hi >> 3 == 0);
|
|
94
|
+
bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xff);
|
|
95
|
+
if (!hasMoreBits) {
|
|
96
|
+
return;
|
|
90
97
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const shift = hi >>> i;
|
|
100
|
-
const hasNext = !(shift >>> 7 == 0);
|
|
101
|
-
const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
|
|
102
|
-
bytes.push(byte);
|
|
103
|
-
if (!hasNext) {
|
|
104
|
-
return;
|
|
98
|
+
for (let i = 3; i < 31; i = i + 7) {
|
|
99
|
+
const shift = hi >>> i;
|
|
100
|
+
const hasNext = !(shift >>> 7 == 0);
|
|
101
|
+
const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
|
|
102
|
+
bytes.push(byte);
|
|
103
|
+
if (!hasNext) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
-
bytes.push((hi >>> 31) & 0x01);
|
|
107
|
+
bytes.push((hi >>> 31) & 0x01);
|
|
108
108
|
}
|
|
109
109
|
// constants for binary math
|
|
110
110
|
const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
|
|
@@ -119,31 +119,32 @@ const TWO_PWR_32_DBL = (1 << 16) * (1 << 16);
|
|
|
119
119
|
* Copyright 2008 Google Inc.
|
|
120
120
|
*/
|
|
121
121
|
export function int64fromString(dec) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
122
|
+
// Check for minus sign.
|
|
123
|
+
let minus = dec[0] == "-";
|
|
124
|
+
if (minus)
|
|
125
|
+
dec = dec.slice(1);
|
|
126
|
+
// Work 6 decimal digits at a time, acting like we're converting base 1e6
|
|
127
|
+
// digits to binary. This is safe to do with floating point math because
|
|
128
|
+
// Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
|
|
129
|
+
const base = 1e6;
|
|
130
|
+
let lowBits = 0;
|
|
131
|
+
let highBits = 0;
|
|
132
|
+
function add1e6digit(begin, end) {
|
|
133
|
+
// Note: Number('') is 0.
|
|
134
|
+
const digit1e6 = Number(dec.slice(begin, end));
|
|
135
|
+
highBits *= base;
|
|
136
|
+
lowBits = lowBits * base + digit1e6;
|
|
137
|
+
// Carry bits from lowBits to
|
|
138
|
+
if (lowBits >= TWO_PWR_32_DBL) {
|
|
139
|
+
highBits = highBits + ((lowBits / TWO_PWR_32_DBL) | 0);
|
|
140
|
+
lowBits = lowBits % TWO_PWR_32_DBL;
|
|
141
|
+
}
|
|
140
142
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return [minus, lowBits, highBits];
|
|
143
|
+
add1e6digit(-24, -18);
|
|
144
|
+
add1e6digit(-18, -12);
|
|
145
|
+
add1e6digit(-12, -6);
|
|
146
|
+
add1e6digit(-6);
|
|
147
|
+
return [minus, lowBits, highBits];
|
|
147
148
|
}
|
|
148
149
|
/**
|
|
149
150
|
* Format 64 bit integer value (as two JS numbers) to decimal string.
|
|
@@ -151,54 +152,52 @@ export function int64fromString(dec) {
|
|
|
151
152
|
* Copyright 2008 Google Inc.
|
|
152
153
|
*/
|
|
153
154
|
export function int64toString(bitsLow, bitsHigh) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
// What this code is doing is essentially converting the input number from
|
|
160
|
-
// base-2 to base-1e7, which allows us to represent the 64-bit range with
|
|
161
|
-
// only 3 (very large) digits. Those digits are then trivial to convert to
|
|
162
|
-
// a base-10 string.
|
|
163
|
-
// The magic numbers used here are -
|
|
164
|
-
// 2^24 = 16777216 = (1,6777216) in base-1e7.
|
|
165
|
-
// 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
|
|
166
|
-
// Split 32:32 representation into 16:24:24 representation so our
|
|
167
|
-
// intermediate digits don't overflow.
|
|
168
|
-
let low = bitsLow & 0xffffff;
|
|
169
|
-
let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xffffff;
|
|
170
|
-
let high = (bitsHigh >> 16) & 0xffff;
|
|
171
|
-
// Assemble our three base-1e7 digits, ignoring carries. The maximum
|
|
172
|
-
// value in a digit at this step is representable as a 48-bit integer, which
|
|
173
|
-
// can be stored in a 64-bit floating point number.
|
|
174
|
-
let digitA = low + mid * 6777216 + high * 6710656;
|
|
175
|
-
let digitB = mid + high * 8147497;
|
|
176
|
-
let digitC = high * 2;
|
|
177
|
-
// Apply carries from A to B and from B to C.
|
|
178
|
-
let base = 10000000;
|
|
179
|
-
if (digitA >= base) {
|
|
180
|
-
digitB += Math.floor(digitA / base);
|
|
181
|
-
digitA %= base;
|
|
182
|
-
}
|
|
183
|
-
if (digitB >= base) {
|
|
184
|
-
digitC += Math.floor(digitB / base);
|
|
185
|
-
digitB %= base;
|
|
186
|
-
}
|
|
187
|
-
// Convert base-1e7 digits to base-10, with optional leading zeroes.
|
|
188
|
-
function decimalFrom1e7(digit1e7, needLeadingZeros) {
|
|
189
|
-
let partial = digit1e7 ? String(digit1e7) : "";
|
|
190
|
-
if (needLeadingZeros) {
|
|
191
|
-
return "0000000".slice(partial.length) + partial;
|
|
155
|
+
// Skip the expensive conversion if the number is small enough to use the
|
|
156
|
+
// built-in conversions.
|
|
157
|
+
if (bitsHigh <= 0x1fffff) {
|
|
158
|
+
return "" + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
|
|
192
159
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
160
|
+
// What this code is doing is essentially converting the input number from
|
|
161
|
+
// base-2 to base-1e7, which allows us to represent the 64-bit range with
|
|
162
|
+
// only 3 (very large) digits. Those digits are then trivial to convert to
|
|
163
|
+
// a base-10 string.
|
|
164
|
+
// The magic numbers used here are -
|
|
165
|
+
// 2^24 = 16777216 = (1,6777216) in base-1e7.
|
|
166
|
+
// 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
|
|
167
|
+
// Split 32:32 representation into 16:24:24 representation so our
|
|
168
|
+
// intermediate digits don't overflow.
|
|
169
|
+
let low = bitsLow & 0xffffff;
|
|
170
|
+
let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xffffff;
|
|
171
|
+
let high = (bitsHigh >> 16) & 0xffff;
|
|
172
|
+
// Assemble our three base-1e7 digits, ignoring carries. The maximum
|
|
173
|
+
// value in a digit at this step is representable as a 48-bit integer, which
|
|
174
|
+
// can be stored in a 64-bit floating point number.
|
|
175
|
+
let digitA = low + mid * 6777216 + high * 6710656;
|
|
176
|
+
let digitB = mid + high * 8147497;
|
|
177
|
+
let digitC = high * 2;
|
|
178
|
+
// Apply carries from A to B and from B to C.
|
|
179
|
+
let base = 10000000;
|
|
180
|
+
if (digitA >= base) {
|
|
181
|
+
digitB += Math.floor(digitA / base);
|
|
182
|
+
digitA %= base;
|
|
183
|
+
}
|
|
184
|
+
if (digitB >= base) {
|
|
185
|
+
digitC += Math.floor(digitB / base);
|
|
186
|
+
digitB %= base;
|
|
187
|
+
}
|
|
188
|
+
// Convert base-1e7 digits to base-10, with optional leading zeroes.
|
|
189
|
+
function decimalFrom1e7(digit1e7, needLeadingZeros) {
|
|
190
|
+
let partial = digit1e7 ? String(digit1e7) : "";
|
|
191
|
+
if (needLeadingZeros) {
|
|
192
|
+
return "0000000".slice(partial.length) + partial;
|
|
193
|
+
}
|
|
194
|
+
return partial;
|
|
195
|
+
}
|
|
196
|
+
return (decimalFrom1e7(digitC, /*needLeadingZeros=*/ 0) +
|
|
197
|
+
decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
|
|
198
|
+
// If the final 1e7 digit didn't need leading zeros, we would have
|
|
199
|
+
// returned via the trivial code path at the top.
|
|
200
|
+
decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1));
|
|
202
201
|
}
|
|
203
202
|
/**
|
|
204
203
|
* Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
|
|
@@ -208,20 +207,21 @@ export function int64toString(bitsLow, bitsHigh) {
|
|
|
208
207
|
* See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144
|
|
209
208
|
*/
|
|
210
209
|
export function varint32write(value, bytes) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
210
|
+
if (value >= 0) {
|
|
211
|
+
// write value as varint 32
|
|
212
|
+
while (value > 0x7f) {
|
|
213
|
+
bytes.push((value & 0x7f) | 0x80);
|
|
214
|
+
value = value >>> 7;
|
|
215
|
+
}
|
|
216
|
+
bytes.push(value);
|
|
216
217
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
else {
|
|
219
|
+
for (let i = 0; i < 9; i++) {
|
|
220
|
+
bytes.push((value & 127) | 128);
|
|
221
|
+
value = value >> 7;
|
|
222
|
+
}
|
|
223
|
+
bytes.push(1);
|
|
222
224
|
}
|
|
223
|
-
bytes.push(1);
|
|
224
|
-
}
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
227
|
* Read an unsigned 32 bit varint.
|
|
@@ -229,37 +229,38 @@ export function varint32write(value, bytes) {
|
|
|
229
229
|
* See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220
|
|
230
230
|
*/
|
|
231
231
|
export function varint32read() {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
b = this.buf[this.pos++];
|
|
239
|
-
result |= (b & 0x7f) << 7;
|
|
240
|
-
if ((b & 0x80) == 0) {
|
|
241
|
-
this.assertBounds();
|
|
242
|
-
return result;
|
|
243
|
-
}
|
|
244
|
-
b = this.buf[this.pos++];
|
|
245
|
-
result |= (b & 0x7f) << 14;
|
|
246
|
-
if ((b & 0x80) == 0) {
|
|
247
|
-
this.assertBounds();
|
|
248
|
-
return result;
|
|
249
|
-
}
|
|
250
|
-
b = this.buf[this.pos++];
|
|
251
|
-
result |= (b & 0x7f) << 21;
|
|
252
|
-
if ((b & 0x80) == 0) {
|
|
253
|
-
this.assertBounds();
|
|
254
|
-
return result;
|
|
255
|
-
}
|
|
256
|
-
// Extract only last 4 bits
|
|
257
|
-
b = this.buf[this.pos++];
|
|
258
|
-
result |= (b & 0x0f) << 28;
|
|
259
|
-
for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++)
|
|
232
|
+
let b = this.buf[this.pos++];
|
|
233
|
+
let result = b & 0x7f;
|
|
234
|
+
if ((b & 0x80) == 0) {
|
|
235
|
+
this.assertBounds();
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
260
238
|
b = this.buf[this.pos++];
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
239
|
+
result |= (b & 0x7f) << 7;
|
|
240
|
+
if ((b & 0x80) == 0) {
|
|
241
|
+
this.assertBounds();
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
b = this.buf[this.pos++];
|
|
245
|
+
result |= (b & 0x7f) << 14;
|
|
246
|
+
if ((b & 0x80) == 0) {
|
|
247
|
+
this.assertBounds();
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
b = this.buf[this.pos++];
|
|
251
|
+
result |= (b & 0x7f) << 21;
|
|
252
|
+
if ((b & 0x80) == 0) {
|
|
253
|
+
this.assertBounds();
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
// Extract only last 4 bits
|
|
257
|
+
b = this.buf[this.pos++];
|
|
258
|
+
result |= (b & 0x0f) << 28;
|
|
259
|
+
for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++)
|
|
260
|
+
b = this.buf[this.pos++];
|
|
261
|
+
if ((b & 0x80) != 0)
|
|
262
|
+
throw new Error("invalid varint");
|
|
263
|
+
this.assertBounds();
|
|
264
|
+
// Result can have 32 bits, convert it to unsigned
|
|
265
|
+
return result >>> 0;
|
|
265
266
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
export { proto3 } from "./proto3.js";
|
|
2
15
|
export { proto2 } from "./proto2.js";
|
|
3
16
|
export { protoInt64 } from "./proto-int64.js";
|
|
4
|
-
export { Message } from "./message.js";
|
|
17
|
+
export { Message, } from "./message.js";
|
|
5
18
|
export { ScalarType } from "./field.js";
|
|
6
19
|
export { MethodKind, MethodIdempotency } from "./service-type.js";
|
|
7
20
|
export { TypeRegistry } from "./type-registry.js";
|
package/dist/esm/json-format.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
export {};
|
package/dist/esm/message-type.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
export {};
|
package/dist/esm/message.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
/**
|
|
2
15
|
* Message is the base class of every message, generated, or created at
|
|
3
16
|
* runtime.
|
|
@@ -6,89 +19,80 @@
|
|
|
6
19
|
* run time, use proto3.makeMessageType().
|
|
7
20
|
*/
|
|
8
21
|
export class Message {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
* the protobuf message declaration and provides metadata for reflection-
|
|
86
|
-
* based operations.
|
|
87
|
-
*/
|
|
88
|
-
getType() {
|
|
89
|
-
// Any class that extends Message _must_ provide a complete static
|
|
90
|
-
// implementation of MessageType.
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
|
92
|
-
return Object.getPrototypeOf(this).constructor;
|
|
93
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* Compare with a message of the same type.
|
|
24
|
+
*/
|
|
25
|
+
equals(other) {
|
|
26
|
+
return this.getType().runtime.util.equals(this.getType(), this, other);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a deep copy.
|
|
30
|
+
*/
|
|
31
|
+
clone() {
|
|
32
|
+
// return this.getType().runtime.util.clone(this);
|
|
33
|
+
return this.getType().runtime.util.clone(this);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parse from binary data, merging fields.
|
|
37
|
+
*
|
|
38
|
+
* Repeated fields are appended. Map entries are added, overwriting
|
|
39
|
+
* existing keys.
|
|
40
|
+
*
|
|
41
|
+
* If a message field is already present, it will be merged with the
|
|
42
|
+
* new data.
|
|
43
|
+
*/
|
|
44
|
+
fromBinary(bytes, options) {
|
|
45
|
+
const type = this.getType(), format = type.runtime.bin, opt = format.makeReadOptions(options);
|
|
46
|
+
format.readMessage(this, opt.readerFactory(bytes), bytes.byteLength, opt);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse a message from a JSON value.
|
|
51
|
+
*/
|
|
52
|
+
fromJson(jsonValue, options) {
|
|
53
|
+
const type = this.getType(), format = type.runtime.json, opt = format.makeReadOptions(options);
|
|
54
|
+
format.readMessage(type, jsonValue, opt, this);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse a message from a JSON string.
|
|
59
|
+
*/
|
|
60
|
+
fromJsonString(jsonString, options) {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- assigning to JsonValue is safe here
|
|
62
|
+
return this.fromJson(JSON.parse(jsonString), options);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Serialize the message to binary data.
|
|
66
|
+
*/
|
|
67
|
+
toBinary(options) {
|
|
68
|
+
const type = this.getType(), bin = type.runtime.bin, opt = bin.makeWriteOptions(options), writer = opt.writerFactory();
|
|
69
|
+
bin.writeMessage(this, writer, opt);
|
|
70
|
+
return writer.finish();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Serialize the message to a JSON value, a JavaScript value that can be
|
|
74
|
+
* passed to JSON.stringify().
|
|
75
|
+
*/
|
|
76
|
+
toJson(options) {
|
|
77
|
+
const type = this.getType(), json = type.runtime.json, opt = json.makeWriteOptions(options);
|
|
78
|
+
return json.writeMessage(this, opt);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Serialize the message to a JSON string.
|
|
82
|
+
*/
|
|
83
|
+
toJsonString(options) {
|
|
84
|
+
const value = this.toJson(options);
|
|
85
|
+
return JSON.stringify(value, null, options?.prettySpaces ?? 0);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Retrieve the MessageType of this message - a singleton that represents
|
|
89
|
+
* the protobuf message declaration and provides metadata for reflection-
|
|
90
|
+
* based operations.
|
|
91
|
+
*/
|
|
92
|
+
getType() {
|
|
93
|
+
// Any class that extends Message _must_ provide a complete static
|
|
94
|
+
// implementation of MessageType.
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
|
96
|
+
return Object.getPrototypeOf(this).constructor;
|
|
97
|
+
}
|
|
94
98
|
}
|