/** * The wire types of the protobuf format, which a tag carries with the field * number. The same as `ProtobufWriter.WireType`. * * @stability experimental * @category constants * @since 4.1.5 */ export declare const WireType: { readonly Varint: 0; readonly I64: 1; readonly Len: 2; readonly StartGroup: 3; readonly EndGroup: 4; readonly I32: 5; }; /** * A protobuf wire type, from 0 through 5. * * @stability experimental * @category models * @since 4.1.5 */ export type WireType = typeof WireType[keyof typeof WireType]; declare const ProtobufReaderError_base: new = {}>(args: import("../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("../Cause.ts").YieldableError & { readonly _tag: "ProtobufReaderError"; } & Readonly; /** * The error thrown by a {@link ProtobufReader} for malformed input. * * **Details** * * `offset` is the position in the input where reading failed. * * **Example** (Catching malformed input) * * ```ts import.meta.vitest * import { ProtobufReader } from "effect/protobuf" * * // A varint whose last byte is missing * const r = ProtobufReader.make(new Uint8Array([0x08, 0x96])) * r.tag() * try { * r.int32() * } catch (e) { * e instanceof ProtobufReader.ProtobufReaderError // => true * String((e as ProtobufReader.ProtobufReaderError).message) // => "Expected a complete value at offset 2" * } * ``` * * @stability experimental * @category errors * @since 4.1.5 */ export declare class ProtobufReaderError extends ProtobufReaderError_base<{ readonly message: string; readonly offset: number; }> { } /** * A reader of the protobuf wire format, positioned at its current offset. * * **Details** * * Every method throws a {@link ProtobufReaderError} for malformed input. * 64-bit integers are read as a `bigint`, or as a `number` with * {@link ProtobufReader.int64Number} and its siblings. Create one with * {@link make}. * * **Example** (Reading a field) * * ```ts import.meta.vitest * import { ProtobufReader } from "effect/protobuf" * * // message Test { int32 a = 1; } with a = 150 * const r = ProtobufReader.make(new Uint8Array([0x08, 0x96, 0x01])) * const tag = r.tag() * ProtobufReader.fieldNumber(tag) // => 1 * r.int32() // => 150 * r.isDone() // => true * ``` * * @stability experimental * @category models * @since 4.1.5 */ export declare class ProtobufReader { private readonly buf; private pos; private limit; private lo; private hi; /** * Creates a reader borrowing `bytes`. Mutating `bytes` affects subsequent * reads and any views returned by {@link ProtobufReader.bytesView}. * * @since 4.1.5 */ constructor(bytes: Uint8Array); /** * The position of the next byte to read. * * @since 4.1.5 */ get offset(): number; /** * Whether every byte of the message being read has been read. * * @since 4.1.5 */ isDone(): boolean; private fail; /** * Reads a tag, which {@link fieldNumber} and {@link wireType} take apart. * * @since 4.1.5 */ tag(): number; private byte; private need; private length32; /** * Reads a `uint32` varint. * * @since 4.1.5 */ uint32(): number; private uint32Checked; /** * Reads an `int32` varint. * * @since 4.1.5 */ int32(): number; /** * Reads a `sint32` varint, with the zigzag encoding. * * @since 4.1.5 */ sint32(): number; private varint64; private varint64Checked; /** * Reads a `uint64` varint. * * @since 4.1.5 */ uint64(): bigint; /** * Reads an `int64` varint. * * @since 4.1.5 */ int64(): bigint; /** * Reads a `sint64` varint, with the zigzag encoding. * * @since 4.1.5 */ sint64(): bigint; /** * Reads a `uint64` varint as a `number`. * * **Details** * * Outside the safe integer range the number is rounded, as `Number` rounds * a `bigint`, which `Number.isSafeInteger` detects. It saves creating a * `bigint` for each value. * * @since 4.1.5 */ uint64Number(): number; /** * Reads an `int64` varint as a `number`. * * **Details** * * Outside the safe integer range the number is rounded, as `Number` rounds * a `bigint`, which `Number.isSafeInteger` detects. It saves creating a * `bigint` for each value. * * **Example** (Reading an `int64` as a number) * * ```ts import.meta.vitest * import { ProtobufReader, ProtobufWriter } from "effect/protobuf" * * const bytes = ProtobufWriter.make().int64(-2).int64(2n ** 60n).finish() * const r = ProtobufReader.make(bytes) * r.int64Number() // => -2 * Number.isSafeInteger(r.int64Number()) // => false * ``` * * @since 4.1.5 */ int64Number(): number; /** * Reads a `sint64` varint, with the zigzag encoding, as a `number`. * * **Details** * * Outside the safe integer range the number is rounded, as `Number` rounds * a `bigint`, which `Number.isSafeInteger` detects. It saves creating a * `bigint` for each value. * * @since 4.1.5 */ sint64Number(): number; /** * Reads a `bool` varint: any nonzero value is `true`. * * @since 4.1.5 */ bool(): boolean; /** * Reads a little-endian `sfixed32`. * * @since 4.1.5 */ sfixed32(): number; /** * Reads a little-endian `fixed32`. * * @since 4.1.5 */ fixed32(): number; /** * Reads a little-endian `fixed64`. * * @since 4.1.5 */ fixed64(): bigint; /** * Reads a little-endian `sfixed64`. * * @since 4.1.5 */ sfixed64(): bigint; /** * Reads a little-endian `fixed64` as a `number`. * * **Details** * * Outside the safe integer range the number is rounded, as `Number` rounds * a `bigint`, which `Number.isSafeInteger` detects. It saves creating a * `bigint` for each value. * * @since 4.1.5 */ fixed64Number(): number; /** * Reads a little-endian `sfixed64` as a `number`. * * **Details** * * Outside the safe integer range the number is rounded, as `Number` rounds * a `bigint`, which `Number.isSafeInteger` detects. It saves creating a * `bigint` for each value. * * @since 4.1.5 */ sfixed64Number(): number; /** * Reads a little-endian 32-bit `float`. * * @since 4.1.5 */ float(): number; /** * Reads a little-endian 64-bit `double`. * * @since 4.1.5 */ double(): number; private end; /** * Reads length-prefixed bytes, as a copy. * * @since 4.1.5 */ bytes(): Uint8Array; /** * Reads length-prefixed bytes as a view of the input. Mutating the input or * the returned view changes the other; use {@link ProtobufReader.bytes} * when the result must own its bytes. * * @since 4.1.5 */ bytesView(): Uint8Array; /** * Reads a length-prefixed string. Invalid UTF-8 fails by default; setting * `validateUtf8` to `false` replaces invalid sequences with U+FFFD. * * @since 4.1.5 */ string(options?: { readonly validateUtf8?: boolean | undefined; }): string; /** * Reads a length prefix and returns a child reader restricted to its payload. * Advances this reader past the payload immediately. The child borrows the * same input and reports absolute offsets; it cannot read enclosing fields. * Leaving part of the child unread does not affect the parent's position. * * @since 4.1.5 */ delimited(): ProtobufReader; /** * Skips the value of the field of `tag`, including all of a group. Group * nesting is bounded by `maxDepth`, 512 by default, and uses an explicit * stack. A zero limit rejects groups but permits other wire types. The limit * must be a non-negative integer; otherwise this throws `RangeError`. * * @since 4.1.5 */ skip(tag: number, maxDepth?: number): void; } /** * The field number of a tag from {@link ProtobufReader.tag}. * * @stability experimental * @category utils * @since 4.1.5 */ export declare const fieldNumber: (tag: number) => number; /** * The wire type of a tag from {@link ProtobufReader.tag}. * * @stability experimental * @category utils * @since 4.1.5 */ export declare const wireType: (tag: number) => WireType; /** * Creates a reader of `bytes`, which are not copied. * * **Example** (Creating a reader) * * ```ts import.meta.vitest * import { ProtobufReader } from "effect/protobuf" * * ProtobufReader.make(new Uint8Array([0x96, 0x01])).uint32() // => 150 * ``` * * @stability experimental * @category constructors * @since 4.1.5 */ export declare const make: (bytes: Uint8Array) => ProtobufReader; export {}; //# sourceMappingURL=ProtobufReader.d.ts.map