Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/wire/size-delimited.d.ts

raw
1 import type { DescMessage } from "../descriptors.js";
2 import type { BinaryWriteOptions } from "../to-binary.js";
3 import type { MessageShape } from "../types.js";
4 import type { BinaryReadOptions } from "../from-binary.js";
5 /**
6 * Serialize a message, prefixing it with its size.
7 *
8 * A size-delimited message is a varint size in bytes, followed by exactly
9 * that many bytes of a message serialized with the binary format.
10 *
11 * This size-delimited format is compatible with other implementations.
12 * For details, see https://github.com/protocolbuffers/protobuf/issues/10229
13 */
14 export declare function sizeDelimitedEncode<Desc extends DescMessage>(messageDesc: Desc, message: MessageShape<Desc>, options?: BinaryWriteOptions): Uint8Array;
15 /**
16 * Options for parsing size-delimited messages from a stream.
17 */
18 export interface SizeDelimitedDecodeOptions extends BinaryReadOptions {
19 /**
20 * Limit the size of a single message in the stream, in bytes.
21 *
22 * If a message in the stream declares a size exceeding this limit, an
23 * error is raised before the message is buffered.
24 *
25 * The default limit is 64 MiB.
26 */
27 readMaxBytes: number;
28 }
29 /**
30 * Parse a stream of size-delimited messages.
31 *
32 * A size-delimited message is a varint size in bytes, followed by exactly
33 * that many bytes of a message serialized with the binary format.
34 *
35 * This size-delimited format is compatible with other implementations.
36 * For details, see https://github.com/protocolbuffers/protobuf/issues/10229
37 *
38 * Messages exceeding the limit given with the option readMaxBytes raise an
39 * error. The limit is 64 MiB by default. All other options are the
40 * standard binary read options, passed through to decode each message.
41 */
42 export declare function sizeDelimitedDecodeStream<Desc extends DescMessage>(messageDesc: Desc, iterable: AsyncIterable<Uint8Array>, options?: Partial<SizeDelimitedDecodeOptions>): AsyncIterableIterator<MessageShape<Desc>>;
43 /**
44 * Decodes the size from the given size-delimited message, which may be
45 * incomplete.
46 *
47 * Returns an object with the following properties:
48 * - size: The size of the delimited message in bytes
49 * - offset: The offset in the given byte array where the message starts
50 * - eof: true
51 *
52 * If the size-delimited data does not include all bytes of the varint size,
53 * the following object is returned:
54 * - size: null
55 * - offset: null
56 * - eof: false
57 *
58 * This function can be used to implement parsing of size-delimited messages
59 * from a stream.
60 */
61 export declare function sizeDelimitedPeek(data: Uint8Array): {
62 readonly eof: false;
63 readonly size: number;
64 readonly offset: number;
65 } | {
66 readonly eof: true;
67 readonly size: null;
68 readonly offset: null;
69 };