/** * Protobuf binary format wire types. * * A wire type provides just enough information to find the length of the * following value. * * See https://developers.google.com/protocol-buffers/docs/encoding#structure */ export declare enum WireType { /** * Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum */ Varint = 0, /** * Used for fixed64, sfixed64, double. * Always 8 bytes with little-endian byte order. */ Bit64 = 1, /** * Used for string, bytes, embedded messages, packed repeated fields * * Only repeated numeric types (types which use the varint, 32-bit, * or 64-bit wire types) can be packed. In proto3, such fields are * packed by default. */ LengthDelimited = 2, /** * Start of a tag-delimited aggregate, such as a proto2 group, or a message * in editions with message_encoding = DELIMITED. */ StartGroup = 3, /** * End of a tag-delimited aggregate. */ EndGroup = 4, /** * Used for fixed32, sfixed32, float. * Always 4 bytes with little-endian byte order. */ Bit32 = 5 } type TextEncoderLike = { encode(input?: string): Uint8Array; }; type TextDecoderLike = { decode(input?: Uint8Array): string; }; export interface IBinaryReader { /** * Current position. */ readonly pos: number; /** * Number of bytes available in this reader. */ readonly len: number; /** * Reads a tag - field number and wire type. */ tag(): [number, WireType]; /** * Skip one element on the wire and return the skipped data. */ skip(wireType: WireType): Uint8Array; /** * Read a `uint32` field, an unsigned 32 bit varint. */ uint32(): number; /** * Read a `int32` field, a signed 32 bit varint. */ int32(): number; /** * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint. */ sint32(): number; /** * Read a `int64` field, a signed 64-bit varint. */ int64(): bigint | string; /** * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint. */ sint64(): bigint | string; /** * Read a `fixed64` field, a signed, fixed-length 64-bit integer. */ sfixed64(): bigint | string; /** * Read a `uint64` field, an unsigned 64-bit varint. */ uint64(): bigint | string; /** * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer. */ fixed64(): bigint | string; /** * Read a `bool` field, a variant. */ bool(): boolean; /** * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer. */ fixed32(): number; /** * Read a `sfixed32` field, a signed, fixed-length 32-bit integer. */ sfixed32(): number; /** * Read a `float` field, 32-bit floating point number. */ float(): number; /** * Read a `double` field, a 64-bit floating point number. */ double(): number; /** * Read a `bytes` field, length-delimited arbitrary data. */ bytes(): Uint8Array; /** * Read a `string` field, length-delimited data converted to UTF-8 text. */ string(): string; } export interface IBinaryWriter { /** * Return all bytes written and reset this writer. */ finish(): Uint8Array; /** * Start a new fork for length-delimited data like a message * or a packed repeated field. * * Must be joined later with `join()`. */ fork(): IBinaryWriter; /** * Join the last fork. Write its length and bytes, then * return to the previous state. */ join(): IBinaryWriter; /** * Writes a tag (field number and wire type). * * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )` * * Generated code should compute the tag ahead of time and call `uint32()`. */ tag(fieldNo: number, type: WireType): IBinaryWriter; /** * Write a chunk of raw bytes. */ raw(chunk: Uint8Array): IBinaryWriter; /** * Write a `uint32` value, an unsigned 32 bit varint. */ uint32(value: number): IBinaryWriter; /** * Write a `int32` value, a signed 32 bit varint. */ int32(value: number): IBinaryWriter; /** * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint. */ sint32(value: number): IBinaryWriter; /** * Write a `int64` value, a signed 64-bit varint. */ int64(value: string | number | bigint): IBinaryWriter; /** * Write a `uint64` value, an unsigned 64-bit varint. */ uint64(value: string | number | bigint): IBinaryWriter; /** * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint. */ sint64(value: string | number | bigint): IBinaryWriter; /** * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer. */ fixed64(value: string | number | bigint): IBinaryWriter; /** * Write a `fixed64` value, a signed, fixed-length 64-bit integer. */ sfixed64(value: string | number | bigint): IBinaryWriter; /** * Write a `bool` value, a variant. */ bool(value: boolean): IBinaryWriter; /** * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer. */ fixed32(value: number): IBinaryWriter; /** * Write a `sfixed32` value, a signed, fixed-length 32-bit integer. */ sfixed32(value: number): IBinaryWriter; /** * Write a `float` value, 32-bit floating point number. */ float(value: number): IBinaryWriter; /** * Write a `double` value, a 64-bit floating point number. */ double(value: number): IBinaryWriter; /** * Write a `bytes` value, length-delimited arbitrary data. */ bytes(value: Uint8Array): IBinaryWriter; /** * Write a `string` value, length-delimited data converted to UTF-8 text. */ string(value: string): IBinaryWriter; } export declare class BinaryWriter implements IBinaryWriter { /** * We cannot allocate a buffer for the entire output * because we don't know it's size. * * So we collect smaller chunks of known size and * concat them later. * * Use `raw()` to push data to this array. It will flush * `buf` first. */ private chunks; /** * A growing buffer for byte values. If you don't know * the size of the data you are writing, push to this * array. */ protected buf: number[]; /** * Previous fork states. */ private stack; /** * Text encoder instance to convert UTF-8 to bytes. */ private readonly textEncoder; constructor(textEncoder?: TextEncoderLike); /** * Return all bytes written and reset this writer. */ finish(): Uint8Array; /** * Start a new fork for length-delimited data like a message * or a packed repeated field. * * Must be joined later with `join()`. */ fork(): IBinaryWriter; /** * Join the last fork. Write its length and bytes, then * return to the previous state. */ join(): IBinaryWriter; /** * Writes a tag (field number and wire type). * * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`. * * Generated code should compute the tag ahead of time and call `uint32()`. */ tag(fieldNo: number, type: WireType): IBinaryWriter; /** * Write a chunk of raw bytes. */ raw(chunk: Uint8Array): IBinaryWriter; /** * Write a `uint32` value, an unsigned 32 bit varint. */ uint32(value: number): IBinaryWriter; /** * Write a `int32` value, a signed 32 bit varint. */ int32(value: number): IBinaryWriter; /** * Write a `bool` value, a variant. */ bool(value: boolean): IBinaryWriter; /** * Write a `bytes` value, length-delimited arbitrary data. */ bytes(value: Uint8Array): IBinaryWriter; /** * Write a `string` value, length-delimited data converted to UTF-8 text. */ string(value: string): IBinaryWriter; /** * Write a `float` value, 32-bit floating point number. */ float(value: number): IBinaryWriter; /** * Write a `double` value, a 64-bit floating point number. */ double(value: number): IBinaryWriter; /** * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer. */ fixed32(value: number): IBinaryWriter; /** * Write a `sfixed32` value, a signed, fixed-length 32-bit integer. */ sfixed32(value: number): IBinaryWriter; /** * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint. */ sint32(value: number): IBinaryWriter; /** * Write a `fixed64` value, a signed, fixed-length 64-bit integer. */ sfixed64(value: string | number | bigint): IBinaryWriter; /** * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer. */ fixed64(value: string | number | bigint): IBinaryWriter; /** * Write a `int64` value, a signed 64-bit varint. */ int64(value: string | number | bigint): IBinaryWriter; /** * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint. */ sint64(value: string | number | bigint): IBinaryWriter; /** * Write a `uint64` value, an unsigned 64-bit varint. */ uint64(value: string | number | bigint): IBinaryWriter; } export declare class BinaryReader implements IBinaryReader { /** * Current position. */ pos: number; /** * Number of bytes available in this reader. */ readonly len: number; private readonly buf; private readonly view; private readonly textDecoder; constructor(buf: Uint8Array, textDecoder?: TextDecoderLike); /** * Reads a tag - field number and wire type. */ tag(): [number, WireType]; /** * Skip one element on the wire and return the skipped data. * Supports WireType.StartGroup since v2.0.0-alpha.23. */ skip(wireType: WireType): Uint8Array; protected varint64: () => [number, number]; /** * Throws error if position in byte array is out of range. */ protected assertBounds(): void; /** * Read a `uint32` field, an unsigned 32 bit varint. */ uint32: IBinaryReader["uint32"]; /** * Read a `int32` field, a signed 32 bit varint. */ int32(): number; /** * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint. */ sint32(): number; /** * Read a `int64` field, a signed 64-bit varint. */ int64(): bigint | string; /** * Read a `uint64` field, an unsigned 64-bit varint. */ uint64(): bigint | string; /** * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint. */ sint64(): bigint | string; /** * Read a `bool` field, a variant. */ bool(): boolean; /** * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer. */ fixed32(): number; /** * Read a `sfixed32` field, a signed, fixed-length 32-bit integer. */ sfixed32(): number; /** * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer. */ fixed64(): bigint | string; /** * Read a `fixed64` field, a signed, fixed-length 64-bit integer. */ sfixed64(): bigint | string; /** * Read a `float` field, 32-bit floating point number. */ float(): number; /** * Read a `double` field, a 64-bit floating point number. */ double(): number; /** * Read a `bytes` field, length-delimited arbitrary data. */ bytes(): Uint8Array; /** * Read a `string` field, length-delimited data converted to UTF-8 text. */ string(): string; } export {};