Index: third_party/protobuf/python/google/protobuf/pyext/cpp_message.py |
diff --git a/third_party/protobuf/python/google/protobuf/internal/message_cpp_test.py b/third_party/protobuf/python/google/protobuf/pyext/cpp_message.py |
similarity index 56% |
copy from third_party/protobuf/python/google/protobuf/internal/message_cpp_test.py |
copy to third_party/protobuf/python/google/protobuf/pyext/cpp_message.py |
index 0d84b3207bdd0a5f5b7202e9ad67d6cfcf55e0d3..b215211ee581f2bfa4fa8d06cf3ca3fc27941f56 100644 |
--- a/third_party/protobuf/python/google/protobuf/internal/message_cpp_test.py |
+++ b/third_party/protobuf/python/google/protobuf/pyext/cpp_message.py |
@@ -1,8 +1,6 @@ |
-#! /usr/bin/python |
-# |
# Protocol Buffers - Google's data interchange format |
# Copyright 2008 Google Inc. All rights reserved. |
-# http://code.google.com/p/protobuf/ |
+# https://developers.google.com/protocol-buffers/ |
# |
# Redistribution and use in source and binary forms, with or without |
# modification, are permitted provided that the following conditions are |
@@ -30,16 +28,38 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-"""Tests for google.protobuf.internal.message_cpp.""" |
+"""Protocol message implementation hooks for C++ implementation. |
+ |
+Contains helper functions used to create protocol message classes from |
+Descriptor objects at runtime backed by the protocol buffer C++ API. |
+""" |
+ |
+__author__ = 'tibell@google.com (Johan Tibell)' |
+ |
+from google.protobuf.pyext import _message |
+ |
+ |
+class GeneratedProtocolMessageType(_message.MessageMeta): |
-__author__ = 'shahms@google.com (Shahms King)' |
+ """Metaclass for protocol message classes created at runtime from Descriptors. |
-import os |
-os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' |
+ 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: |
-import unittest |
-from google.protobuf.internal.message_test import * |
+ mydescriptor = Descriptor(.....) |
+ class MyProtoClass(Message): |
+ __metaclass__ = GeneratedProtocolMessageType |
+ DESCRIPTOR = mydescriptor |
+ myproto_instance = MyProtoClass() |
+ myproto.foo_field = 23 |
+ ... |
+ The above example will not work for nested types. If you wish to include them, |
+ use reflection.MakeClass() instead of manually instantiating the class in |
+ order to create the appropriate class structure. |
+ """ |
-if __name__ == '__main__': |
- unittest.main() |
+ # Must be consistent with the protocol-compiler code in |
+ # proto2/compiler/internal/generator.*. |
+ _DESCRIPTOR_KEY = 'DESCRIPTOR' |