protobuf - Registry for Google Protocol Buffer messages and enums¶
Overview¶
This module provides central registry for Google Protocol Buffer messages and enums.
The generated *_pb2.py
protobuf files could be registered using register_decriptor
or load_registered
function. The registry could be then used to obtain information
about protobuf messages or enum types, or to create message instances or enum values.
Constants¶
- firebird.base.protobuf.PROTO_EMPTY = 'google.protobuf.Empty'¶
Name of well-known EMPTY protobuf message (for use with
create_message()
)
- firebird.base.protobuf.PROTO_ANY = 'google.protobuf.Any'¶
Name of well-known ANY protobuf message (for use with
create_message()
)
- firebird.base.protobuf.PROTO_DURATION = 'google.protobuf.Duration'¶
Name of well-known DURATION protobuf message (for use with
create_message()
)
- firebird.base.protobuf.PROTO_TIMESTAMP = 'google.protobuf.Timestamp'¶
Name of well-known TIMESTAMP protobuf message (for use with
create_message()
)
- firebird.base.protobuf.PROTO_STRUCT = 'google.protobuf.Struct'¶
Name of well-known STRUCT protobuf message (for use with
create_message()
)
- firebird.base.protobuf.PROTO_VALUE = 'google.protobuf.Value'¶
Name of well-known VALUE protobuf message (for use with
create_message()
)
- firebird.base.protobuf.PROTO_LISTVALUE = 'google.protobuf.ListValue'¶
Name of well-known LISTVALUE protobuf message (for use with
create_message()
)
- firebird.base.protobuf.PROTO_FIELDMASK = 'google.protobuf.FieldMask'¶
Name of well-known FIELDMASK protobuf message (for use with
create_message()
)
Functions¶
- firebird.base.protobuf.register_decriptor(file_descriptor) None [source]¶
Registers enums and messages defined by protobuf file DESCRIPTOR.
- Return type:
None
- firebird.base.protobuf.load_registered(group: str) None [source]¶
Load registered protobuf packages.
Protobuf packages must register the pb2-file DESCRIPTOR in
entry_points
section ofsetup.cfg
orpyproject.toml
file.- Parameters:
group (str) – Entry-point group name.
- Return type:
None
Example
# setup.cfg: [options.entry_points] firebird.base.protobuf = firebird.base.lib_a = firebird.base.lib_a_pb2:DESCRIPTOR firebird.base.lib_b = firebird.base.lib_b_pb2:DESCRIPTOR firebird.base.lib_c = firebird.base.lib_c_pb2:DESCRIPTOR # pyproject.toml [project.entry-points."firebird.base.protobuf"] "firebird.base.lib_a" = "firebird.base.lib_a_pb2:DESCRIPTOR" "firebird.base.lib_b" = "firebird.base.lib_b_pb2:DESCRIPTOR" "firebird.base.lib_c" = "firebird.base.lib_c_pb2:DESCRIPTOR" # will be loaded with: load_registered('firebird.base.protobuf')
- firebird.base.protobuf.is_msg_registered(name: str) bool [source]¶
Returns True if specified
name
refers to registered protobuf message type.
- firebird.base.protobuf.is_enum_registered(name: str) bool [source]¶
Returns True if specified
name
refers to registered protobuf enum type.
- firebird.base.protobuf.get_enum_type(name: str) ProtoEnumType [source]¶
Returns wrapper instance for protobuf enum type with specified
name
.
- firebird.base.protobuf.get_enum_value_name(enum_type_name: str, value: int) str [source]¶
Returns name for the enum value.
- firebird.base.protobuf.create_message(name: str, serialized: bytes = None) Message [source]¶
Returns new protobuf message instance.
- firebird.base.protobuf.get_enum_field_type(msg, field_name: str) str [source]¶
Returns name of enum type for message enum field.
Data classes¶
- class firebird.base.protobuf.ProtoMessageType(name: str, constructor: Callable)[source]¶
Bases:
Distinct
Google protobuf message type.
- class firebird.base.protobuf.ProtoEnumType(descriptor: EnumDescriptor)[source]¶
Bases:
Distinct
Google protobuf enum type
- Parameters:
descriptor (EnumDescriptor) –
- items()[source]¶
Return a list of the (name, value) pairs of the enum.
These are returned in the order they were defined in the .proto file.
- keys()[source]¶
Return a list of the string names in the enum.
These are returned in the order they were defined in the .proto file.
- values()[source]¶
Return a list of the integer values in the enum.
These are returned in the order they were defined in the .proto file.
- descriptor: EnumDescriptor¶