QAbstractProtobufSerializer Class

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
繼承者:

QProtobufJsonSerializer and QProtobufSerializer

注意: 此類的所有函數 可重入 .

公共類型

(從 6.8 起) 枚舉類 Error { None, InvalidHeader, UnknownType, UnexpectedEndOfStream, InvalidFormat }

公共函數

virtual ~QAbstractProtobufSerializer ()
bool deserialize (QProtobufMessage * message , QByteArrayView data ) const
(從 6.8 起) virtual QAbstractProtobufSerializer::Error lastError () const = 0
(從 6.8 起) virtual QString lastErrorString () const = 0
QByteArray serialize (const QProtobufMessage * message ) const

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.

成員類型文檔編製

[since 6.8] enum class QAbstractProtobufSerializer:: Error

This enum contains possible errors that can occur during deserialization. When an error occurs, call lastErrorString () to get a human-readable error message.

常量 描述
QAbstractProtobufSerializer::Error::None 0 沒有齣現錯誤。
QAbstractProtobufSerializer::Error::InvalidHeader 1 Something went wrong while attempting to decode a header in the message.
QAbstractProtobufSerializer::Error::UnknownType 2 While serializing or deserializing a message, no deserializer was found for a message field.
QAbstractProtobufSerializer::Error::UnexpectedEndOfStream 3 While deserializing a message, the stream ended unexpectedly.
QAbstractProtobufSerializer::Error::InvalidFormat 4 The data has invalid format. For example the JSON value doesn't match the field type.

該枚舉在 Qt 6.8 引入。

成員函數文檔編製

[virtual noexcept] QAbstractProtobufSerializer:: ~QAbstractProtobufSerializer ()

銷毀此 QAbstractProtobufSerializer .

bool QAbstractProtobufSerializer:: deserialize ( QProtobufMessage * message , QByteArrayView data ) const

Deserializes a registered Protobuf message message QByteArray data . message 不得為 nullptr 。返迴 true if deserialization was successful, otherwise false .

Unexpected/unknown properties in the data are skipped.

另請參閱 serialize ().

[pure virtual, since 6.8] QAbstractProtobufSerializer::Error QAbstractProtobufSerializer:: lastError () const

Returns the last error for the serializer instance.

該函數在 Qt 6.8 引入。

另請參閱 lastErrorString ().

[pure virtual, since 6.8] QString QAbstractProtobufSerializer:: lastErrorString () const

Returns the last error string for the serializer instance.

該函數在 Qt 6.8 引入。

另請參閱 lastError ().

QByteArray QAbstractProtobufSerializer:: serialize (const QProtobufMessage * message ) const

Serializes a registered Protobuf message message QByteArray . message 不得為 nullptr .

另請參閱 deserialize ().

宏文檔編製

Q_PROTOBUF_OBJECT

Declares the propertyOrdering member in a class inheriting QProtobufMessage . This is used as part of the code generated by the qtprotobufgen tool.