@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.
Files changed (127) hide show
  1. package/README.md +21 -1
  2. package/dist/cjs/binary-encoding.js +402 -410
  3. package/dist/cjs/descriptor-registry.js +407 -449
  4. package/dist/cjs/descriptor-set.js +416 -513
  5. package/dist/cjs/field.js +30 -30
  6. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  7. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  8. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  9. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  10. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  11. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  12. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  13. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  14. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  15. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  16. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  17. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  18. package/dist/cjs/index.js +24 -122
  19. package/dist/cjs/message.js +81 -89
  20. package/dist/cjs/private/assert.js +20 -26
  21. package/dist/cjs/private/base64.js +79 -78
  22. package/dist/cjs/private/binary-format-common.js +195 -208
  23. package/dist/cjs/private/binary-format-proto2.js +75 -109
  24. package/dist/cjs/private/binary-format-proto3.js +57 -90
  25. package/dist/cjs/private/enum.js +38 -43
  26. package/dist/cjs/private/field-list.js +51 -50
  27. package/dist/cjs/private/field-wrapper.js +8 -10
  28. package/dist/cjs/private/field.js +22 -25
  29. package/dist/cjs/private/goog-varint.js +275 -0
  30. package/dist/cjs/private/json-format-common.js +414 -440
  31. package/dist/cjs/private/json-format-proto2.js +78 -89
  32. package/dist/cjs/private/json-format-proto3.js +69 -93
  33. package/dist/cjs/private/message-type.js +26 -27
  34. package/dist/cjs/private/names.js +58 -62
  35. package/dist/cjs/private/proto-runtime.js +11 -16
  36. package/dist/cjs/private/scalars.js +100 -103
  37. package/dist/cjs/private/util-common.js +180 -210
  38. package/dist/cjs/proto-int64.js +111 -112
  39. package/dist/cjs/proto2.js +50 -63
  40. package/dist/cjs/proto3.js +61 -74
  41. package/dist/cjs/service-type.js +14 -17
  42. package/dist/cjs/type-registry.js +33 -31
  43. package/dist/esm/binary-encoding.js +401 -414
  44. package/dist/esm/descriptor-registry.js +409 -458
  45. package/dist/esm/descriptor-set.js +417 -478
  46. package/dist/esm/field.js +29 -29
  47. package/dist/esm/google/protobuf/any_pb.js +122 -140
  48. package/dist/esm/google/protobuf/api_pb.js +177 -197
  49. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  50. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  51. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  52. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  53. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  54. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  55. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  56. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  57. package/dist/esm/google/protobuf/type_pb.js +401 -421
  58. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  59. package/dist/esm/index.js +1 -1
  60. package/dist/esm/message.js +81 -89
  61. package/dist/esm/private/assert.js +19 -21
  62. package/dist/esm/private/base64.js +79 -78
  63. package/dist/esm/private/binary-format-common.js +196 -207
  64. package/dist/esm/private/binary-format-proto2.js +76 -81
  65. package/dist/esm/private/binary-format-proto3.js +58 -67
  66. package/dist/esm/private/enum.js +38 -43
  67. package/dist/esm/private/field-list.js +51 -50
  68. package/dist/esm/private/field-wrapper.js +8 -10
  69. package/dist/esm/private/field.js +22 -22
  70. package/dist/esm/private/goog-varint.js +266 -0
  71. package/dist/esm/private/json-format-common.js +414 -435
  72. package/dist/esm/private/json-format-proto2.js +76 -81
  73. package/dist/esm/private/json-format-proto3.js +66 -80
  74. package/dist/esm/private/message-type.js +27 -28
  75. package/dist/esm/private/names.js +57 -57
  76. package/dist/esm/private/proto-runtime.js +11 -11
  77. package/dist/esm/private/scalars.js +99 -99
  78. package/dist/esm/private/util-common.js +180 -192
  79. package/dist/esm/proto-int64.js +111 -112
  80. package/dist/esm/proto2.js +50 -57
  81. package/dist/esm/proto3.js +61 -68
  82. package/dist/esm/service-type.js +12 -12
  83. package/dist/esm/type-registry.js +33 -31
  84. package/dist/types/binary-encoding.d.ts +398 -398
  85. package/dist/types/binary-format.d.ts +69 -91
  86. package/dist/types/descriptor-registry.d.ts +23 -29
  87. package/dist/types/descriptor-set.d.ts +107 -128
  88. package/dist/types/enum.d.ts +21 -21
  89. package/dist/types/field-list.d.ts +21 -21
  90. package/dist/types/field.d.ts +191 -231
  91. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  92. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  93. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  94. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  95. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  96. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  97. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  98. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  99. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  100. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  101. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  102. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  103. package/dist/types/index.d.ts +4 -27
  104. package/dist/types/json-format.d.ts +70 -89
  105. package/dist/types/message-type.d.ts +38 -46
  106. package/dist/types/message.d.ts +73 -99
  107. package/dist/types/private/assert.d.ts +1 -4
  108. package/dist/types/private/binary-format-common.d.ts +6 -32
  109. package/dist/types/private/enum.d.ts +4 -11
  110. package/dist/types/private/field-list.d.ts +14 -21
  111. package/dist/types/private/field-wrapper.d.ts +5 -11
  112. package/dist/types/private/field.d.ts +12 -12
  113. package/dist/types/{google/varint.d.ts → private/goog-varint.d.ts} +6 -13
  114. package/dist/types/private/json-format-common.d.ts +5 -27
  115. package/dist/types/private/message-type.d.ts +3 -8
  116. package/dist/types/private/names.d.ts +1 -4
  117. package/dist/types/private/options-map.d.ts +1 -1
  118. package/dist/types/private/proto-runtime.d.ts +29 -42
  119. package/dist/types/private/scalars.d.ts +5 -12
  120. package/dist/types/private/util-common.d.ts +1 -4
  121. package/dist/types/private/util.d.ts +29 -41
  122. package/dist/types/proto-int64.d.ts +42 -42
  123. package/dist/types/service-type.d.ts +37 -57
  124. package/dist/types/type-registry.d.ts +13 -15
  125. package/package.json +2 -2
  126. package/dist/cjs/google/varint.js +0 -280
  127. package/dist/esm/google/varint.js +0 -265
