import * as Result from "../Result.ts"; import type * as ProtobufDescriptor from "./ProtobufDescriptor.ts"; /** * The key of the unknown fields of a message value: the encoded bytes of the * fields its descriptor does not declare, extensions among them, and of the * numbers that a closed enum does not have. * * @stability experimental * @category symbols * @since 4.1.5 */ export declare const unknownFields: unique symbol; /** * A message value, keyed by the `name` of each field. * * @stability experimental * @category models * @since 4.1.5 */ export interface Message { readonly [key: string]: unknown; readonly [unknownFields]?: Uint8Array; } declare const ProtobufMessageError_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: "ProtobufMessageError"; } & Readonly; /** * The error for a value that does not encode, or bytes that do not decode. * `path` leads to the field that failed: the keys of message fields, indexes * of list elements, and keys of map entries. * * @stability experimental * @category errors * @since 4.1.5 */ export declare class ProtobufMessageError extends ProtobufMessageError_base<{ readonly message: string; readonly path: ReadonlyArray; }> { } /** * Decodes the binary encoding of a message. * * **Details** * * Repeated occurrences of a singular message field merge. The same applies * to repeated occurrences of the active message case of a oneof; changing * cases discards the previous value. Repeated map keys replace earlier values. * * Required fields are checked after these operations, including in empty * message values synthesized for map entries that omit their value. A failure * includes the path through message fields, list indexes, and map keys. * Malformed bytes fail even when a later occurrence would replace their value. * A field with an incompatible wire type is treated as unknown. * * - `readUnknownFields`: whether to keep the fields the descriptor does not * declare, `true` by default. * - `maxDepth`: a non-negative integer limiting nested message values and * unknown groups, 100 by default. The root message has depth zero. A map * container does not add depth; its message values do. Unknown * length-delimited bytes remain opaque. * * **Example** (Decoding a message) * * ```ts import.meta.vitest * import { Result } from "effect" * import { ProtobufDescriptor, ProtobufMessage } from "effect/protobuf" * * // message Test { int32 a = 1; } * const registry = Result.getOrThrow(ProtobufDescriptor.make([{ * name: "test.proto", * syntax: "proto3", * message_type: [{ name: "Test", field: [{ name: "a", number: 1, label: 1, type: 5 }] }] * }])) * const decode = ProtobufMessage.decode(registry.getMessage("Test")!) * * Result.getOrThrow(decode(new Uint8Array([0x08, 0x96, 0x01]))) // => { a: 150 } * Result.isFailure(decode(new Uint8Array([0x08, 0x96]))) // => true * ``` * * @stability experimental * @category decoding * @since 4.1.5 */ export declare const decode: (descriptor: ProtobufDescriptor.MessageDescriptor, options?: { readonly readUnknownFields?: boolean | undefined; readonly maxDepth?: number | undefined; }) => (bytes: Uint8Array) => Result.Result; /** * Encodes a message. Fields are written in field-number order, and unknown * fields last. * * **Details** * * Checks field types, numeric ranges, closed enum values, oneof cases, and * required fields while encoding. Invalid values return a failure with their * field path; no partial output is returned. Successful output owns its bytes. * * - `writeUnknownFields`: whether to write the unknown fields of values, * `true` by default. * - `maxDepth`: a non-negative integer limiting nested message values, 100 by * default. The root message has depth zero. A map container does not add * depth; its message values do. Raw unknown fields are written unchanged. * * **Example** (Encoding a message) * * ```ts import.meta.vitest * import { Result } from "effect" * import { ProtobufDescriptor, ProtobufMessage } from "effect/protobuf" * * // message Test { int32 a = 1; } * const registry = Result.getOrThrow(ProtobufDescriptor.make([{ * name: "test.proto", * syntax: "proto3", * message_type: [{ name: "Test", field: [{ name: "a", number: 1, label: 1, type: 5 }] }] * }])) * const encode = ProtobufMessage.encode(registry.getMessage("Test")!) * * Result.getOrThrow(encode({ a: 150 })) // => new Uint8Array([0x08, 0x96, 0x01]) * Result.isFailure(encode({ a: 1.5 })) // => true * ``` * * @stability experimental * @category encoding * @since 4.1.5 */ export declare const encode: (descriptor: ProtobufDescriptor.MessageDescriptor, options?: { readonly writeUnknownFields?: boolean | undefined; readonly maxDepth?: number | undefined; }) => (message: object) => Result.Result, ProtobufMessageError>; /** * Reads an extension from the unknown fields of a message: its value, or * `undefined` when it is not set, or an array for a repeated extension. * * **Details** * * Message occurrences merge before required fields are checked. MessageSet * extensions accept both group items and ordinary length-delimited fields. * * @stability experimental * @category extensions * @since 4.1.5 */ export declare const getExtension: (message: object, extension: ProtobufDescriptor.ExtensionDescriptor) => Result.Result; /** * Returns a copy of a message with an extension set in its unknown fields, * replacing an earlier value. `undefined` clears the extension. * * **Details** * * Preserves other unknown fields, including occurrences of the extension's * field number with an incompatible wire type and unknown closed-enum numbers. * * **Example** (Setting an extension) * * ```ts import.meta.vitest * import { Result } from "effect" * import { ProtobufDescriptor, ProtobufMessage } from "effect/protobuf" * * // message Product { string name = 1; extensions 100 to max; } * // extend Product { int32 priority = 100; } * const registry = Result.getOrThrow(ProtobufDescriptor.make([{ * name: "product.proto", * message_type: [{ * name: "Product", * field: [{ name: "name", number: 1, label: 1, type: 9 }], * extension_range: [{ start: 100, end: 536870912 }] * }], * extension: [{ name: "priority", number: 100, label: 1, type: 5, extendee: ".Product" }] * }])) * const priority = registry.getExtension("priority")! * * const product = Result.getOrThrow(ProtobufMessage.setExtension({ name: "lamp" }, priority, 3)) * Result.getOrThrow(ProtobufMessage.getExtension(product, priority)) // => 3 * ``` * * @stability experimental * @category extensions * @since 4.1.5 */ export declare const setExtension: (message: A, extension: ProtobufDescriptor.ExtensionDescriptor, value: unknown) => Result.Result; export {}; //# sourceMappingURL=ProtobufMessage.d.ts.map