/** * The wire types of the protobuf format, which a tag carries with the field * number. * * **Details** * * - `Varint`: `int32`, `int64`, `uint32`, `uint64`, `sint32`, `sint64`, * `bool`, and enums. * - `I64`: `fixed64`, `sfixed64`, and `double`. * - `Len`: strings, bytes, nested messages, and packed repeated fields. * - `StartGroup` and `EndGroup`: the deprecated proto2 groups. * - `I32`: `fixed32`, `sfixed32`, and `float`. * * @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]; /** * A writer of the protobuf wire format. * * **Details** * * Every write returns the writer, so writes chain: `w.tag(1, WireType.Len).string("a")`. * 64-bit integers are given as a `bigint`, a `number` that is an integer, or a * decimal `string`. {@link ProtobufWriter.finish} returns the bytes and resets * the writer, which can then write a new message. Create one with {@link make}. * * **Example** (Writing a field) * * ```ts import.meta.vitest * import { ProtobufWriter } from "effect/protobuf" * * // message Test { int32 a = 1; } with a = 150 * ProtobufWriter.make() * .tag(1, ProtobufWriter.WireType.Varint) * .int32(150) * .finish() // => new Uint8Array([0x08, 0x96, 0x01]) * ``` * * @stability experimental * @category models * @since 4.1.5 */ export declare class ProtobufWriter { private buf; private view; private pos; private readonly forks; /** * Returns an owned copy of the written bytes and resets the writer. Later * writes cannot change the returned bytes. Throws if a * {@link ProtobufWriter.fork} is not joined. * * @since 4.1.5 */ finish(): Uint8Array; /** * Starts a length-delimited value, such as a nested message or a packed * repeated field, after its tag. {@link ProtobufWriter.join} ends it. * * @since 4.1.5 */ fork(): this; /** * Ends the length-delimited value of the last {@link ProtobufWriter.fork}, * filling in its length. * * @since 4.1.5 */ join(): this; /** * Writes a tag: an integer field number from 1 through 536870911 and a wire * type from 0 through 5. Invalid arguments throw `RangeError` before writing. * * @since 4.1.5 */ tag(fieldNumber: number, wireType: WireType): this; /** * Writes a `uint32` varint. * * @since 4.1.5 */ uint32(n: number): this; /** * Writes an `int32` varint. Negative values take ten bytes, as for `int64`. * * @since 4.1.5 */ int32(n: number): this; /** * Writes a `sint32` varint, with the zigzag encoding. * * @since 4.1.5 */ sint32(n: number): this; /** * Writes a `uint64` varint. * * @since 4.1.5 */ uint64(n: bigint | number | string): this; /** * Writes an `int64` varint. Negative values take ten bytes. * * @since 4.1.5 */ int64(n: bigint | number | string): this; /** * Writes a `sint64` varint, with the zigzag encoding. * * @since 4.1.5 */ sint64(n: bigint | number | string): this; /** * Writes a `bool` varint. * * @since 4.1.5 */ bool(value: boolean): this; /** * Writes a little-endian `fixed32`. * * @since 4.1.5 */ fixed32(n: number): this; /** * Writes a little-endian `sfixed32`. * * @since 4.1.5 */ sfixed32(n: number): this; /** * Writes a little-endian `fixed64`. * * @since 4.1.5 */ fixed64(n: bigint | number | string): this; /** * Writes a little-endian `sfixed64`. * * @since 4.1.5 */ sfixed64(n: bigint | number | string): this; /** * Writes a little-endian 32-bit `float`. * * @since 4.1.5 */ float(n: number): this; /** * Writes a little-endian 64-bit `double`. * * @since 4.1.5 */ double(n: number): this; /** * Writes length-prefixed bytes. * * @since 4.1.5 */ bytes(bytes: Uint8Array): this; /** * Writes bytes as they are, without a length prefix, such as fields that * are already encoded. * * **Example** (Copying encoded fields) * * ```ts import.meta.vitest * import { ProtobufWriter } from "effect/protobuf" * * const { Varint } = ProtobufWriter.WireType * const fields = ProtobufWriter.make().tag(1, Varint).uint32(150).finish() * * ProtobufWriter.make().tag(2, Varint).bool(true).raw(fields).finish() // => new Uint8Array([0x10, 0x01, 0x08, 0x96, 0x01]) * ``` * * @since 4.1.5 */ raw(bytes: Uint8Array): this; /** * Writes a length-prefixed UTF-8 string. * * @since 4.1.5 */ string(s: string): this; private ensure; private grow; private varint64; private reserveLength; private fillLength; } /** * Creates a writer. * * **Example** (Creating a writer) * * ```ts import.meta.vitest * import { ProtobufWriter } from "effect/protobuf" * * ProtobufWriter.make().uint32(150).finish() // => new Uint8Array([0x96, 0x01]) * ``` * * @stability experimental * @category constructors * @since 4.1.5 */ export declare const make: () => ProtobufWriter; //# sourceMappingURL=ProtobufWriter.d.ts.map