@@ -7,415 +7,415 @@
7
7
  * See https://developers.google.com/protocol-buffers/docs/encoding#structure
8
8
  */
9
9
  export declare enum WireType {
10
- /**
11
- * Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum
12
- */
13
- Varint = 0,
14
- /**
15
- * Used for fixed64, sfixed64, double.
16
- * Always 8 bytes with little-endian byte order.
17
- */
18
- Bit64 = 1,
19
- /**
20
- * Used for string, bytes, embedded messages, packed repeated fields
21
- *
22
- * Only repeated numeric types (types which use the varint, 32-bit,
23
- * or 64-bit wire types) can be packed. In proto3, such fields are
24
- * packed by default.
25
- */
26
- LengthDelimited = 2,
27
- /**
28
- * Used for groups
29
- * @deprecated
30
- */
31
- StartGroup = 3,
32
- /**
33
- * Used for groups
34
- * @deprecated
35
- */
36
- EndGroup = 4,
37
- /**
38
- * Used for fixed32, sfixed32, float.
39
- * Always 4 bytes with little-endian byte order.
40
- */
41
- Bit32 = 5,
10
+ /**
11
+ * Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum
12
+ */
13
+ Varint = 0,
14
+ /**
15
+ * Used for fixed64, sfixed64, double.
16
+ * Always 8 bytes with little-endian byte order.
17
+ */
18
+ Bit64 = 1,
19
+ /**
20
+ * Used for string, bytes, embedded messages, packed repeated fields
21
+ *
22
+ * Only repeated numeric types (types which use the varint, 32-bit,
23
+ * or 64-bit wire types) can be packed. In proto3, such fields are
24
+ * packed by default.
25
+ */
26
+ LengthDelimited = 2,
27
+ /**
28
+ * Used for groups
29
+ * @deprecated
30
+ */
31
+ StartGroup = 3,
32
+ /**
33
+ * Used for groups
34
+ * @deprecated
35
+ */
36
+ EndGroup = 4,
37
+ /**
38
+ * Used for fixed32, sfixed32, float.
39
+ * Always 4 bytes with little-endian byte order.
40
+ */
41
+ Bit32 = 5
42
42
  }
