% DO NOT EDIT, generated by generate_docs.py.
google.protobuf.message¶
包含一个协议消息的抽象基类。
- exception google.protobuf.message.DecodeError¶
在对信息进行反序列化时产生的异常。
- args¶
- with_traceback()¶
Exception.with_traceback(tb)
—— 设置self.__traceback__
为tb
并返回self
。
- exception google.protobuf.message.EncodeError¶
在对信息进行序列化时出现的异常。
- args¶
- with_traceback()¶
Exception.with_traceback(tb)
—— 设置self.__traceback__
为tb
并返回self
。
- exception google.protobuf.message.Error¶
Base error type for this module.
- args¶
- with_traceback()¶
Exception.with_traceback(tb)
—— 设置self.__traceback__
为tb
并返回self
。
- class google.protobuf.message.Message¶
该模块的基本错误类型。
协议消息类几乎总是由协议编译器生成。这些生成的类型对消息进行子类化,并实现如下所示的方法。
- ByteSize()¶
返回该消息的序列化大小。
递归调用所有包含的信息的
ByteSize()
。- 返回:
int:序列化此信息所需的字节数。
- Clear()¶
清除信息中设置的所有数据。
- ClearExtension(extension_handle)¶
清除一个给定的扩展名的内容。
- 参数:
extension_handle
:要清除的扩展的句柄。
- ClearField(field_name)¶
清除一个给定字段的内容。
在一个 oneof 组内,清除字段集。如果名称既不是指定义的字段,也不是指 oneof 组,就会出现
ValueError
。- 参数:
field_name
(字符串):要检查是否存在的字段的名称。- 触发:
ValueError:如果
field_name
不是这个消息的成员。
- CopyFrom(other_msg)¶
将指定信息的内容复制到当前信息中。
该方法清除当前消息,然后使用 MergeFrom 合并指定的消息。
- 参数:
other_msg (Message): A message to copy into the current one.
- DESCRIPTOR = None¶
The
google.protobuf.descriptor.Descriptor
for this message type.
- DiscardUnknownFields()¶
Clears all fields in the
UnknownFieldSet
.This operation is recursive for nested message.
- classmethod FromString(s)¶
- HasExtension(extension_handle)¶
Checks if a certain extension is present for this message.
Extensions are retrieved using the
Extensions
mapping (if present).- 参数:
extension_handle: The handle for the extension to check.
- 返回:
bool: Whether the extension is present for this message.
- 触发:
- KeyError: if the extension is repeated. Similar to repeated fields,
there is no separate notion of presence: a “not present” repeated extension is an empty list.
- HasField(field_name)¶
Checks if a certain field is set for the message.
For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor,
ValueError
will be raised.- 参数:
field_name
(字符串):要检查是否存在的字段的名称。- 返回:
bool: Whether a value has been set for the named field.
- 触发:
ValueError:如果
field_name
不是这个消息的成员。
- IsInitialized()¶
Checks if the message is initialized.
- 返回:
bool: The method returns True if the message is initialized (i.e. all of its required fields are set).
- ListFields()¶
Returns a list of (FieldDescriptor, value) tuples for present fields.
A message field is non-empty if HasField() would return true. A singular primitive field is non-empty if HasField() would return true in proto2 or it is non zero in proto3. A repeated field is non-empty if it contains at least one element. The fields are ordered by field number.
- 返回:
list[tuple(FieldDescriptor, value)]: field descriptors and values for all fields in the message which are not empty. The values vary by field type.
- MergeFrom(other_msg)¶
Merges the contents of the specified message into current message.
This method merges the contents of the specified message into the current message. Singular fields that are set in the specified message overwrite the corresponding fields in the current message. Repeated fields are appended. Singular sub-messages and groups are recursively merged.
- 参数:
other_msg (Message): A message to merge into the current message.
- MergeFromString(serialized)¶
Merges serialized protocol buffer data into this message.
When we find a field in serialized that is already present in this message:
If it’s a “repeated” field, we append to the end of our list.
Else, if it’s a scalar, we overwrite our field.
Else, (it’s a nonrepeated composite), we recursively merge into the existing composite.
- 参数:
- serialized (bytes): Any object that allows us to call
memoryview(serialized)
to access a string of bytes using the buffer interface.
- 返回:
int: The number of bytes read from serialized. For non-group messages, this will always be len(serialized), but for messages which are actually groups, this will generally be less than len(serialized), since we must stop when we reach an
END_GROUP
tag. Note that if we do stop because of anEND_GROUP
tag, the number of bytes returned does not include the bytes for theEND_GROUP
tag information.- 触发:
DecodeError: if the input cannot be parsed.
- ParseFromString(serialized)¶
Parse serialized protocol buffer data into this message.
Like
MergeFromString()
, except we clear the object first.
- static RegisterExtension(extension_handle)¶
- SerializePartialToString(**kwargs)¶
Serializes the protocol message to a binary string.
This method is similar to SerializeToString but doesn’t check if the message is initialized.
- Keyword Args:
- deterministic (bool): If true, requests deterministic serialization
of the protobuf, with predictable ordering of map keys.
- 返回:
bytes: A serialized representation of the partial message.
- SerializeToString(**kwargs)¶
Serializes the protocol message to a binary string.
- Keyword Args:
- deterministic (bool): If true, requests deterministic serialization
of the protobuf, with predictable ordering of map keys.
- 返回:
A binary string representation of the message if all of the required fields in the message are set (i.e. the message is initialized).
- 触发:
EncodeError: if the message isn’t initialized (see
IsInitialized()
).
- SetInParent()¶
Mark this as present in the parent.
This normally happens automatically when you assign a field of a sub-message, but sometimes you want to make the sub-message present while keeping it empty. If you find yourself using this, you may want to reconsider your design.
- UnknownFields()¶
Returns the UnknownFieldSet.
- 返回:
UnknownFieldSet: The unknown fields stored in this message.
- WhichOneof(oneof_group)¶
Returns the name of the field that is set inside a oneof group.
If no field is set, returns None.
- 参数:
oneof_group (str): the name of the oneof group to check.
- 返回:
str or None: The name of the group that is set, or None.
- 触发:
ValueError: no group with the given name exists