GitHub

descriptor

API reference for descriptor.

Resolved protobuf descriptors (Effect's protobuf/ProtobufDescriptor).

make resolves FileDescriptorProto s, as protoc writes them, into a Registry of message, enum, extension and service descriptors, which pyfect.protobuf.message encodes and decodes by. from_file_descriptor_set reads the output of protoc --descriptor_set_out. The types and descriptors of google/protobuf/descriptor.proto itself are in pyfect.protobuf.descriptor_proto.

Types

TypeDefinitionDescription
EditionNametype EditionName = Literal['proto2', 'proto3', '2023', '2024', '2026']

The editions resolved. proto2 and proto3 files are the editions of their syntax.

FieldDescriptortype FieldDescriptor = SingularFieldDescriptor | ListFieldDescriptor | MapFieldDescriptor
JsTypetype JsType = Literal['bigint', 'number', 'string']

How a 64-bit integer value is held, as [jstype = ...] asks: an int (Effect's bigint), a float (JS_NUMBER) or a decimal str (JS_STRING).

Presencetype Presence = Literal['implicit', 'explicit', 'required']

When a singular field is present: "implicit" when not its zero value (proto3 without optional), "explicit" when set, even to its zero value, "required" always (proto2 required).

ScalarTypetype ScalarType = Literal['double', 'float', 'int64', 'uint64', 'int32', 'fixed64', 'fixed32', 'bool', 'string', 'bytes', 'uint32', 'sfixed32', 'sfixed64', 'sint32', 'sint64']
ValueTypetype ValueType = ScalarValueType | EnumValueType | MessageValueType

The type of a singular field's value, a list's elements or a map's values.

Classes

Functions

make

make(files) -> Result[Registry, ProtobufDescriptorError]

Resolves files together; each file's imports must be among them.

ParameterTypeDescription
filesIterable[FileDescriptorProto]

Returns Result[Registry, ProtobufDescriptorError]

def make(files: Iterable[FileDescriptorProto]) -> Result[Registry, ProtobufDescriptorError]:
    """Resolves ``files`` together; each file's imports must be among them."""
    try:
        return Ok(_resolve.resolve(files))
    except _resolve.ResolveError as error:
        return Err(ProtobufDescriptorError(str(error)))

from_file_descriptor_set

from_file_descriptor_set(data) -> Result[Registry, ProtobufDescriptorError]

Resolves the files of an encoded FileDescriptorSet.

ParameterTypeDescription
databytes | bytearray | memoryview

Returns Result[Registry, ProtobufDescriptorError]

def from_file_descriptor_set(
    data: bytes | bytearray | memoryview,
) -> Result[Registry, ProtobufDescriptorError]:
    """Resolves the files of an encoded ``FileDescriptorSet``."""
    try:
        decoded = _binary.decode(FILE_DESCRIPTOR_SET, data)
    except _binary.Failure as failure:
        return Err(ProtobufDescriptorError(failure.message))
    return make(cast("FileDescriptorSet", decoded).get("file", []))