43
43
  declare type TextEncoderLike = {
44
- encode(input?: string): Uint8Array;
44
+ encode(input?: string): Uint8Array;
45
45
  };
46
46
  declare type TextDecoderLike = {
47
- decode(input?: Uint8Array): string;
47
+ decode(input?: Uint8Array): string;
48
48
  };
49
49
  export interface IBinaryReader {
50
- /**
51
- * Current position.
52
- */
53
- readonly pos: number;
54
- /**
55
- * Number of bytes available in this reader.
56
- */
57
- readonly len: number;
58
- /**
59
- * Reads a tag - field number and wire type.
60
- */
61
- tag(): [number, WireType];
62
- /**
63
- * Skip one element on the wire and return the skipped data.
64
- */
65
- skip(wireType: WireType): Uint8Array;
66
- /**
67
- * Read a `int32` field, a signed 32 bit varint.
68
- */
69
- uint32(): number;
70
- /**
71
- * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
72
- */
73
- int32(): number;
74
- /**
75
- * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
76
- */
77
- sint32(): number;
78
- /**
79
- * Read a `int64` field, a signed 64-bit varint.
80
- */
81
- int64(): bigint | string;
82
- /**
83
- * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
84
- */
85
- sint64(): bigint | string;
86
- /**
87
- * Read a `fixed64` field, a signed, fixed-length 64-bit integer.
88
- */
89
- sfixed64(): bigint | string;
90
- /**
91
- * Read a `uint64` field, an unsigned 64-bit varint.
92
- */
93
- uint64(): bigint | string;
94
- /**
95
- * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
96
- */
97
- fixed64(): bigint | string;
98
- /**
99
- * Read a `bool` field, a variant.
100
- */
101
- bool(): boolean;
102
- /**
103
- * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
104
- */
105
- fixed32(): number;
106
- /**
107
- * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
108
- */
109
- sfixed32(): number;
110
- /**
111
- * Read a `float` field, 32-bit floating point number.
112
- */
113
- float(): number;
114
- /**
115
- * Read a `double` field, a 64-bit floating point number.
116
- */
117
- double(): number;
118
- /**
119
- * Read a `bytes` field, length-delimited arbitrary data.
120
- */
121
- bytes(): Uint8Array;
122
- /**
123
- * Read a `string` field, length-delimited data converted to UTF-8 text.
124
- */
125
- string(): string;
50
+ /**
51
+ * Current position.
52
+ */
53
+ readonly pos: number;
54
+ /**
55
+ * Number of bytes available in this reader.
56
+ */
57
+ readonly len: number;
58
+ /**
59
+ * Reads a tag - field number and wire type.
60
+ */
61
+ tag(): [number, WireType];
62
+ /**
63
+ * Skip one element on the wire and return the skipped data.
64
+ */
65
+ skip(wireType: WireType): Uint8Array;
66
+ /**
67
+ * Read a `int32` field, a signed 32 bit varint.
68
+ */
69
+ uint32(): number;
70
+ /**
71
+ * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
72
+ */
73
+ int32(): number;
74
+ /**
75
+ * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
76
+ */
77
+ sint32(): number;
78
+ /**
79
+ * Read a `int64` field, a signed 64-bit varint.
80
+ */
81
+ int64(): bigint | string;
82
+ /**
83
+ * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
84
+ */
85
+ sint64(): bigint | string;
86
+ /**
87
+ * Read a `fixed64` field, a signed, fixed-length 64-bit integer.
88
+ */
89
+ sfixed64(): bigint | string;
90
+ /**
91
+ * Read a `uint64` field, an unsigned 64-bit varint.
92
+ */
93
+ uint64(): bigint | string;
94
+ /**
95
+ * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
96
+ */
97
+ fixed64(): bigint | string;
98
+ /**
99
+ * Read a `bool` field, a variant.
100
+ */
101
+ bool(): boolean;
102
+ /**
103
+ * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
104
+ */
105
+ fixed32(): number;
106
+ /**
107
+ * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
108
+ */
109
+ sfixed32(): number;
110
+ /**
111
+ * Read a `float` field, 32-bit floating point number.
112
+ */
113
+ float(): number;
114
+ /**
115
+ * Read a `double` field, a 64-bit floating point number.
116
+ */
117
+ double(): number;
118
+ /**
119
+ * Read a `bytes` field, length-delimited arbitrary data.
120
+ */
121
+ bytes(): Uint8Array;
122
+ /**
123
+ * Read a `string` field, length-delimited data converted to UTF-8 text.
124
+ */
125
+ string(): string;
126
126
  }
