/** * Buffer I/O utilities for Native format encoding/decoding. */ import { type DecodeOptions, type TypedArray } from "./types.ts"; export declare function writeUtf8Encoder(str: string, target: Uint8Array, offset: number, maxLen: number): number; export declare function writeUtf8Buffer(str: string, target: Uint8Array, offset: number, maxLen: number): number; export declare const writeUtf8: (str: string, target: Uint8Array, offset: number, maxLen: number) => number; export declare function decodeUtf8Slice(buffer: Uint8Array, start: number, len: number): string; /** * Growable buffer for streaming decode. Replaces chunk array + flattenChunks(). * Amortized O(n) vs O(n²) for many small chunks. */ /** * Growable byte buffer for framing blocks out of a chunked stream, with two * consumption modes for two ownership contracts: * * - `startNextBlock(bytes)` — stable: moves the unread remainder into a * freshly allocated backing buffer, so zero-copy views handed out while * decoding earlier blocks (typed array columns, string/UUID subarrays) * are never mutated afterwards. Use when decoded views escape the loop. * * - `consume(bytes)` — amortized in-place: advances a read offset and * compacts with copyWithin past 50% waste. No allocation in steady state, * but ONLY safe when nothing that aliases this buffer outlives the call. * * Growth always allocates a fresh buffer (never compacts in place), so * escaped views stay valid across `append` in either mode. */ export declare class BlockBuffer { private buffer; private readOffset; private writeOffset; private initialSize; constructor(initialSize?: number); get available(): number; get view(): Uint8Array; append(chunk: Uint8Array): void; /** In-place consume. Only safe when no views into this buffer outlive the call. */ consume(bytes: number): void; /** Stable consume: remainder moves to a fresh buffer so escaped views stay valid. */ startNextBlock(bytesConsumed: number): void; private ensureCapacity; } export declare class BufferUnderflowError extends Error { constructor(message: string); } export type TypedArrayConstructor = { new (length: number): T; new (buffer: ArrayBuffer, byteOffset: number, length: number): T; BYTES_PER_ELEMENT: number; }; export declare function varIntSize(value: number | bigint): number; export declare function writeVarInt(buffer: Uint8Array, offset: number, value: number | bigint): number; export declare function readVarInt(buffer: Uint8Array, cursor: { offset: number; }): number; export declare function readVarInt64(buffer: Uint8Array, cursor: { offset: number; }): bigint; export declare class BufferWriter { private buffer; private offset; private view; constructor(initialSize?: number); private ensure; write(chunk: Uint8Array): void; writeU8(v: number): void; writeU32LE(v: number): void; writeU64LE(v: bigint): void; writeI32LE(v: number): void; writeVarint(value: number | bigint): void; writeString(val: string): void; private writeStringGeneral; reset(maxRetainedCapacity?: number): void; finish(): Uint8Array; finishCopy(): Uint8Array; } export declare class BufferReader { buffer: Uint8Array; offset: number; view: DataView; options?: DecodeOptions; constructor(buffer: Uint8Array, offset?: number, options?: DecodeOptions); readVarint(): number; readVarInt64(): bigint; readString(): string; readTypedArray(Ctor: TypedArrayConstructor, count: number): T; readBytes(length: number): Uint8Array; ensureAvailable(bytes: number): void; readU8(): number; readU32LE(): number; readU64LE(): bigint; readI32LE(): number; readI64LE(): bigint; /** * Replace the underlying buffer while preserving read offset. * Used for progressive decoding: when more data arrives, swap in * the larger buffer and continue reading from where we left off. * The idea being that we keep decoding from where we left off. */ replaceBuffer(newBuffer: Uint8Array): void; } //# sourceMappingURL=io.d.ts.map