import { _IProtobufWriter } from "./_IProtobufWriter"; /** * Measures a Protocol Buffer message before it is written. * * It receives the same calls as {@link _ProtobufWriter}, counts the bytes and * records the byte length of every string and length-delimited message, which * the writer reads back in order. The writer then allocates exactly one * buffer. * * @evidence contracts/common.md#principled-implementation The sizer replays the encoder's calls to compute the exact byte length and, for each string or length-delimited message, the prefix lengths, which the writer then consumes in the same order, so the buffer is allocated once and filled without a growth step. Varint lengths follow from the value ranges, a negative int32 takes ten bytes and 64-bit values are measured after reduction to an unsigned 64-bit pattern. * @evidence contracts/common.md#clear-and-simple-design One class holding the total length, a position stack for open messages and the list of recorded lengths; its private varint measurers are shared by the scalar methods. * @evidence contracts/common.md#prohibited-implementation-shortcuts The size rules are the protobuf wire format's, with no caller special-cased. An ldelim call without an open fork throws; callers must finish any forks they open. * @evidence contracts/common.md#meaningful-documentation A comment explains the two-pass role with the writer, and the fields have comments. */ export declare class _ProtobufSizer implements _IProtobufWriter { /** Total measured byte length, including length prefixes. */ len: number; /** Byte positions at which still-open messages started. */ readonly pos: Array; /** String and message byte lengths in the writer's consumption order. */ readonly varlen: Array; /** Reserved length-list indices for still-open messages. */ readonly varlenidx: Array; /** Start measuring from an optional existing byte count. */ constructor(length?: number); /** * Count one byte. * * @evidence contracts/common.md#principled-implementation A boolean always takes one byte. * @evidence contracts/common.md#clear-and-simple-design One increment. * @evidence contracts/common.md#prohibited-implementation-shortcuts A fixed wire size. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ bool(): void; /** * Count the varint of a signed 32-bit integer, which is ten bytes when * negative. * * @evidence contracts/common.md#principled-implementation A negative value takes ten bytes because it is sign-extended to 64 bits, otherwise the varint length of the value is used. * @evidence contracts/common.md#clear-and-simple-design One branch over the shared measurer. * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is the wire format's. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ int32(value: number): void; /** * Count the varint of the unsigned ZigZag form of a signed 32-bit integer. * * @evidence contracts/common.md#principled-implementation The ZigZag mapping is taken as an unsigned 32-bit value before measuring, so magnitudes of 2^30 or more are measured as five bytes and not as a negative number; the writer applies the same mapping. * @evidence contracts/common.md#clear-and-simple-design One expression over the shared measurer. * @evidence contracts/common.md#prohibited-implementation-shortcuts The mapping is the protobuf definition and is not special-cased. * @evidence contracts/common.md#meaningful-documentation A comment states the unsigned mapping and the reason for it. */ sint32(value: number): void; /** * Count the varint of an unsigned 32-bit integer. * * @evidence contracts/common.md#principled-implementation The varint length of an unsigned 32-bit value, one to five bytes. * @evidence contracts/common.md#clear-and-simple-design One delegation. * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is the wire format's. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ uint32(value: number): void; /** * Count the varint of a signed 64-bit integer. * * @evidence contracts/common.md#principled-implementation A number is converted to a bigint and measured as an unsigned 64-bit pattern, which gives ten bytes for a negative value. * @evidence contracts/common.md#clear-and-simple-design One delegation to the 64-bit measurer. * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is the wire format's. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ int64(value: bigint | number): void; /** * Count the varint of the ZigZag form of a signed 64-bit integer. * * @evidence contracts/common.md#principled-implementation The ZigZag mapping on a bigint, `(n << 1) ^ (n >> 63)`, is measured as an unsigned 64-bit pattern. * @evidence contracts/common.md#clear-and-simple-design One expression over the 64-bit measurer. * @evidence contracts/common.md#prohibited-implementation-shortcuts The mapping is the protobuf definition. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ sint64(value: bigint | number): void; /** * Count the varint of an unsigned 64-bit integer. * * @evidence contracts/common.md#principled-implementation A number or bigint is measured as an unsigned 64-bit varint. * @evidence contracts/common.md#clear-and-simple-design One delegation to the 64-bit measurer. * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is the wire format's. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ uint64(value: bigint | number): void; /** * Count four bytes. * * @evidence contracts/common.md#principled-implementation A float takes four bytes regardless of value. * @evidence contracts/common.md#clear-and-simple-design One increment. * @evidence contracts/common.md#prohibited-implementation-shortcuts A fixed wire size. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ float(_value: number): void; /** * Count eight bytes. * * @evidence contracts/common.md#principled-implementation A double takes eight bytes regardless of value. * @evidence contracts/common.md#clear-and-simple-design One increment. * @evidence contracts/common.md#prohibited-implementation-shortcuts A fixed wire size. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ double(_value: number): void; /** * Count the length prefix and the bytes. * * @evidence contracts/common.md#principled-implementation The length prefix is measured as an unsigned 32-bit varint and the byte length is added. * @evidence contracts/common.md#clear-and-simple-design Two increments. * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is the wire format's. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ bytes(value: Uint8Array): void; /** * Count the length prefix and the UTF-8 bytes, and record the byte length for * the writer. * * @evidence contracts/common.md#principled-implementation The UTF-8 byte length is measured by encoding through a Blob, recorded in the length list so the writer reuses it and not recomputes it, and added with its varint prefix. * @evidence contracts/common.md#clear-and-simple-design One function using a module-level measuring helper. * @evidence contracts/common.md#prohibited-implementation-shortcuts The measure counts UTF-8 bytes and not code units. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is counted. */ string(value: string): void; /** * Save the position and reserve a length slot for a message that is starting. * * @evidence contracts/common.md#principled-implementation The current length and the length list's size are saved on stacks and a zero is reserved in the list, to be filled when the message ends. * @evidence contracts/common.md#clear-and-simple-design Three stack operations. * @evidence contracts/common.md#prohibited-implementation-shortcuts The bookkeeping is the two-pass design's. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is saved. */ fork(): void; /** * Fill the reserved length slot with the size of the message that ends here, * and count its length prefix. * * @throws Error when no `fork` is open * * @evidence contracts/common.md#principled-implementation The length of the message since its fork is stored in the reserved list slot and its varint prefix is counted; an unmatched call throws a typed error instead of corrupting the stacks. * @evidence contracts/common.md#clear-and-simple-design One function paired with fork. * @evidence contracts/common.md#prohibited-implementation-shortcuts The unmatched case throws rather than being tolerated. * @evidence contracts/common.md#meaningful-documentation A one-line comment states what is recorded. */ ldelim(): void; /** * Clear the counters and stacks so the sizer can measure another message. * * @evidence contracts/common.md#principled-implementation The counters and stacks are cleared in place, so the same sizer can measure another message without allocating new arrays. * @evidence contracts/common.md#clear-and-simple-design Four assignments. * @evidence contracts/common.md#prohibited-implementation-shortcuts No hidden state is kept. * @evidence contracts/common.md#meaningful-documentation A one-line comment states that the arrays are reused. */ reset(): void; private varint32; private varint64; }