127
127
  export interface IBinaryWriter {
128
- /**
129
- * Return all bytes written and reset this writer.
130
- */
131
- finish(): Uint8Array;
132
- /**
133
- * Start a new fork for length-delimited data like a message
134
- * or a packed repeated field.
135
- *
136
- * Must be joined later with `join()`.
137
- */
138
- fork(): IBinaryWriter;
139
- /**
140
- * Join the last fork. Write its length and bytes, then
141
- * return to the previous state.
142
- */
143
- join(): IBinaryWriter;
144
- /**
145
- * Writes a tag (field number and wire type).
146
- *
147
- * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`
148
- *
149
- * Generated code should compute the tag ahead of time and call `uint32()`.
150
- */
151
- tag(fieldNo: number, type: WireType): IBinaryWriter;
152
- /**
153
- * Write a chunk of raw bytes.
154
- */
155
- raw(chunk: Uint8Array): IBinaryWriter;
156
- /**
157
- * Write a `uint32` value, an unsigned 32 bit varint.
158
- */
159
- uint32(value: number): IBinaryWriter;
160
- /**
161
- * Write a `int32` value, a signed 32 bit varint.
162
- */
163
- int32(value: number): IBinaryWriter;
164
- /**
165
- * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
166
- */
167
- sint32(value: number): IBinaryWriter;
168
- /**
169
- * Write a `int64` value, a signed 64-bit varint.
170
- */
171
- int64(value: string | number | bigint): IBinaryWriter;
172
- /**
173
- * Write a `uint64` value, an unsigned 64-bit varint.
174
- */
175
- uint64(value: string | number | bigint): IBinaryWriter;
176
- /**
177
- * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
178
- */
179
- sint64(value: string | number | bigint): IBinaryWriter;
180
- /**
181
- * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
182
- */
183
- fixed64(value: string | number | bigint): IBinaryWriter;
184
- /**
185
- * Write a `fixed64` value, a signed, fixed-length 64-bit integer.
186
- */
187
- sfixed64(value: string | number | bigint): IBinaryWriter;
188
- /**
189
- * Write a `bool` value, a variant.
190
- */
191
- bool(value: boolean): IBinaryWriter;
192
- /**
193
- * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
194
- */
195
- fixed32(value: number): IBinaryWriter;
196
- /**
197
- * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
198
- */
199
- sfixed32(value: number): IBinaryWriter;
200
- /**
201
- * Write a `float` value, 32-bit floating point number.
202
- */
203
- float(value: number): IBinaryWriter;
204
- /**
205
- * Write a `double` value, a 64-bit floating point number.
206
- */
207
- double(value: number): IBinaryWriter;
208
- /**
209
- * Write a `bytes` value, length-delimited arbitrary data.
210
- */
211
- bytes(value: Uint8Array): IBinaryWriter;
212
- /**
213
- * Write a `string` value, length-delimited data converted to UTF-8 text.
214
- */
215
- string(value: string): IBinaryWriter;
128
+ /**
129
+ * Return all bytes written and reset this writer.
130
+ */
131
+ finish(): Uint8Array;
132
+ /**
133
+ * Start a new fork for length-delimited data like a message
134
+ * or a packed repeated field.
135
+ *
136
+ * Must be joined later with `join()`.
137
+ */
138
+ fork(): IBinaryWriter;
139
+ /**
140
+ * Join the last fork. Write its length and bytes, then
141
+ * return to the previous state.
142
+ */
143
+ join(): IBinaryWriter;
144
+ /**
145
+ * Writes a tag (field number and wire type).
146
+ *
147
+ * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`
148
+ *
149
+ * Generated code should compute the tag ahead of time and call `uint32()`.
150
+ */
151
+ tag(fieldNo: number, type: WireType): IBinaryWriter;
152
+ /**
153
+ * Write a chunk of raw bytes.
154
+ */
155
+ raw(chunk: Uint8Array): IBinaryWriter;
156
+ /**
157
+ * Write a `uint32` value, an unsigned 32 bit varint.
158
+ */
159
+ uint32(value: number): IBinaryWriter;
160
+ /**
161
+ * Write a `int32` value, a signed 32 bit varint.
162
+ */
163
+ int32(value: number): IBinaryWriter;
164
+ /**
165
+ * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
166
+ */
167
+ sint32(value: number): IBinaryWriter;
168
+ /**
169
+ * Write a `int64` value, a signed 64-bit varint.
170
+ */
171
+ int64(value: string | number | bigint): IBinaryWriter;
172
+ /**
173
+ * Write a `uint64` value, an unsigned 64-bit varint.
174
+ */
175
+ uint64(value: string | number | bigint): IBinaryWriter;
176
+ /**
177
+ * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
178
+ */
179
+ sint64(value: string | number | bigint): IBinaryWriter;
180
+ /**
181
+ * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
182
+ */
183
+ fixed64(value: string | number | bigint): IBinaryWriter;
184
+ /**
185
+ * Write a `fixed64` value, a signed, fixed-length 64-bit integer.
186
+ */
187
+ sfixed64(value: string | number | bigint): IBinaryWriter;
188
+ /**
189
+ * Write a `bool` value, a variant.
190
+ */
191
+ bool(value: boolean): IBinaryWriter;
192
+ /**
193
+ * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
194
+ */
195
+ fixed32(value: number): IBinaryWriter;
196
+ /**
197
+ * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
198
+ */
199
+ sfixed32(value: number): IBinaryWriter;
200
+ /**
201
+ * Write a `float` value, 32-bit floating point number.
202
+ */
203
+ float(value: number): IBinaryWriter;
204
+ /**
205
+ * Write a `double` value, a 64-bit floating point number.
206
+ */
207
+ double(value: number): IBinaryWriter;
208
+ /**
209
+ * Write a `bytes` value, length-delimited arbitrary data.
210
+ */
211
+ bytes(value: Uint8Array): IBinaryWriter;
212
+ /**
213
+ * Write a `string` value, length-delimited data converted to UTF-8 text.
214
+ */
215
+ string(value: string): IBinaryWriter;
216
216
  }
