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 # http://code.google.com/p/protobuf/ |
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. |
11 # * Redistributions in binary form must reproduce the above | 11 # * Redistributions in binary form must reproduce the above |
12 # copyright notice, this list of conditions and the following disclaimer | 12 # copyright notice, this list of conditions and the following disclaimer |
13 # in the documentation and/or other materials provided with the | 13 # in the documentation and/or other materials provided with the |
(...skipping 15 matching lines...) Expand all Loading... |
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 # TODO(robinson): We should just make these methods all "pure-virtual" and move | 31 # TODO(robinson): We should just make these methods all "pure-virtual" and move |
32 # all implementation out, into reflection.py for now. | 32 # all implementation out, into reflection.py for now. |
33 | 33 |
34 | 34 |
35 """Contains an abstract base class for protocol messages.""" | 35 """Contains an abstract base class for protocol messages.""" |
36 | 36 |
37 __author__ = 'robinson@google.com (Will Robinson)' | 37 __author__ = 'robinson@google.com (Will Robinson)' |
38 | 38 |
| 39 |
39 class Error(Exception): pass | 40 class Error(Exception): pass |
40 class DecodeError(Error): pass | 41 class DecodeError(Error): pass |
41 class EncodeError(Error): pass | 42 class EncodeError(Error): pass |
42 | 43 |
43 | 44 |
44 class Message(object): | 45 class Message(object): |
45 | 46 |
46 """Abstract base class for protocol messages. | 47 """Abstract base class for protocol messages. |
47 | 48 |
48 Protocol message classes are almost always generated by the protocol | 49 Protocol message classes are almost always generated by the protocol |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 but for messages which are actually groups, this will | 170 but for messages which are actually groups, this will |
170 generally be less than len(serialized), since we must | 171 generally be less than len(serialized), since we must |
171 stop when we reach an END_GROUP tag. Note that if | 172 stop when we reach an END_GROUP tag. Note that if |
172 we *do* stop because of an END_GROUP tag, the number | 173 we *do* stop because of an END_GROUP tag, the number |
173 of bytes returned does not include the bytes | 174 of bytes returned does not include the bytes |
174 for the END_GROUP tag information. | 175 for the END_GROUP tag information. |
175 """ | 176 """ |
176 raise NotImplementedError | 177 raise NotImplementedError |
177 | 178 |
178 def ParseFromString(self, serialized): | 179 def ParseFromString(self, serialized): |
179 """Parse serialized protocol buffer data into this message. | 180 """Like MergeFromString(), except we clear the object first.""" |
180 | |
181 Like MergeFromString(), except we clear the object first and | |
182 do not return the value that MergeFromString returns. | |
183 """ | |
184 self.Clear() | 181 self.Clear() |
185 self.MergeFromString(serialized) | 182 self.MergeFromString(serialized) |
186 | 183 |
187 def SerializeToString(self): | 184 def SerializeToString(self): |
188 """Serializes the protocol message to a binary string. | 185 """Serializes the protocol message to a binary string. |
189 | 186 |
190 Returns: | 187 Returns: |
191 A binary string representation of the message if all of the required | 188 A binary string representation of the message if all of the required |
192 fields in the message are set (i.e. the message is initialized). | 189 fields in the message are set (i.e. the message is initialized). |
193 | 190 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 # """ | 222 # """ |
226 def ListFields(self): | 223 def ListFields(self): |
227 """Returns a list of (FieldDescriptor, value) tuples for all | 224 """Returns a list of (FieldDescriptor, value) tuples for all |
228 fields in the message which are not empty. A singular field is non-empty | 225 fields in the message which are not empty. A singular field is non-empty |
229 if HasField() would return true, and a repeated field is non-empty if | 226 if HasField() would return true, and a repeated field is non-empty if |
230 it contains at least one element. The fields are ordered by field | 227 it contains at least one element. The fields are ordered by field |
231 number""" | 228 number""" |
232 raise NotImplementedError | 229 raise NotImplementedError |
233 | 230 |
234 def HasField(self, field_name): | 231 def HasField(self, field_name): |
235 """Checks if a certain field is set for the message, or if any field inside | 232 """Checks if a certain field is set for the message. Note if the |
236 a oneof group is set. Note that if the field_name is not defined in the | 233 field_name is not defined in the message descriptor, ValueError will be |
237 message descriptor, ValueError will be raised.""" | 234 raised.""" |
238 raise NotImplementedError | 235 raise NotImplementedError |
239 | 236 |
240 def ClearField(self, field_name): | 237 def ClearField(self, field_name): |
241 """Clears the contents of a given field, or the field set inside a oneof | |
242 group. If the name neither refers to a defined field or oneof group, | |
243 ValueError is raised.""" | |
244 raise NotImplementedError | |
245 | |
246 def WhichOneof(self, oneof_group): | |
247 """Returns the name of the field that is set inside a oneof group, or | |
248 None if no field is set. If no group with the given name exists, ValueError | |
249 will be raised.""" | |
250 raise NotImplementedError | 238 raise NotImplementedError |
251 | 239 |
252 def HasExtension(self, extension_handle): | 240 def HasExtension(self, extension_handle): |
253 raise NotImplementedError | 241 raise NotImplementedError |
254 | 242 |
255 def ClearExtension(self, extension_handle): | 243 def ClearExtension(self, extension_handle): |
256 raise NotImplementedError | 244 raise NotImplementedError |
257 | 245 |
258 def ByteSize(self): | 246 def ByteSize(self): |
259 """Returns the serialized size of this message. | 247 """Returns the serialized size of this message. |
(...skipping 23 matching lines...) Expand all Loading... |
283 raise NotImplementedError | 271 raise NotImplementedError |
284 | 272 |
285 def __getstate__(self): | 273 def __getstate__(self): |
286 """Support the pickle protocol.""" | 274 """Support the pickle protocol.""" |
287 return dict(serialized=self.SerializePartialToString()) | 275 return dict(serialized=self.SerializePartialToString()) |
288 | 276 |
289 def __setstate__(self, state): | 277 def __setstate__(self, state): |
290 """Support the pickle protocol.""" | 278 """Support the pickle protocol.""" |
291 self.__init__() | 279 self.__init__() |
292 self.ParseFromString(state['serialized']) | 280 self.ParseFromString(state['serialized']) |
OLD | NEW |