1# Protocol Buffers - Google's data interchange format 
    2# Copyright 2008 Google Inc.  All rights reserved. 
    3# 
    4# Use of this source code is governed by a BSD-style 
    5# license that can be found in the LICENSE file or at 
    6# https://developers.google.com/open-source/licenses/bsd 
    7 
    8"""Protocol message implementation hooks for C++ implementation. 
    9 
    10Contains helper functions used to create protocol message classes from 
    11Descriptor objects at runtime backed by the protocol buffer C++ API. 
    12""" 
    13 
    14__author__ = 'tibell@google.com (Johan Tibell)' 
    15 
    16from google.protobuf.internal import api_implementation 
    17 
    18 
    19# pylint: disable=protected-access 
    20_message = api_implementation._c_module 
    21# TODO: Remove this import after fix api_implementation 
    22if _message is None: 
    23  from google.protobuf.pyext import _message 
    24 
    25 
    26class GeneratedProtocolMessageType(_message.MessageMeta): 
    27 
    28  """Metaclass for protocol message classes created at runtime from Descriptors. 
    29 
    30  The protocol compiler currently uses this metaclass to create protocol 
    31  message classes at runtime.  Clients can also manually create their own 
    32  classes at runtime, as in this example: 
    33 
    34  mydescriptor = Descriptor(.....) 
    35  factory = symbol_database.Default() 
    36  factory.pool.AddDescriptor(mydescriptor) 
    37  MyProtoClass = message_factory.GetMessageClass(mydescriptor) 
    38  myproto_instance = MyProtoClass() 
    39  myproto.foo_field = 23 
    40  ... 
    41 
    42  The above example will not work for nested types. If you wish to include them, 
    43  use reflection.MakeClass() instead of manually instantiating the class in 
    44  order to create the appropriate class structure. 
    45  """ 
    46 
    47  # Must be consistent with the protocol-compiler code in 
    48  # proto2/compiler/internal/generator.*. 
    49  _DESCRIPTOR_KEY = 'DESCRIPTOR'