217
217
  export declare class BinaryWriter implements IBinaryWriter {
218
- /**
219
- * We cannot allocate a buffer for the entire output
220
- * because we don't know it's size.
221
- *
222
- * So we collect smaller chunks of known size and
223
- * concat them later.
224
- *
225
- * Use `raw()` to push data to this array. It will flush
226
- * `buf` first.
227
- */
228
- private chunks;
229
- /**
230
- * A growing buffer for byte values. If you don't know
231
- * the size of the data you are writing, push to this
232
- * array.
233
- */
234
- protected buf: number[];
235
- /**
236
- * Previous fork states.
237
- */
238
- private stack;
239
- /**
240
- * Text encoder instance to convert UTF-8 to bytes.
241
- */
242
- private readonly textEncoder;
243
- constructor(textEncoder?: TextEncoderLike);
244
- /**
245
- * Return all bytes written and reset this writer.
246
- */
247
- finish(): Uint8Array;
248
- /**
249
- * Start a new fork for length-delimited data like a message
250
- * or a packed repeated field.
251
- *
252
- * Must be joined later with `join()`.
253
- */
254
- fork(): IBinaryWriter;
255
- /**
256
- * Join the last fork. Write its length and bytes, then
257
- * return to the previous state.
258
- */
259
- join(): IBinaryWriter;
260
- /**
261
- * Writes a tag (field number and wire type).
262
- *
263
- * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`.
264
- *
265
- * Generated code should compute the tag ahead of time and call `uint32()`.
266
- */
267
- tag(fieldNo: number, type: WireType): IBinaryWriter;
268
- /**
269
- * Write a chunk of raw bytes.
270
- */
271
- raw(chunk: Uint8Array): IBinaryWriter;
272
- /**
273
- * Write a `uint32` value, an unsigned 32 bit varint.
274
- */
275
- uint32(value: number): IBinaryWriter;
276
- /**
277
- * Write a `int32` value, a signed 32 bit varint.
278
- */
279
- int32(value: number): IBinaryWriter;
280
- /**
281
- * Write a `bool` value, a variant.
282
- */
283
- bool(value: boolean): IBinaryWriter;
284
- /**
285
- * Write a `bytes` value, length-delimited arbitrary data.
286
- */
287
- bytes(value: Uint8Array): IBinaryWriter;
288
- /**
289
- * Write a `string` value, length-delimited data converted to UTF-8 text.
290
- */
291
- string(value: string): IBinaryWriter;
292
- /**
293
- * Write a `float` value, 32-bit floating point number.
294
- */
295
- float(value: number): IBinaryWriter;
296
- /**
297
- * Write a `double` value, a 64-bit floating point number.
298
- */
299
- double(value: number): IBinaryWriter;
300
- /**
301
- * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
302
- */
303
- fixed32(value: number): IBinaryWriter;
304
- /**
305
- * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
306
- */
307
- sfixed32(value: number): IBinaryWriter;
308
- /**
309
- * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
310
- */
311
- sint32(value: number): IBinaryWriter;
312
- /**
313
- * Write a `fixed64` value, a signed, fixed-length 64-bit integer.
314
- */
315
- sfixed64(value: string | number | bigint): IBinaryWriter;
316
- /**
317
- * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
318
- */
319
- fixed64(value: string | number | bigint): IBinaryWriter;
320
- /**
321
- * Write a `int64` value, a signed 64-bit varint.
322
- */
323
- int64(value: string | number | bigint): IBinaryWriter;
324
- /**
325
- * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
326
- */
327
- sint64(value: string | number | bigint): IBinaryWriter;
328
- /**
329
- * Write a `uint64` value, an unsigned 64-bit varint.
330
- */
331
- uint64(value: string | number | bigint): IBinaryWriter;
218
+ /**
219
+ * We cannot allocate a buffer for the entire output
220
+ * because we don't know it's size.
221
+ *
222
+ * So we collect smaller chunks of known size and
223
+ * concat them later.
224
+ *
225
+ * Use `raw()` to push data to this array. It will flush
226
+ * `buf` first.
227
+ */
228
+ private chunks;
229
+ /**
230
+ * A growing buffer for byte values. If you don't know
231
+ * the size of the data you are writing, push to this
232
+ * array.
233
+ */
234
+ protected buf: number[];
235
+ /**
236
+ * Previous fork states.
237
+ */
238
+ private stack;
239
+ /**
240
+ * Text encoder instance to convert UTF-8 to bytes.
241
+ */
242
+ private readonly textEncoder;
243
+ constructor(textEncoder?: TextEncoderLike);
244
+ /**
245
+ * Return all bytes written and reset this writer.
246
+ */
247
+ finish(): Uint8Array;
248
+ /**
249
+ * Start a new fork for length-delimited data like a message
250
+ * or a packed repeated field.
251
+ *
252
+ * Must be joined later with `join()`.
253
+ */
254
+ fork(): IBinaryWriter;
255
+ /**
256
+ * Join the last fork. Write its length and bytes, then
257
+ * return to the previous state.
258
+ */
259
+ join(): IBinaryWriter;
260
+ /**
261
+ * Writes a tag (field number and wire type).
262
+ *
263
+ * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`.
264
+ *
265
+ * Generated code should compute the tag ahead of time and call `uint32()`.
266
+ */
267
+ tag(fieldNo: number, type: WireType): IBinaryWriter;
268
+ /**
269
+ * Write a chunk of raw bytes.
270
+ */
271
+ raw(chunk: Uint8Array): IBinaryWriter;
272
+ /**
273
+ * Write a `uint32` value, an unsigned 32 bit varint.
274
+ */
275
+ uint32(value: number): IBinaryWriter;
276
+ /**
277
+ * Write a `int32` value, a signed 32 bit varint.
278
+ */
279
+ int32(value: number): IBinaryWriter;
280
+ /**
281
+ * Write a `bool` value, a variant.
282
+ */
283
+ bool(value: boolean): IBinaryWriter;
284
+ /**
285
+ * Write a `bytes` value, length-delimited arbitrary data.
286
+ */
287
+ bytes(value: Uint8Array): IBinaryWriter;
288
+ /**
289
+ * Write a `string` value, length-delimited data converted to UTF-8 text.
290
+ */
291
+ string(value: string): IBinaryWriter;
292
+ /**
293
+ * Write a `float` value, 32-bit floating point number.
294
+ */
295
+ float(value: number): IBinaryWriter;
296
+ /**
297
+ * Write a `double` value, a 64-bit floating point number.
298
+ */
299
+ double(value: number): IBinaryWriter;
300
+ /**
301
+ * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
302
+ */
303
+ fixed32(value: number): IBinaryWriter;
304
+ /**
305
+ * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
306
+ */
307
+ sfixed32(value: number): IBinaryWriter;
308
+ /**
309
+ * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
310
+ */
311
+ sint32(value: number): IBinaryWriter;
312
+ /**
313
+ * Write a `fixed64` value, a signed, fixed-length 64-bit integer.
314
+ */
315
+ sfixed64(value: string | number | bigint): IBinaryWriter;
316
+ /**
317
+ * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
318
+ */
319
+ fixed64(value: string | number | bigint): IBinaryWriter;
320
+ /**
321
+ * Write a `int64` value, a signed 64-bit varint.
322
+ */
323
+ int64(value: string | number | bigint): IBinaryWriter;
324
+ /**
325
+ * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
326
+ */
327
+ sint64(value: string | number | bigint): IBinaryWriter;
328
+ /**
329
+ * Write a `uint64` value, an unsigned 64-bit varint.
330
+ */
331
+ uint64(value: string | number | bigint): IBinaryWriter;
332
332
  }
