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"""Protocol message implementation hooks for C++ implementation.
8
9Contains helper functions used to create protocol message classes from
10Descriptor objects at runtime backed by the protocol buffer C++ API.
11"""
12
13__author__ = 'tibell@google.com (Johan Tibell)'
14
15from google.protobuf.internal import api_implementation
16
17# pylint: disable=protected-access
18_message = api_implementation._c_module
19# TODO: Remove this import after fix api_implementation
20if _message is None:
21 from google.protobuf.pyext import _message
22
23
24class GeneratedProtocolMessageType(_message.MessageMeta):
25 """Metaclass for protocol message classes created at runtime from Descriptors.
26
27 The protocol compiler currently uses this metaclass to create protocol
28 message classes at runtime. Clients can also manually create their own
29 classes at runtime, as in this example:
30
31 mydescriptor = Descriptor(.....)
32 factory = symbol_database.Default()
33 factory.pool.AddDescriptor(mydescriptor)
34 MyProtoClass = message_factory.GetMessageClass(mydescriptor)
35 myproto_instance = MyProtoClass()
36 myproto.foo_field = 23
37 ...
38
39 The above example will not work for nested types. If you wish to include them,
40 use reflection.MakeClass() instead of manually instantiating the class in
41 order to create the appropriate class structure.
42 """
43
44 # Must be consistent with the protocol-compiler code in
45 # proto2/compiler/internal/generator.*.
46 _DESCRIPTOR_KEY = 'DESCRIPTOR'