OLD | NEW |
1 # Protocol Buffers - Google's data interchange format | 1 # Protocol Buffers - Google's data interchange format |
2 # Copyright 2008 Google Inc. All rights reserved. | 2 # Copyright 2008 Google Inc. All rights reserved. |
3 # https://developers.google.com/protocol-buffers/ | 3 # https://developers.google.com/protocol-buffers/ |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 from google.protobuf.internal import api_implementation | 51 from google.protobuf.internal import api_implementation |
52 from google.protobuf import message | 52 from google.protobuf import message |
53 | 53 |
54 | 54 |
55 if api_implementation.Type() == 'cpp': | 55 if api_implementation.Type() == 'cpp': |
56 from google.protobuf.pyext import cpp_message as message_impl | 56 from google.protobuf.pyext import cpp_message as message_impl |
57 else: | 57 else: |
58 from google.protobuf.internal import python_message as message_impl | 58 from google.protobuf.internal import python_message as message_impl |
59 | 59 |
60 # The type of all Message classes. | 60 # The type of all Message classes. |
61 # Part of the public interface. | 61 # Part of the public interface, but normally only used by message factories. |
62 # | |
63 # Used by generated files, but clients can also use it at runtime: | |
64 # mydescriptor = pool.FindDescriptor(.....) | |
65 # class MyProtoClass(Message): | |
66 # __metaclass__ = GeneratedProtocolMessageType | |
67 # DESCRIPTOR = mydescriptor | |
68 GeneratedProtocolMessageType = message_impl.GeneratedProtocolMessageType | 62 GeneratedProtocolMessageType = message_impl.GeneratedProtocolMessageType |
69 | 63 |
70 | 64 |
71 def ParseMessage(descriptor, byte_str): | 65 def ParseMessage(descriptor, byte_str): |
72 """Generate a new Message instance from this Descriptor and a byte string. | 66 """Generate a new Message instance from this Descriptor and a byte string. |
73 | 67 |
74 Args: | 68 Args: |
75 descriptor: Protobuf Descriptor object | 69 descriptor: Protobuf Descriptor object |
76 byte_str: Serialized protocol buffer byte string | 70 byte_str: Serialized protocol buffer byte string |
77 | 71 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 The Message class object described by the descriptor. | 105 The Message class object described by the descriptor. |
112 """ | 106 """ |
113 attributes = {} | 107 attributes = {} |
114 for name, nested_type in descriptor.nested_types_by_name.items(): | 108 for name, nested_type in descriptor.nested_types_by_name.items(): |
115 attributes[name] = MakeClass(nested_type) | 109 attributes[name] = MakeClass(nested_type) |
116 | 110 |
117 attributes[GeneratedProtocolMessageType._DESCRIPTOR_KEY] = descriptor | 111 attributes[GeneratedProtocolMessageType._DESCRIPTOR_KEY] = descriptor |
118 | 112 |
119 return GeneratedProtocolMessageType(str(descriptor.name), (message.Message,), | 113 return GeneratedProtocolMessageType(str(descriptor.name), (message.Message,), |
120 attributes) | 114 attributes) |
OLD | NEW |