The QAbstractProtobufSerializer class is interface that represents basic functions for serialization/deserialization. 更多...
头: | #include <QAbstractProtobufSerializer> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf) |
Since: | Qt 6.5 |
继承者: | |
状态: | 技术预览 |
注意: 此类的所有函数 可重入 .
enum | DeserializationError { NoError, InvalidHeaderError, NoDeserializerError, UnexpectedEndOfStreamError, InvalidFormatError } |
virtual | ~QAbstractProtobufSerializer () |
bool | deserialize (T * object , QByteArrayView data ) const |
QByteArray | serialize (const QProtobufMessage * message ) const |
virtual bool | deserializeMessage (QProtobufMessage * message , const QtProtobufPrivate::QProtobufPropertyOrdering & ordering , QByteArrayView data ) const = 0 |
virtual QByteArray | serializeMessage (const QProtobufMessage * message , const QtProtobufPrivate::QProtobufPropertyOrdering & ordering ) const = 0 |
Q_DECLARE_PROTOBUF_SERIALIZERS ( Type ) | |
Q_PROTOBUF_OBJECT |
The
QProtobufSerializer
class registers serializers/deserializers for classes implementing a protobuf message, inheriting
QProtobufMessage
. These classes are generated automatically, based on a
.proto
file, using the CMake function
qt_add_protobuf
or by running
qtprotobufgen
直接。
This class should be used as a base for specific serializers. The handlers property contains all message-specific serializers and should be used while serialization/deserialization. Inherited classes should reimplement scope of virtual methods that used by registered message serialization/deserialization functions.
This enum contains possible errors that can occur during deserialization. When an error occurs, call deserializationErrorString() to get a human-readable error message.
常量 | 值 | 描述 |
---|---|---|
QAbstractProtobufSerializer::NoError
|
0
|
没有出现错误。 |
QAbstractProtobufSerializer::InvalidHeaderError
|
1
|
Something went wrong while attempting to decode a header in the message. |
QAbstractProtobufSerializer::NoDeserializerError
|
2
|
While deserializing a message, no deserializer was found for a type in the message. |
QAbstractProtobufSerializer::UnexpectedEndOfStreamError
|
3
|
While deserializing a message, the stream ended unexpectedly. |
QAbstractProtobufSerializer::InvalidFormatError
|
4
|
The data has invalid format. For example the JSON value doesn't match the field type. |
[virtual noexcept]
QAbstractProtobufSerializer::
~QAbstractProtobufSerializer
()
销毁此 QAbstractProtobufSerializer .
This function deserializes a registered Protobuf message
object
从
QByteArray
data
.
object
不得为
nullptr
。返回
true
if deserialization was successful, otherwise
false
.
For a given type,
T
, you should call the
deserialize()
function on an instance of that type, which in turn will call this function for you.
Unexpected/unknown properties in the data are skipped.
另请参阅 serialize ().
[pure virtual protected]
bool
QAbstractProtobufSerializer::
deserializeMessage
(
QProtobufMessage
*
message
, const
QtProtobufPrivate::QProtobufPropertyOrdering
&
ordering
,
QByteArrayView
data
) const
This is called by
deserialize
() to deserialize a registered Protobuf message
message
with
ordering
从
QByteArrayView
data
.
message
can be assumed to not be
nullptr
。返回
true
if deserialization was successful, otherwise
false
.
This function serializes a registered Protobuf message
message
成
QByteArray
.
message
不得为
nullptr
.
For a given type,
T
, you should call the
serialize()
function on an instance of that type, which in turn will call this function for you.
另请参阅 deserialize ().
[pure virtual protected]
QByteArray
QAbstractProtobufSerializer::
serializeMessage
(const
QProtobufMessage
*
message
, const
QtProtobufPrivate::QProtobufPropertyOrdering
&
ordering
) const
This is called by
serialize
() to serialize a registered Protobuf message
message
with
ordering
.
message
不得为
nullptr
。返回
QByteArray
containing the serialized message.
Defines serialize and deserialize functions for a Type inheriting QProtobufMessage . This is used as part of the code generated by the qtprotobufgen tool.
Declares the propertyOrdering member in a class inheriting QProtobufMessage . This is used as part of the code generated by the qtprotobufgen tool.