333
333
  export declare class BinaryReader implements IBinaryReader {
334
- /**
335
- * Current position.
336
- */
337
- pos: number;
338
- /**
339
- * Number of bytes available in this reader.
340
- */
341
- readonly len: number;
342
- private readonly buf;
343
- private readonly view;
344
- private readonly textDecoder;
345
- constructor(buf: Uint8Array, textDecoder?: TextDecoderLike);
346
- /**
347
- * Reads a tag - field number and wire type.
348
- */
349
- tag(): [number, WireType];
350
- /**
351
- * Skip one element on the wire and return the skipped data.
352
- * Supports WireType.StartGroup since v2.0.0-alpha.23.
353
- */
354
- skip(wireType: WireType): Uint8Array;
355
- protected varint64: () => [number, number];
356
- /**
357
- * Throws error if position in byte array is out of range.
358
- */
359
- protected assertBounds(): void;
360
- /**
361
- * Read a `uint32` field, an unsigned 32 bit varint.
362
- */
363
- uint32: () => number;
364
- /**
365
- * Read a `int32` field, a signed 32 bit varint.
366
- */
367
- int32(): number;
368
- /**
369
- * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
370
- */
371
- sint32(): number;
372
- /**
373
- * Read a `int64` field, a signed 64-bit varint.
374
- */
375
- int64(): bigint | string;
376
- /**
377
- * Read a `uint64` field, an unsigned 64-bit varint.
378
- */
379
- uint64(): bigint | string;
380
- /**
381
- * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
382
- */
383
- sint64(): bigint | string;
384
- /**
385
- * Read a `bool` field, a variant.
386
- */
387
- bool(): boolean;
388
- /**
389
- * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
390
- */
391
- fixed32(): number;
392
- /**
393
- * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
394
- */
395
- sfixed32(): number;
396
- /**
397
- * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
398
- */
399
- fixed64(): bigint | string;
400
- /**
401
- * Read a `fixed64` field, a signed, fixed-length 64-bit integer.
402
- */
403
- sfixed64(): bigint | string;
404
- /**
405
- * Read a `float` field, 32-bit floating point number.
406
- */
407
- float(): number;
408
- /**
409
- * Read a `double` field, a 64-bit floating point number.
410
- */
411
- double(): number;
412
- /**
413
- * Read a `bytes` field, length-delimited arbitrary data.
414
- */
415
- bytes(): Uint8Array;
416
- /**
417
- * Read a `string` field, length-delimited data converted to UTF-8 text.
418
- */
419
- string(): string;
334
+ /**
335
+ * Current position.
336
+ */
337
+ pos: number;
338
+ /**
339
+ * Number of bytes available in this reader.
340
+ */
341
+ readonly len: number;
342
+ private readonly buf;
343
+ private readonly view;
344
+ private readonly textDecoder;
345
+ constructor(buf: Uint8Array, textDecoder?: TextDecoderLike);
346
+ /**
347
+ * Reads a tag - field number and wire type.
348
+ */
349
+ tag(): [number, WireType];
350
+ /**
351
+ * Skip one element on the wire and return the skipped data.
352
+ * Supports WireType.StartGroup since v2.0.0-alpha.23.
353
+ */
354
+ skip(wireType: WireType): Uint8Array;
355
+ protected varint64: () => [number, number];
356
+ /**
357
+ * Throws error if position in byte array is out of range.
358
+ */
359
+ protected assertBounds(): void;
360
+ /**
361
+ * Read a `uint32` field, an unsigned 32 bit varint.
362
+ */
363
+ uint32: () => number;
364
+ /**
365
+ * Read a `int32` field, a signed 32 bit varint.
366
+ */
367
+ int32(): number;
368
+ /**
369
+ * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
370
+ */
371
+ sint32(): number;
372
+ /**
373
+ * Read a `int64` field, a signed 64-bit varint.
374
+ */
375
+ int64(): bigint | string;
376
+ /**
377
+ * Read a `uint64` field, an unsigned 64-bit varint.
378
+ */
379
+ uint64(): bigint | string;
380
+ /**
381
+ * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
382
+ */
383
+ sint64(): bigint | string;
384
+ /**
385
+ * Read a `bool` field, a variant.
386
+ */
387
+ bool(): boolean;
388
+ /**
389
+ * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
390
+ */
391
+ fixed32(): number;
392
+ /**
393
+ * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
394
+ */
395
+ sfixed32(): number;
396
+ /**
397
+ * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
398
+ */
399
+ fixed64(): bigint | string;
400
+ /**
401
+ * Read a `fixed64` field, a signed, fixed-length 64-bit integer.
402
+ */
403
+ sfixed64(): bigint | string;
404
+ /**
405
+ * Read a `float` field, 32-bit floating point number.
406
+ */
407
+ float(): number;
408
+ /**
409
+ * Read a `double` field, a 64-bit floating point number.
410
+ */
411
+ double(): number;
412
+ /**
413
+ * Read a `bytes` field, length-delimited arbitrary data.
414
+ */
415
+ bytes(): Uint8Array;
416
+ /**
417
+ * Read a `string` field, length-delimited data converted to UTF-8 text.
418
+ */
419
+ string(): string;
420
420
  }
421
421
  export {};