Public Member Functions | Private Attributes | Static Private Attributes | List of all members
google.protobuf.internal.python_message.GeneratedProtocolMessageType Class Reference
Inheritance diagram for google.protobuf.internal.python_message.GeneratedProtocolMessageType:
Inheritance graph
[legend]

Public Member Functions

def __init__ (cls, name, bases, dictionary)
 
def __init__ (cls, name, bases, dictionary)
 
def __new__ (cls, name, bases, dictionary)
 
def __new__ (cls, name, bases, dictionary)
 

Private Attributes

 _decoders_by_tag
 

Static Private Attributes

string _DESCRIPTOR_KEY = 'DESCRIPTOR'
 

Detailed Description

Metaclass for protocol message classes created at runtime from Descriptors.

We add implementations for all methods described in the Message class.  We
also create properties to allow getting/setting all fields in the protocol
message.  Finally, we create slots to prevent users from accidentally
"setting" nonexistent fields in the protocol message, which then wouldn't get
serialized / deserialized properly.

The protocol compiler currently uses this metaclass to create protocol
message classes at runtime.  Clients can also manually create their own
classes at runtime, as in this example:

mydescriptor = Descriptor(.....)
factory = symbol_database.Default()
factory.pool.AddDescriptor(mydescriptor)
MyProtoClass = factory.GetPrototype(mydescriptor)
myproto_instance = MyProtoClass()
myproto.foo_field = 23
...

Definition at line 80 of file bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py.

Constructor & Destructor Documentation

◆ __init__() [1/2]

def google.protobuf.internal.python_message.GeneratedProtocolMessageType.__init__ (   cls,
  name,
  bases,
  dictionary 
)
Here we perform the majority of our work on the class.
We add enum getters, an __init__ method, implementations
of all Message methods, and properties for all fields
in the protocol type.

Args:
  name: Name of the class (ignored, but required by the
metaclass protocol).
  bases: Base classes of the class we're constructing.
(Should be message.Message).  We ignore this field, but
it's required by the metaclass protocol
  dictionary: The class dictionary of the class we're
constructing.  dictionary[_DESCRIPTOR_KEY] must contain
a Descriptor object describing this protocol message
type.

Definition at line 153 of file bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py.

◆ __init__() [2/2]

def google.protobuf.internal.python_message.GeneratedProtocolMessageType.__init__ (   cls,
  name,
  bases,
  dictionary 
)
Here we perform the majority of our work on the class.
We add enum getters, an __init__ method, implementations
of all Message methods, and properties for all fields
in the protocol type.

Args:
  name: Name of the class (ignored, but required by the
metaclass protocol).
  bases: Base classes of the class we're constructing.
(Should be message.Message).  We ignore this field, but
it's required by the metaclass protocol
  dictionary: The class dictionary of the class we're
constructing.  dictionary[_DESCRIPTOR_KEY] must contain
a Descriptor object describing this protocol message
type.

Definition at line 157 of file protobuf/python/google/protobuf/internal/python_message.py.

Member Function Documentation

◆ __new__() [1/2]

def google.protobuf.internal.python_message.GeneratedProtocolMessageType.__new__ (   cls,
  name,
  bases,
  dictionary 
)
Custom allocation for runtime-generated class types.

We override __new__ because this is apparently the only place
where we can meaningfully set __slots__ on the class we're creating(?).
(The interplay between metaclasses and slots is not very well-documented).

Args:
  name: Name of the class (ignored, but required by the
metaclass protocol).
  bases: Base classes of the class we're constructing.
(Should be message.Message).  We ignore this field, but
it's required by the metaclass protocol
  dictionary: The class dictionary of the class we're
constructing.  dictionary[_DESCRIPTOR_KEY] must contain
a Descriptor object describing this protocol message
type.

Returns:
  Newly-allocated class.

Raises:
  RuntimeError: Generated code only work with python cpp extension.

Definition at line 104 of file protobuf/python/google/protobuf/internal/python_message.py.

◆ __new__() [2/2]

def google.protobuf.internal.python_message.GeneratedProtocolMessageType.__new__ (   cls,
  name,
  bases,
  dictionary 
)
Custom allocation for runtime-generated class types.

We override __new__ because this is apparently the only place
where we can meaningfully set __slots__ on the class we're creating(?).
(The interplay between metaclasses and slots is not very well-documented).

Args:
  name: Name of the class (ignored, but required by the
metaclass protocol).
  bases: Base classes of the class we're constructing.
(Should be message.Message).  We ignore this field, but
it's required by the metaclass protocol
  dictionary: The class dictionary of the class we're
constructing.  dictionary[_DESCRIPTOR_KEY] must contain
a Descriptor object describing this protocol message
type.

Returns:
  Newly-allocated class.

Definition at line 107 of file bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py.

Member Data Documentation

◆ _decoders_by_tag

google.protobuf.internal.python_message.GeneratedProtocolMessageType._decoders_by_tag
private

◆ _DESCRIPTOR_KEY

string google.protobuf.internal.python_message.GeneratedProtocolMessageType._DESCRIPTOR_KEY = 'DESCRIPTOR'
staticprivate

The documentation for this class was generated from the following file:


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:27