QAbstractProtobufSerializer Class
The QAbstractProtobufSerializer class is interface that represents basic functions for serialization/deserialization. More...
Header: | #include <QAbstractProtobufSerializer> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Protobuf) target_link_libraries(mytarget PRIVATE Qt6::Protobuf) |
Since: | Qt 6.5 |
Inherited By: | |
Status: | Technical Preview |
Note: All functions in this class are reentrant.
Public Types
enum | DeserializationError { NoError, InvalidHeaderError, NoDeserializerError, UnexpectedEndOfStreamError, InvalidFormatError } |
Public Functions
virtual | ~QAbstractProtobufSerializer() |
bool | deserialize(QProtobufMessage *message, QByteArrayView data) const |
virtual bool | deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &metaEnum) const = 0 |
virtual bool | deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum) const = 0 |
virtual bool | deserializeListObject(QProtobufMessage *message) const = 0 |
virtual bool | deserializeMapPair(QVariant &key, QVariant &value) const = 0 |
virtual bool | deserializeObject(QProtobufMessage *message) const = 0 |
QByteArray | serialize(const QProtobufMessage *message) const |
virtual void | serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const = 0 |
virtual void | serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const = 0 |
virtual void | serializeListObject(const QProtobufMessage *message, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const = 0 |
virtual void | serializeMapPair(const QVariant &key, const QVariant &value, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const = 0 |
virtual void | serializeObject(const QProtobufMessage *message, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const = 0 |
Protected Functions
virtual bool | deserializeMessage(QProtobufMessage *message, QByteArrayView data) const = 0 |
virtual QByteArray | serializeMessage(const QProtobufMessage *message) const = 0 |
Macros
Detailed Description
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 directly.
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.
Member Type Documentation
enum QAbstractProtobufSerializer::DeserializationError
This enum contains possible errors that can occur during deserialization. When an error occurs, call deserializationErrorString() to get a human-readable error message.
Constant | Value | Description |
---|---|---|
QAbstractProtobufSerializer::NoError | 0 | No error occurred. |
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. |
Member Function Documentation
[virtual noexcept]
QAbstractProtobufSerializer::~QAbstractProtobufSerializer()
Destroys this QAbstractProtobufSerializer.
bool QAbstractProtobufSerializer::deserialize(QProtobufMessage *message, QByteArrayView data) const
Deserializes a registered Protobuf message message from a QByteArray data. message must not be nullptr
. Returns true
if deserialization was successful, otherwise false
.
Unexpected/unknown properties in the data are skipped.
See also serialize().
[pure virtual]
bool QAbstractProtobufSerializer::deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &metaEnum) const
This function deserializes an enum value from a wire. metaEnum helps to decode the enum value. Returns true
if deserialization was successful, otherwise false
.
You should not call this function directly.
See also QAbstractProtobufSerializer::serializeEnum().
[pure virtual]
bool QAbstractProtobufSerializer::deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum) const
This function deserializes a list of enum value from a wire. metaEnum helps to decode the enum value. Returns true
if deserialization was successful, otherwise false
.
You should not call this function directly.
See also QAbstractProtobufSerializer::serializeEnumList().
[pure virtual]
bool QAbstractProtobufSerializer::deserializeListObject(QProtobufMessage *message) const
Deserializes message from byte stream as part of list property from a wire. Returns true
if deserialization was successful, otherwise false
.
You should not call this function directly.
See also QAbstractProtobufSerializer::serializeListObject().
[pure virtual]
bool QAbstractProtobufSerializer::deserializeMapPair(QVariant &key, QVariant &value) const
This function deserializes a pair of key and value from a wire. Returns true
if deserialization was successful, otherwise false
.
You should not call this function directly.
See also QAbstractProtobufSerializer::serializeMapPair().
[pure virtual protected]
bool QAbstractProtobufSerializer::deserializeMessage(QProtobufMessage *message, QByteArrayView data) const
This is called by deserialize() to deserialize a registered Protobuf message from a QByteArrayView data. message can be assumed to not be nullptr
. Returns true
if deserialization was successful, otherwise false
.
[pure virtual]
bool QAbstractProtobufSerializer::deserializeObject(QProtobufMessage *message) const
Deserializes a registered Protobuf message message. message must not be nullptr
. Returns true
if deserialization was successful, otherwise false
.
You should not call this function directly.
See also QAbstractProtobufSerializer::serializeObject().
QByteArray QAbstractProtobufSerializer::serialize(const QProtobufMessage *message) const
Serializes a registered Protobuf message message into a QByteArray. message must not be nullptr
.
See also deserialize().
[pure virtual]
void QAbstractProtobufSerializer::serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const
This function serializes value from enum associated with property fieldInfo. metaEnum helps to encode the enum value.
You should not call this function directly.
See also QAbstractProtobufSerializer::deserializeEnum().
[pure virtual]
void QAbstractProtobufSerializer::serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const
This function serializes a list, value, for enum list associated with property fieldInfo. metaEnum helps to encode the enum value.
You should not call this function directly.
See also QAbstractProtobufSerializer::deserializeEnumList().
[pure virtual]
void QAbstractProtobufSerializer::serializeListObject(const QProtobufMessage *message, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const
Serializes message as part of a list of messages one by one with fieldInfo.
You should not call this function directly.
See also QAbstractProtobufSerializer::deserializeListObject().
[pure virtual]
void QAbstractProtobufSerializer::serializeMapPair(const QVariant &key, const QVariant &value, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const
This function serializes pair of key and value, that belong as a protobuf map record, according to fieldInfo.
You should not call this function directly.
See also QAbstractProtobufSerializer::deserializeMapPair().
[pure virtual protected]
QByteArray QAbstractProtobufSerializer::serializeMessage(const QProtobufMessage *message) const
This is called by serialize() to serialize a registered Protobuf message. message must not be nullptr
. Returns a QByteArray containing the serialized message.
[pure virtual]
void QAbstractProtobufSerializer::serializeObject(const QProtobufMessage *message, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const
Serializes a registered Protobuf message message with defined fieldInfo, that is recognized like an object, into a QByteArray. message must not be nullptr
.
You should not call this function directly.
See also QAbstractProtobufSerializer::deserializeObject().
Macro Documentation
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.