code: def MakeClass(descriptor):
      """Construct a class object for a protobuf described by descriptor.
  
      Composite descriptors are handled by defining the new class as a member of the
      parent class, recursing as deep as necessary.
      This is the dynamic equivalent to:
  
      class Parent(message.Message):
        __metaclass__ = GeneratedProtocolMessageType
        DESCRIPTOR = descriptor
        class Child(message.Message):
          __metaclass__ = GeneratedProtocolMessageType
          DESCRIPTOR = descriptor.nested_types[0]
  
      Sample usage:
        file_descriptor = descriptor_pb2.FileDescriptorProto()
        file_descriptor.ParseFromString(proto2_string)
        msg_descriptor = descriptor.MakeDescriptor(file_descriptor.message_type[0])
        msg_class = reflection.MakeClass(msg_descriptor)
        msg = msg_class()
  
      Args:
        descriptor: A descriptor.Descriptor object describing the protobuf.
      Returns:
        The Message class object described by the descriptor.
      """
      if descriptor in MESSAGE_CLASS_CACHE:
          return MESSAGE_CLASS_CACHE[descriptor]
  
      attributes = {}
      for name, nested_type in descriptor.nested_types_by_name.items():
          attributes[name] = MakeClass(nested_type)
  
      attributes[
          GeneratedProtocolMessageType._DESCRIPTOR_KEY
      ] = descriptor
  
      result = GeneratedProtocolMessageType(
          str(descriptor.name), (message.Message,), attributes
      )
      MESSAGE_CLASS_CACHE[descriptor] = result
      return result
  
imports: from google.protobuf.internal import api_implementation
  from google.protobuf import message
label_desc: Use image node_id 2 for calling a global function with example usage: MakeClass(descriptor) and returns: result, MESSAGE_CLASS_CACHE