30 #include <QMetaObject>
32 #include <unordered_map>
36 #include "qtprotobuftypes.h"
37 #include "qtprotobuflogging.h"
38 #include "qprotobufselfcheckiterator.h"
40 #include "qtprotobufglobal.h"
42 namespace QtProtobuf {
44 class QProtobufMetaProperty;
45 class QProtobufMetaObject;
83 Q_ASSERT(
object !=
nullptr);
84 qProtoDebug() << T::staticMetaObject.className() <<
"serialize";
85 return serializeMessage(
object, T::protobufMetaObject);
99 Q_ASSERT(
object !=
nullptr);
100 qProtoDebug() << T::staticMetaObject.className() <<
"deserialize";
105 deserializeMessage(&newValue, T::protobufMetaObject, data);
122 virtual QByteArray
serializeMessage(
const QObject *
object,
const QProtobufMetaObject &metaObject)
const = 0;
131 virtual void deserializeMessage(QObject *
object,
const QProtobufMetaObject &metaObject,
const QByteArray &data)
const = 0;
160 Q_UNUSED(metaProperty);
180 Q_UNUSED(metaProperty);
200 Q_UNUSED(metaProperty);
222 Q_UNUSED(metaProperty);
279 #include "qabstractprotobufserializer_p.h"
287 static void qRegisterProtobufType() {
289 QtProtobufPrivate::registerHandler(qMetaTypeId<T *>(), { QtProtobufPrivate::serializeObject<T>,
290 QtProtobufPrivate::deserializeObject<T>, QtProtobufPrivate::ObjectHandler });
291 QtProtobufPrivate::registerHandler(qMetaTypeId<QList<QSharedPointer<T>>>(), { QtProtobufPrivate::serializeList<T>,
292 QtProtobufPrivate::deserializeList<T>, QtProtobufPrivate::ListHandler });
300 template<
typename K,
typename V,
301 typename std::enable_if_t<!std::is_base_of<QObject, V>::value,
int> = 0>
302 inline void qRegisterProtobufMapType() {
303 QtProtobufPrivate::registerHandler(qMetaTypeId<QMap<K, V>>(), { QtProtobufPrivate::serializeMap<K, V>,
304 QtProtobufPrivate::deserializeMap<K, V>, QtProtobufPrivate::MapHandler });
313 template<
typename K,
typename V,
314 typename std::enable_if_t<std::is_base_of<QObject, V>::value,
int> = 0>
315 inline void qRegisterProtobufMapType() {
316 QtProtobufPrivate::registerHandler(qMetaTypeId<QMap<K, QSharedPointer<V>>>(), { QtProtobufPrivate::serializeMap<K, V>,
317 QtProtobufPrivate::deserializeMap<K, V>, QtProtobufPrivate::MapHandler });
327 typename std::enable_if_t<std::is_enum<T>::value,
int> = 0>
328 inline void qRegisterProtobufEnumType() {
329 QtProtobufPrivate::registerHandler(qMetaTypeId<T>(), { QtProtobufPrivate::serializeEnum<T>,
330 QtProtobufPrivate::deserializeEnum<T>, QtProtobufPrivate::ObjectHandler });
331 QtProtobufPrivate::registerHandler(qMetaTypeId<QList<T>>(), { QtProtobufPrivate::serializeEnumList<T>,
332 QtProtobufPrivate::deserializeEnumList<T>, QtProtobufPrivate::ListHandler });
The QAbstractProtobufSerializer class is interface that represents basic functions for serialization/...
Definition: qabstractprotobufserializer.h:72
virtual QByteArray serializeListObject(const QObject *object, const QProtobufMetaObject &metaObject, const QProtobufMetaProperty &metaProperty) const =0
serializeListObject Method called to serialize object as a part of list property
void deserialize(T *object, const QByteArray &data)
Deserialization of a byte-array into a registered qtproto message object.
Definition: qabstractprotobufserializer.h:98
QByteArray serialize(const QObject *object)
Serialization of a registered qtproto message object into byte-array.
Definition: qabstractprotobufserializer.h:82
virtual QByteArray serializeMapBegin(const QProtobufMetaProperty &metaProperty) const
serializeMapEnd Method called at the begining of map serialization
Definition: qabstractprotobufserializer.h:199
virtual QByteArray serializeEnumList(const QList< int64 > &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const =0
serializeEnumList Method called to serialize list of enum values
virtual void deserializeObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const =0
deserializeObject Deserializes buffer to an object
virtual QByteArray serializeMapEnd(QByteArray &buffer, const QProtobufMetaProperty &metaProperty) const
serializeMapEnd Method called at the end of map serialization
Definition: qabstractprotobufserializer.h:221
virtual QByteArray serializeObject(const QObject *object, const QProtobufMetaObject &metaObject, const QProtobufMetaProperty &metaProperty) const =0
serializeObject Serializes complete object according given propertyOrdering and metaObject informatio...
virtual QByteArray serializeMessage(const QObject *object, const QProtobufMetaObject &metaObject) const =0
serializeMessage
virtual void deserializeMessage(QObject *object, const QProtobufMetaObject &metaObject, const QByteArray &data) const =0
serializeMessage
virtual bool deserializeListObject(QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const =0
deserializeListObject Deserializes an object from byte stream as part of list property
virtual QByteArray serializeEnum(int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const =0
serializeEnum Serializes enum value represented as int64 type
virtual QByteArray serializeListEnd(QByteArray &buffer, const QProtobufMetaProperty &metaProperty) const
serializeListEnd Method called at the end of object list serialization
Definition: qabstractprotobufserializer.h:179
virtual void deserializeEnum(int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const =0
deserializeEnum Deserializes enum value from byte stream
virtual QByteArray serializeMapPair(const QVariant &key, const QVariant &value, const QProtobufMetaProperty &metaProperty) const =0
serializeMapPair Serializes QMap pair of key and value to raw data buffer
virtual void deserializeEnumList(QList< int64 > &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const =0
deserializeEnum Deserializes list of enum values from byte stream
virtual bool deserializeMapPair(QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const =0
deserializeMapPair Deserializes QMap pair of key and value from raw data
virtual QByteArray serializeListBegin(const QProtobufMetaProperty &metaProperty) const
serializeListBegin Method called at the begining of object list serialization
Definition: qabstractprotobufserializer.h:159
The QProtobufSelfcheckIterator class.
Definition: qprotobufselfcheckiterator.h:40