Go to the documentation of this file.
35 """Contains an abstract base class for protocol messages."""
37 __author__ =
'robinson@google.com (Will Robinson)'
46 """Abstract base class for protocol messages.
48 Protocol message classes are almost always generated by the protocol
49 compiler. These generated types subclass Message and implement the methods
52 TODO(robinson): Link to an HTML document here.
54 TODO(robinson): Document that instances of this class will also
55 have an Extensions attribute with __getitem__ and __setitem__.
56 Again, not sure how to best convey this.
58 TODO(robinson): Document that the class must also have a static
59 RegisterExtension(extension_field) method.
60 Not sure how to best express at this point.
75 """Recursively compares two messages by value and structure."""
76 raise NotImplementedError
80 return not self == other_msg
83 raise TypeError(
'unhashable object')
86 """Outputs a human-readable representation of the message."""
87 raise NotImplementedError
90 """Outputs a human-readable representation of the message."""
91 raise NotImplementedError
94 """Merges the contents of the specified message into current message.
96 This method merges the contents of the specified message into the current
97 message. Singular fields that are set in the specified message overwrite
98 the corresponding fields in the current message. Repeated fields are
99 appended. Singular sub-messages and groups are recursively merged.
102 other_msg: Message to merge into the current message.
104 raise NotImplementedError
107 """Copies the content of the specified message into the current message.
109 The method clears the current message and then merges the specified
110 message using MergeFrom.
113 other_msg: Message to copy into the current one.
115 if self
is other_msg:
121 """Clears all data that was set in the message."""
122 raise NotImplementedError
125 """Mark this as present in the parent.
127 This normally happens automatically when you assign a field of a
128 sub-message, but sometimes you want to make the sub-message
129 present while keeping it empty. If you find yourself using this,
130 you may want to reconsider your design."""
131 raise NotImplementedError
134 """Checks if the message is initialized.
137 The method returns True if the message is initialized (i.e. all of its
138 required fields are set).
140 raise NotImplementedError
149 """Merges serialized protocol buffer data into this message.
151 When we find a field in |serialized| that is already present
153 - If it's a "repeated" field, we append to the end of our list.
154 - Else, if it's a scalar, we overwrite our field.
155 - Else, (it's a nonrepeated composite), we recursively merge
156 into the existing composite.
158 TODO(robinson): Document handling of unknown fields.
161 serialized: Any object that allows us to call buffer(serialized)
162 to access a string of bytes using the buffer interface.
164 TODO(robinson): When we switch to a helper, this will return None.
167 The number of bytes read from |serialized|.
168 For non-group messages, this will always be len(serialized),
169 but for messages which are actually groups, this will
170 generally be less than len(serialized), since we must
171 stop when we reach an END_GROUP tag. Note that if
172 we *do* stop because of an END_GROUP tag, the number
173 of bytes returned does not include the bytes
174 for the END_GROUP tag information.
177 message.DecodeError if the input cannot be parsed.
179 raise NotImplementedError
182 """Parse serialized protocol buffer data into this message.
184 Like MergeFromString(), except we clear the object first.
190 """Serializes the protocol message to a binary string.
193 **kwargs: Keyword arguments to the serialize method, accepts
194 the following keyword args:
195 deterministic: If true, requests deterministic serialization of the
196 protobuf, with predictable ordering of map keys.
199 A binary string representation of the message if all of the required
200 fields in the message are set (i.e. the message is initialized).
203 message.EncodeError if the message isn't initialized.
205 raise NotImplementedError
208 """Serializes the protocol message to a binary string.
210 This method is similar to SerializeToString but doesn't check if the
211 message is initialized.
214 **kwargs: Keyword arguments to the serialize method, accepts
215 the following keyword args:
216 deterministic: If true, requests deterministic serialization of the
217 protobuf, with predictable ordering of map keys.
220 A string representation of the partial message.
222 raise NotImplementedError
241 """Returns a list of (FieldDescriptor, value) tuples for all
242 fields in the message which are not empty. A message field is
243 non-empty if HasField() would return true. A singular primitive field
244 is non-empty if HasField() would return true in proto2 or it is non zero
245 in proto3. A repeated field is non-empty if it contains at least one
246 element. The fields are ordered by field number"""
247 raise NotImplementedError
250 """Checks if a certain field is set for the message, or if any field inside
251 a oneof group is set. Note that if the field_name is not defined in the
252 message descriptor, ValueError will be raised."""
253 raise NotImplementedError
256 """Clears the contents of a given field, or the field set inside a oneof
257 group. If the name neither refers to a defined field or oneof group,
258 ValueError is raised."""
259 raise NotImplementedError
262 """Returns the name of the field that is set inside a oneof group, or
263 None if no field is set. If no group with the given name exists, ValueError
265 raise NotImplementedError
268 raise NotImplementedError
271 raise NotImplementedError
274 """Returns the UnknownFieldSet."""
275 raise NotImplementedError
278 raise NotImplementedError
281 """Returns the serialized size of this message.
282 Recursively calls ByteSize() on all contained messages.
284 raise NotImplementedError
287 """Internal method used by the protocol message implementation.
288 Clients should not call this directly.
290 Sets a listener that this message will call on certain state transitions.
292 The purpose of this method is to register back-edges from children to
293 parents at runtime, for the purpose of setting "has" bits and
294 byte-size-dirty bits in the parent and ancestor objects whenever a child or
295 descendant object is modified.
297 If the client wants to disconnect this Message from the object tree, she
298 explicitly sets callback to None.
300 If message_listener is None, unregisters any existing listener. Otherwise,
301 message_listener must implement the MessageListener interface in
302 internal/message_listener.py, and we discard any listener registered
303 via a previous _SetListener() call.
305 raise NotImplementedError
308 """Support the pickle protocol."""
312 """Support the pickle protocol."""
314 serialized = state[
'serialized']
317 if not isinstance(serialized, bytes):
318 serialized = serialized.encode(
'latin1')
def HasField(self, field_name)
def __deepcopy__(self, memo=None)
def SerializePartialToString(self, **kwargs)
def __eq__(self, other_msg)
def DiscardUnknownFields(self)
def WhichOneof(self, oneof_group)
def ParseFromString(self, serialized)
def _SetListener(self, message_listener)
def SerializeToString(self, **kwargs)
def ClearExtension(self, extension_handle)
def __setstate__(self, state)
def CopyFrom(self, other_msg)
def ClearField(self, field_name)
def HasExtension(self, extension_handle)
def MergeFromString(self, serialized)
def MergeFrom(self, other_msg)
def __ne__(self, other_msg)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:25