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 # http://code.google.com/p/protobuf/ | 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. |
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 | |
40 class Error(Exception): pass | 39 class Error(Exception): pass |
41 class DecodeError(Error): pass | 40 class DecodeError(Error): pass |
42 class EncodeError(Error): pass | 41 class EncodeError(Error): pass |
43 | 42 |
44 | 43 |
45 class Message(object): | 44 class Message(object): |
46 | 45 |
47 """Abstract base class for protocol messages. | 46 """Abstract base class for protocol messages. |
48 | 47 |
49 Protocol message classes are almost always generated by the protocol | 48 Protocol message classes are almost always generated by the protocol |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 but for messages which are actually groups, this will | 169 but for messages which are actually groups, this will |
171 generally be less than len(serialized), since we must | 170 generally be less than len(serialized), since we must |
172 stop when we reach an END_GROUP tag. Note that if | 171 stop when we reach an END_GROUP tag. Note that if |
173 we *do* stop because of an END_GROUP tag, the number | 172 we *do* stop because of an END_GROUP tag, the number |
174 of bytes returned does not include the bytes | 173 of bytes returned does not include the bytes |
175 for the END_GROUP tag information. | 174 for the END_GROUP tag information. |
176 """ | 175 """ |
177 raise NotImplementedError | 176 raise NotImplementedError |
178 | 177 |
179 def ParseFromString(self, serialized): | 178 def ParseFromString(self, serialized): |
180 """Like MergeFromString(), except we clear the object first.""" | 179 """Parse serialized protocol buffer data into this message. |
| 180 |
| 181 Like MergeFromString(), except we clear the object first and |
| 182 do not return the value that MergeFromString returns. |
| 183 """ |
181 self.Clear() | 184 self.Clear() |
182 self.MergeFromString(serialized) | 185 self.MergeFromString(serialized) |
183 | 186 |
184 def SerializeToString(self): | 187 def SerializeToString(self): |
185 """Serializes the protocol message to a binary string. | 188 """Serializes the protocol message to a binary string. |
186 | 189 |
187 Returns: | 190 Returns: |
188 A binary string representation of the message if all of the required | 191 A binary string representation of the message if all of the required |
189 fields in the message are set (i.e. the message is initialized). | 192 fields in the message are set (i.e. the message is initialized). |
190 | 193 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 # """ | 225 # """ |
223 def ListFields(self): | 226 def ListFields(self): |
224 """Returns a list of (FieldDescriptor, value) tuples for all | 227 """Returns a list of (FieldDescriptor, value) tuples for all |
225 fields in the message which are not empty. A singular field is non-empty | 228 fields in the message which are not empty. A singular field is non-empty |
226 if HasField() would return true, and a repeated field is non-empty if | 229 if HasField() would return true, and a repeated field is non-empty if |
227 it contains at least one element. The fields are ordered by field | 230 it contains at least one element. The fields are ordered by field |
228 number""" | 231 number""" |
229 raise NotImplementedError | 232 raise NotImplementedError |
230 | 233 |
231 def HasField(self, field_name): | 234 def HasField(self, field_name): |
232 """Checks if a certain field is set for the message. Note if the | 235 """Checks if a certain field is set for the message, or if any field inside |
233 field_name is not defined in the message descriptor, ValueError will be | 236 a oneof group is set. Note that if the field_name is not defined in the |
234 raised.""" | 237 message descriptor, ValueError will be raised.""" |
235 raise NotImplementedError | 238 raise NotImplementedError |
236 | 239 |
237 def ClearField(self, field_name): | 240 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.""" |
238 raise NotImplementedError | 250 raise NotImplementedError |
239 | 251 |
240 def HasExtension(self, extension_handle): | 252 def HasExtension(self, extension_handle): |
241 raise NotImplementedError | 253 raise NotImplementedError |
242 | 254 |
243 def ClearExtension(self, extension_handle): | 255 def ClearExtension(self, extension_handle): |
244 raise NotImplementedError | 256 raise NotImplementedError |
245 | 257 |
246 def ByteSize(self): | 258 def ByteSize(self): |
247 """Returns the serialized size of this message. | 259 """Returns the serialized size of this message. |
(...skipping 23 matching lines...) Expand all Loading... |
271 raise NotImplementedError | 283 raise NotImplementedError |
272 | 284 |
273 def __getstate__(self): | 285 def __getstate__(self): |
274 """Support the pickle protocol.""" | 286 """Support the pickle protocol.""" |
275 return dict(serialized=self.SerializePartialToString()) | 287 return dict(serialized=self.SerializePartialToString()) |
276 | 288 |
277 def __setstate__(self, state): | 289 def __setstate__(self, state): |
278 """Support the pickle protocol.""" | 290 """Support the pickle protocol.""" |
279 self.__init__() | 291 self.__init__() |
280 self.ParseFromString(state['serialized']) | 292 self.ParseFromString(state['serialized']) |
OLD | NEW |