import { DescMessage, DescField, DescFile, MessageShape } from '@bufbuild/protobuf'; /** * SBE View: read-only access into an SBE-encoded buffer with no message * allocation. Mirrors `protowire/encoding/sbe/view.go`. * * Strings still allocate (JavaScript has no `unsafe.String` equivalent), but * Bytes() returns a zero-copy `Uint8Array` subarray and Composite() just * returns a new View over the same underlying buffer. */ interface ViewSchema { fields: Map; groups: ViewGroupInfo[]; } interface ViewGroupInfo { name: string; schema: ViewSchema; } /** * View provides allocation-free read access to SBE-encoded data. Field * accessors decode primitives directly from the underlying buffer. */ declare class View { /** Full SBE message buffer — needed to walk groups past the root block. */ private readonly data; /** Current block (root, group entry, or composite). */ private readonly block; private readonly view; private readonly schema; /** Offset of the first group header (end of root block) in `data`. */ private readonly groupsStart; constructor(data: Uint8Array, block: Uint8Array, schema: ViewSchema, groupsStart: number); static fromCodec(codec: Codec, data: Uint8Array): View; private field; int(name: string): number | bigint; uint(name: string): number | bigint; float(name: string): number; bool(name: string): boolean; enum(name: string): number; /** Trims trailing NUL padding. */ string(name: string): string; /** Zero-copy subarray view over the field's bytes. */ bytes(name: string): Uint8Array; composite(name: string): View; group(name: string): GroupView; } declare class GroupView { private readonly data; /** Offset in `data` of this group's header. */ private readonly base; private readonly blockLength; private readonly count; private readonly schema; constructor(data: Uint8Array, base: number, blockLength: number, count: number, schema: ViewSchema); get length(): number; entry(i: number): View; } /** * SBE wire-layout templates derived from proto descriptors. * Mirrors `protowire/encoding/sbe/template.go`. */ type SbeEncoding = "int8" | "int16" | "int32" | "int64" | "uint8" | "uint16" | "uint32" | "uint64" | "float" | "double" | "char"; interface FieldTemplate { fd: DescField; offset: number; size: number; /** Empty string for composite fields. */ encoding: SbeEncoding | ""; /** Non-empty for composite (nested message) fields. */ composite: FieldTemplate[]; /** Lazily populated by view.buildViewSchema for composite fields. */ compositeView?: ViewSchema; } interface GroupTemplate { fd: DescField; blockLength: number; fields: FieldTemplate[]; } interface MessageTemplate { desc: DescMessage; templateId: number; schemaId: number; version: number; blockLength: number; fields: FieldTemplate[]; groups: GroupTemplate[]; /** Lazily populated by View.fromCodec on first use. */ view?: ViewSchema; } /** * SBE codec: registers proto messages by template ID and dispatches to the * marshal/unmarshal/view paths. Mirrors `protowire/encoding/sbe/sbe.go`. */ /** SBE message header size: blockLength(2) + templateId(2) + schemaId(2) + version(2). */ declare const HEADER_SIZE = 8; /** SBE repeating-group header size: blockLength(2) + numInGroup(2). */ declare const GROUP_HEADER_SIZE = 4; declare class Codec { readonly byName: Map; readonly byId: Map; static fromFiles(...files: DescFile[]): Codec; private registerMessage; template(typeName: string): MessageTemplate; templateById(id: number): MessageTemplate; /** Construct a zero-allocation reader over an SBE-encoded buffer. */ view(data: Uint8Array): View; } /** * SBE marshal: serializes a proto message into the SBE binary format using a * pre-built MessageTemplate. Mirrors `protowire/encoding/sbe/marshal.go`. */ declare function marshal(codec: Codec, desc: Desc, msg: MessageShape): Uint8Array; /** * SBE unmarshal: decodes an SBE binary buffer into a proto message using a * pre-built MessageTemplate. Mirrors `protowire/encoding/sbe/unmarshal.go`. */ declare function unmarshal(codec: Codec, desc: Desc, msg: MessageShape, data: Uint8Array): void; /** * SBE XML schema model + parser. Mirrors the data shape of * `protowire/encoding/sbe/xmlschema.go`. * * Also exports the name-conversion helpers shared between XMLToProto and * ProtoToXML. */ interface XMLSchema { package: string; id: number; version: number; byteOrder: string; description: string; types: XMLTypes; messages: XMLMessage[]; } interface XMLTypes { types: XMLType[]; composites: XMLComposite[]; enums: XMLEnum[]; } interface XMLType { name: string; primitiveType: string; length?: number; description?: string; } interface XMLComposite { name: string; description?: string; types: XMLType[]; refs: XMLRef[]; } interface XMLRef { name: string; type: string; } interface XMLEnum { name: string; encodingType: string; description?: string; validValues: XMLValidValue[]; } interface XMLValidValue { name: string; value: string; } interface XMLMessage { name: string; id: number; description?: string; fields: XMLField[]; groups: XMLGroup[]; } interface XMLField { name: string; id: number; type: string; } interface XMLGroup { name: string; id: number; fields: XMLField[]; } declare function parseXMLSchema(xml: string): XMLSchema; declare function camelToSnake(s: string): string; declare function snakeToCamel(s: string): string; declare function camelToScreamingSnake(s: string): string; declare function screamingSnakeToPascal(s: string): string; declare function stripEnumPrefix(valueName: string, enumName: string): string; declare function singularPascal(s: string): string; /** * Convert an SBE XML schema into proto3 source with sbe annotations. * Mirrors `protowire/encoding/sbe/xmltoproto.go`. */ declare function xmlToProto(xml: string): string; /** * Convert proto file descriptors with SBE annotations to an SBE XML schema. * Mirrors `protowire/encoding/sbe/prototoxml.go`. */ declare function protoToXml(file: DescFile): string; export { Codec, type FieldTemplate, GROUP_HEADER_SIZE, type GroupTemplate, GroupView, HEADER_SIZE, type MessageTemplate, type SbeEncoding, View, type ViewSchema, type XMLComposite, type XMLEnum, type XMLField, type XMLGroup, type XMLMessage, type XMLRef, type XMLSchema, type XMLType, type XMLTypes, type XMLValidValue, camelToScreamingSnake, camelToSnake, marshal, parseXMLSchema, protoToXml, screamingSnakeToPascal, singularPascal, snakeToCamel, stripEnumPrefix, unmarshal, xmlToProto };