Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/wire/binary-encoding.d.ts

raw
1 /**
2 * Protobuf binary format wire types.
3 *
4 * A wire type provides just enough information to find the length of the
5 * following value.
6 *
7 * See https://developers.google.com/protocol-buffers/docs/encoding#structure
8 */
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 * Start of a tag-delimited aggregate, such as a proto2 group, or a message
29 * in editions with message_encoding = DELIMITED.
30 */
31 StartGroup = 3,
32 /**
33 * End of a tag-delimited aggregate.
34 */
35 EndGroup = 4,
36 /**
37 * Used for fixed32, sfixed32, float.
38 * Always 4 bytes with little-endian byte order.
39 */
40 Bit32 = 5
41 }
42 /**
43 * Maximum value for a 32-bit floating point value (Protobuf FLOAT).
44 */
45 export declare const FLOAT32_MAX = 3.4028234663852886e+38;
46 /**
47 * Minimum value for a 32-bit floating point value (Protobuf FLOAT).
48 */
49 export declare const FLOAT32_MIN = -3.4028234663852886e+38;
50 /**
51 * Maximum value for an unsigned 32-bit integer (Protobuf UINT32, FIXED32).
52 */
53 export declare const UINT32_MAX = 4294967295;
54 /**
55 * Maximum value for a signed 32-bit integer (Protobuf INT32, SFIXED32, SINT32).
56 */
57 export declare const INT32_MAX = 2147483647;
58 /**
59 * Minimum value for a signed 32-bit integer (Protobuf INT32, SFIXED32, SINT32).
60 */
61 export declare const INT32_MIN = -2147483648;
62 export declare class BinaryWriter {
63 /**
64 * Growable byte buffer. We allocate a reasonably sized
65 * initial buffer and double its capacity when needed.
66 */
67 private buffer;
68 /**
69 * Cached DataView for fixed-width writes. Read it via `view()`, which
70 * rebuilds it if `buffer` has since grown.
71 */
72 private viewCache;
73 /**
74 * Current write position in the buffer.
75 */
76 private pos;
77 /**
78 * Previous fork positions (the write position at the time
79 * `fork()` was called).
80 */
81 private stackPos;
82 /**
83 * UTF-8 codec used by `string()`. Uses the text encoding's `encodeUtf8Into`,
84 * or emulates it if a custom `encodeUtf8` was passed to the constructor.
85 */
86 private readonly encodeUtf8Into;
87 constructor(encodeUtf8?: (text: string) => Uint8Array);
88 private ensureCapacity;
89 /**
90 * The DataView over `buffer`, rebuilt only if the buffer has grown since it
91 * was last used.
92 */
93 private view;
94 /**
95 * Return all bytes written and reset this writer.
96 */
97 finish(): Uint8Array<ArrayBuffer>;
98 /**
99 * Start a new fork for length-delimited data like a message
100 * or a packed repeated field.
101 *
102 * Must be joined later with `join()`.
103 */
104 fork(): this;
105 /**
106 * Join the last fork. Write its length and bytes, then
107 * return to the previous state.
108 */
109 join(): this;
110 /**
111 * Writes a tag (field number and wire type).
112 *
113 * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`.
114 *
115 * Generated code should compute the tag ahead of time and call `uint32()`.
116 */
117 tag(fieldNo: number, type: WireType): this;
118 /**
119 * Write a chunk of raw bytes.
120 */
121 raw(chunk: Uint8Array): this;
122 /**
123 * Write a `uint32` value, an unsigned 32 bit varint.
124 */
125 uint32(value: number): this;
126 /**
127 * Write a `int32` value, a signed 32 bit varint.
128 */
129 int32(value: number): this;
130 /**
131 * Write a `bool` value, a varint.
132 */
133 bool(value: boolean): this;
134 /**
135 * Write a `bytes` value, length-delimited arbitrary data.
136 */
137 bytes(value: Uint8Array): this;
138 /**
139 * Write a `string` value, length-delimited data converted to UTF-8 text.
140 */
141 string(value: string): this;
142 /**
143 * Write a `float` value, 32-bit floating point number.
144 */
145 float(value: number): this;
146 /**
147 * Write a `double` value, a 64-bit floating point number.
148 */
149 double(value: number): this;
150 /**
151 * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
152 */
153 fixed32(value: number): this;
154 /**
155 * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
156 */
157 sfixed32(value: number): this;
158 /**
159 * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
160 */
161 sint32(value: number): this;
162 /**
163 * Write a `sfixed64` value, a signed, fixed-length 64-bit integer.
164 */
165 sfixed64(value: string | number | bigint): this;
166 /**
167 * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
168 */
169 fixed64(value: string | number | bigint): this;
170 /**
171 * Write a `int64` value, a signed 64-bit varint.
172 */
173 int64(value: string | number | bigint): this;
174 /**
175 * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
176 */
177 sint64(value: string | number | bigint): this;
178 /**
179 * Write a `uint64` value, an unsigned 64-bit varint.
180 */
181 uint64(value: string | number | bigint): this;
182 /**
183 * Write a 64-bit varint directly into the buffer. Accepts the value as
184 * split low/high 32-bit words.
185 *
186 * Ported from varint64write() to avoid the intermediate number[] buffer.
187 * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
188 */
189 private writeVarint64;
190 }
191 export declare class BinaryReader {
192 private readonly decodeUtf8;
193 /**
194 * Current position.
195 */
196 pos: number;
197 /**
198 * Number of bytes available in this reader.
199 */
200 readonly len: number;
201 private readonly buf;
202 private readonly view;
203 constructor(buf: Uint8Array, decodeUtf8?: (bytes: Uint8Array, strict?: boolean) => string);
204 /**
205 * Reads a tag - field number and wire type. Tags are uint32 varints; values
206 * that do not fit in uint32 are rejected.
207 */
208 tag(): [number, WireType];
209 /**
210 * Skip one element and return the skipped data.
211 *
212 * When skipping StartGroup, provide the tags field number to check for
213 * matching field number in the EndGroup tag. Recursion into nested groups
214 * is guarded by the `recursionLimit` argument: When the limit is reached,
215 * this method throws.
216 */
217 skip(wireType: WireType, fieldNo?: number, recursionLimit?: number): Uint8Array;
218 private varint64Lo;
219 private varint64Hi;
220 private varint64;
221 /**
222 * Throws error if position in byte array is out of range.
223 */
224 private assertBounds;
225 /**
226 * Read a `uint32` field, an unsigned 32 bit varint.
227 */
228 uint32: () => number;
229 /**
230 * Read a `int32` field, a signed 32 bit varint.
231 */
232 int32(): number;
233 /**
234 * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
235 */
236 sint32(): number;
237 /**
238 * Read a `int64` field, a signed 64-bit varint.
239 */
240 int64(): bigint | string;
241 /**
242 * Read a `uint64` field, an unsigned 64-bit varint.
243 */
244 uint64(): bigint | string;
245 /**
246 * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
247 */
248 sint64(): bigint | string;
249 /**
250 * Read a `bool` field, a variant.
251 */
252 bool(): boolean;
253 /**
254 * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
255 */
256 fixed32(): number;
257 /**
258 * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
259 */
260 sfixed32(): number;
261 /**
262 * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
263 */
264 fixed64(): bigint | string;
265 /**
266 * Read a `fixed64` field, a signed, fixed-length 64-bit integer.
267 */
268 sfixed64(): bigint | string;
269 /**
270 * Read a `float` field, 32-bit floating point number.
271 */
272 float(): number;
273 /**
274 * Read a `double` field, a 64-bit floating point number.
275 */
276 double(): number;
277 /**
278 * Read a `bytes` field, length-delimited arbitrary data.
279 */
280 bytes(): Uint8Array;
281 /**
282 * Read a `string` field, length-delimited data converted to UTF-8 text. If
283 * `strict` is true, throw on invalid UTF-8 instead of substituting U+FFFD.
284 */
285 string(strict?: boolean): string;
286 }