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#
| Type | Definition | Description |
|---|---|---|
EditionName | type EditionName = Literal['proto2', 'proto3', '2023', '2024', '2026'] | The editions resolved. proto2 and proto3 files are the editions of their syntax. |
FieldDescriptor | type FieldDescriptor = SingularFieldDescriptor | ListFieldDescriptor | MapFieldDescriptor | |
JsType | type JsType = Literal['bigint', 'number', 'string'] | How a 64-bit integer value is held, as |
Presence | type Presence = Literal['implicit', 'explicit', 'required'] | When a singular field is present: |
ScalarType | type ScalarType = Literal['double', 'float', 'int64', 'uint64', 'int32', 'fixed64', 'fixed32', 'bool', 'string', 'bytes', 'uint32', 'sfixed32', 'sfixed64', 'sint32', 'sint64'] | |
ValueType | type 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.
| Parameter | Type | Description |
|---|---|---|
files | Iterable[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.
| Parameter | Type | Description |
|---|---|---|
data | bytes | 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", []))