import { FieldInfo, FieldList } from "./field.js"; import { ScalarType, ScalarValue } from "./scalar.js"; import { IBinaryReader, IBinaryWriter, WireType } from "./binary-encoding.js"; /** * Options for parsing binary data. */ export interface BinaryReadOptions { /** * Retain unknown fields during parsing? The default behavior is to retain * unknown fields and include them in the serialized output. * * For more details see https://developers.google.com/protocol-buffers/docs/proto3#unknowns */ readUnknownFields: boolean; /** * Allows to use a custom implementation to decode binary data. */ readerFactory: (bytes: Uint8Array) => IBinaryReader; } /** * Options for serializing to binary data. */ export interface BinaryWriteOptions { /** * Include unknown fields in the serialized output? The default behavior * is to retain unknown fields and include them in the serialized output. * * For more details see https://developers.google.com/protocol-buffers/docs/proto3#unknowns */ writeUnknownFields: boolean; /** * Allows to use a custom implementation to encode binary data. */ writerFactory: () => IBinaryWriter; } declare function makeReadOptions(options?: Partial): Readonly; declare function makeWriteOptions(options?: Partial): Readonly; declare function readField(target: Record, reader: IBinaryReader, field: FieldInfo, wireType: WireType, options: BinaryReadOptions): void; /** * AnyMessage is an interface implemented by all messages. If you need to * handle messages of unknown type, this interface provides a convenient * index signature to access fields with message["fieldname"]. */ type AnyMessage = { [k: string]: any; }; declare function readMapEntry(field: FieldInfo & { kind: "map"; }, reader: IBinaryReader, options: BinaryReadOptions): [string | number, ScalarValue | AnyMessage | undefined]; declare function readScalar(reader: IBinaryReader, type: ScalarType): ScalarValue; declare function readScalarLTString(reader: IBinaryReader, type: ScalarType): Exclude; declare function readMessage(message: T, fields: FieldList, reader: IBinaryReader, lengthOrEndTagFieldNo: number, options: BinaryReadOptions, delimitedMessageEncoding: boolean): void; /** * Serialize a message to binary data. */ declare function writeMessage(message: T, fields: FieldList, writer: IBinaryWriter, options: BinaryWriteOptions): void; declare function writeField(field: FieldInfo, value: T, writer: IBinaryWriter, options: BinaryWriteOptions): void; declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: unknown): void; declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: T[]): void; declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & { kind: "map"; }, key: string, value: any): void; export { readField as binaryReadField, readMapEntry as binaryReadMapEntry, readScalar as binaryReadScalar, readScalarLTString as binaryReadScalarLTString, readMessage as binaryReadMessage, writeField as binaryWriteField, writeScalar as binaryWriteScalar, writePacked as binaryWritePacked, writeMapEntry as binaryWriteMapEntry, writeMessage as binaryWriteMessage, makeReadOptions as binaryMakeReadOptions, makeWriteOptions as binaryMakeWriteOptions, };