import { FieldInfo, FieldList } from "./field.js"; import { LongType, ScalarType, ScalarValue } from "./scalar.js"; import { EnumType } from "./enum.js"; import { IMessageTypeRegistry } from "./type-registry.js"; /** * Options for parsing JSON data. */ export interface JsonReadOptions { /** * Ignore unknown fields: Proto3 JSON parser should reject unknown fields * by default. This option ignores unknown fields in parsing, as well as * unrecognized enum string representations. */ ignoreUnknownFields: boolean; /** * This option is required to read `google.protobuf.Any` from JSON format. */ typeRegistry?: IMessageTypeRegistry; } /** * Options for serializing to JSON. */ export interface JsonWriteOptions { /** * Emit fields with default values: Fields with default values are omitted * by default in proto3 JSON output. This option overrides this behavior * and outputs fields with their default values. */ emitDefaultValues: boolean; /** * Emit enum values as integers instead of strings: The name of an enum * value is used by default in JSON output. An option may be provided to * use the numeric value of the enum value instead. */ enumAsInteger: boolean; /** * Use proto field name instead of lowerCamelCase name: By default proto3 * JSON printer should convert the field name to lowerCamelCase and use * that as the JSON name. An implementation may provide an option to use * proto field name as the JSON name instead. Proto3 JSON parsers are * required to accept both the converted lowerCamelCase name and the proto * field name. */ useProtoFieldName: boolean; /** * This option is required to write `google.protobuf.Any` to JSON format. */ typeRegistry?: IMessageTypeRegistry; } /** * Options for serializing to JSON. */ export interface JsonWriteStringOptions extends JsonWriteOptions { prettySpaces: number; } /** * Represents any possible JSON value: * - number * - string * - boolean * - null * - object (with any JSON value as property) * - array (with any JSON value as element) */ export type JsonValue = number | string | boolean | null | JsonObject | JsonValue[]; /** * Represents a JSON object. */ export type JsonObject = { [k: string]: JsonValue; }; declare function makeReadOptions(options?: Partial): Readonly; declare function makeWriteOptions(options?: Partial): Readonly; declare function jsonDebugValue(json: unknown): string; declare function readMessage(fields: FieldList, typeName: string, json: JsonValue, options: JsonReadOptions, message: T): T; declare function writeMessage(message: T, fields: FieldList, options: JsonWriteOptions): JsonValue; declare function readField(target: Record, jsonValue: JsonValue, field: FieldInfo, options: JsonReadOptions): void; declare const tokenNull: unique symbol; declare const tokenIgnoredUnknownEnum: unique symbol; declare function readEnum(type: EnumType, json: JsonValue, ignoreUnknownFields: boolean, nullAsZeroValue: false): number | typeof tokenIgnoredUnknownEnum | typeof tokenNull; declare function readEnum(type: EnumType, json: JsonValue, ignoreUnknownFields: boolean, nullAsZeroValue: true): number | typeof tokenIgnoredUnknownEnum; declare function readScalar(type: ScalarType, json: JsonValue | null | undefined): ScalarValue; declare function readScalar(type: ScalarType, json: JsonValue | null | undefined, longType: LongType): ScalarValue; declare function readScalar(type: ScalarType, json: JsonValue | null | undefined, longType: LongType, nullAsZeroValue: true): ScalarValue; declare function readScalar(type: ScalarType, json: JsonValue | null | undefined, longType: LongType, nullAsZeroValue: false): ScalarValue | typeof tokenNull; declare function readMapKey(type: ScalarType, json: JsonValue): string; /** * Resets the field, so that isFieldSet() will return false. */ export declare function clearField(field: FieldInfo, target: Record): void; declare function writeField(field: FieldInfo, value: unknown, options: JsonWriteOptions): JsonValue | undefined; declare function writeScalar(type: ScalarType, value: unknown): string | number | boolean; declare function writeEnum(type: EnumType, value: unknown, enumAsInteger: boolean): string | number | null; export { readEnum as jsonReadEnum, readField as jsonReadField, readMapKey as jsonReadMapKey, readScalar as jsonReadScalar, readMessage as jsonReadMessage, writeEnum as jsonWriteEnum, writeField as jsonWriteField, writeScalar as jsonWriteScalar, writeMessage as jsonWriteMessage, makeReadOptions as jsonMakeReadOptions, makeWriteOptions as jsonMakeWriteOptions, jsonDebugValue, };