QtProtobuf  0.6
Protobuf plugin to generate Qt classes
Public Member Functions | List of all members
QtProtobuf::QAbstractProtobufSerializer Class Referenceabstract

The QAbstractProtobufSerializer class is interface that represents basic functions for serialization/deserialization. More...

#include <qabstractprotobufserializer.h>

Inheritance diagram for QtProtobuf::QAbstractProtobufSerializer:
Inheritance graph
[legend]

Public Member Functions

template<typename T >
QByteArray serialize (const QObject *object)
 Serialization of a registered qtproto message object into byte-array. More...
 
template<typename T >
void deserialize (T *object, const QByteArray &data)
 Deserialization of a byte-array into a registered qtproto message object. More...
 
virtual QByteArray serializeMessage (const QObject *object, const QProtobufMetaObject &metaObject) const =0
 serializeMessage More...
 
virtual void deserializeMessage (QObject *object, const QProtobufMetaObject &metaObject, const QByteArray &data) const =0
 serializeMessage More...
 
virtual QByteArray serializeObject (const QObject *object, const QProtobufMetaObject &metaObject, const QProtobufMetaProperty &metaProperty) const =0
 serializeObject Serializes complete object according given propertyOrdering and metaObject information More...
 
virtual void deserializeObject (QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const =0
 deserializeObject Deserializes buffer to an object More...
 
virtual QByteArray serializeListBegin (const QProtobufMetaProperty &metaProperty) const
 serializeListBegin Method called at the begining of object list serialization More...
 
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 More...
 
virtual QByteArray serializeListEnd (QByteArray &buffer, const QProtobufMetaProperty &metaProperty) const
 serializeListEnd Method called at the end of object list serialization More...
 
virtual bool deserializeListObject (QObject *object, const QProtobufMetaObject &metaObject, QProtobufSelfcheckIterator &it) const =0
 deserializeListObject Deserializes an object from byte stream as part of list property More...
 
virtual QByteArray serializeMapBegin (const QProtobufMetaProperty &metaProperty) const
 serializeMapEnd Method called at the begining of map serialization More...
 
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 More...
 
virtual QByteArray serializeMapEnd (QByteArray &buffer, const QProtobufMetaProperty &metaProperty) const
 serializeMapEnd Method called at the end of map serialization More...
 
virtual bool deserializeMapPair (QVariant &key, QVariant &value, QProtobufSelfcheckIterator &it) const =0
 deserializeMapPair Deserializes QMap pair of key and value from raw data More...
 
virtual QByteArray serializeEnum (int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const =0
 serializeEnum Serializes enum value represented as int64 type More...
 
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 More...
 
virtual void deserializeEnum (int64 &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const =0
 deserializeEnum Deserializes enum value from byte stream More...
 
virtual void deserializeEnumList (QList< int64 > &value, const QMetaEnum &metaEnum, QProtobufSelfcheckIterator &it) const =0
 deserializeEnum Deserializes list of enum values from byte stream More...
 

Detailed Description

The QAbstractProtobufSerializer class is interface that represents basic functions for serialization/deserialization.

The QAbstractProtobufSerializer class registers serializers/deserializers for classes inherited of QObject. To register serializers for user-defined class it has to be inherited of QObject and contains Q_DECLARE_PROTOBUF_SERIALIZERS macro's.

class MyType : public QObject
{
Q_OBJECT
Q_PROPERTY(qprotobuf::sint32 prop READ prop WRITE setProp NOTIFY propChanged)
...
};
#define Q_PROTOBUF_OBJECT
Declares propertyOrdering for type T inherited of QObject.
Definition: qprotobufobject.h:55
#define Q_DECLARE_PROTOBUF_SERIALIZERS(T)
Defines serializers for type T inherited of QObject.
Definition: qprotobufobject.h:43
int32_t sint32
sint32 signed 32-bit ZigZag integer
Definition: qtprotobuftypes.h:138

Practically code above is generated automaticaly by running qtprotobufgenerator or using cmake build macro qtprotobuf_generate, based on .proto files. But it's still possible to reuse manually written code if needed.

This class should be used as 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 registred message serialization/deserialization functions.

Member Function Documentation

◆ deserialize()

template<typename T >
void QtProtobuf::QAbstractProtobufSerializer::deserialize ( T *  object,
const QByteArray &  data 
)
inline

Deserialization of a byte-array into a registered qtproto message object.

Properties in a message are identified via ProtobufObjectPrivate::decodeHeader. Bytes corresponding to unexpected properties are skipped without any exception

Parameters
[out]objectPointer to memory where result of deserialization should be injected
[in]dataBytes with serialized message

◆ deserializeEnum()

virtual void QtProtobuf::QAbstractProtobufSerializer::deserializeEnum ( int64 &  value,
const QMetaEnum &  metaEnum,
QProtobufSelfcheckIterator it 
) const
pure virtual

deserializeEnum Deserializes enum value from byte stream

Parameters
[out]valueBuffer that will be used to collect new enum value
[in]metaEnumInformation about enumeration type
[in]itPoints to serialized raw key/value data

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ deserializeEnumList()

virtual void QtProtobuf::QAbstractProtobufSerializer::deserializeEnumList ( QList< int64 > &  value,
const QMetaEnum &  metaEnum,
QProtobufSelfcheckIterator it 
) const
pure virtual

deserializeEnum Deserializes list of enum values from byte stream

Parameters
[out]valueQList that will be used to collect deserialized enum values
[in]metaEnumInformation about enumeration type
[in]itPoints to serialized raw key/value data

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ deserializeListObject()

virtual bool QtProtobuf::QAbstractProtobufSerializer::deserializeListObject ( QObject *  object,
const QProtobufMetaObject &  metaObject,
QProtobufSelfcheckIterator it 
) const
pure virtual

deserializeListObject Deserializes an object from byte stream as part of list property

Parameters
[out]objectPointer to pre-allocated object, that will be appended to list property
[in]Protobufmeta object information for given object. Static meta object usualy is used to get actual property value and write new property to object
[in]itPointer to beging of buffer where object serialized data is located

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ deserializeMapPair()

virtual bool QtProtobuf::QAbstractProtobufSerializer::deserializeMapPair ( QVariant &  key,
QVariant &  value,
QProtobufSelfcheckIterator it 
) const
pure virtual

deserializeMapPair Deserializes QMap pair of key and value from raw data

Parameters
[out]keyBuffer that will be used to store deserialized key. When passed to function, QVariant already stores default constructed value. So it's possible to receive meta information about type from it.
[out]valueBuffer that will be used to store deserialized value. When passed to function, QVariant already stores default constructed value. So it's possible to receive meta information about type from it.
[in]itPoints to serialized raw key/value data
See also
https://developers.google.com/protocol-buffers/docs/proto3#maps for details

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ deserializeMessage()

virtual void QtProtobuf::QAbstractProtobufSerializer::deserializeMessage ( QObject *  object,
const QProtobufMetaObject &  metaObject,
const QByteArray &  data 
) const
pure virtual

serializeMessage

Parameters
object
propertyOrdering
metaObject
Returns

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ deserializeObject()

virtual void QtProtobuf::QAbstractProtobufSerializer::deserializeObject ( QObject *  object,
const QProtobufMetaObject &  metaObject,
QProtobufSelfcheckIterator it 
) const
pure virtual

deserializeObject Deserializes buffer to an object

Parameters
[out]objectPointer to pre-allocated object
[in]metaObjectProtobuf meta object information for given object. Static meta object usualy is used to get actual property value and write new property to object
[in]itPointer to beging of buffer where object serialized data is located
[in]propertyOrderingOrdering of properties for given object
[in]metaPropertyInformation about property to be serialized

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ serialize()

template<typename T >
QByteArray QtProtobuf::QAbstractProtobufSerializer::serialize ( const QObject *  object)
inline

Serialization of a registered qtproto message object into byte-array.

Parameters
[in]objectPointer to QObject containing message to be serialized
Returns
serialized message bytes

◆ serializeEnum()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeEnum ( int64  value,
const QMetaEnum &  metaEnum,
const QtProtobuf::QProtobufMetaProperty metaProperty 
) const
pure virtual

serializeEnum Serializes enum value represented as int64 type

Parameters
[in]valueEnum value to be serialized
[in]metaEnumInformation about enumeration type
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array
See also
https://developers.google.com/protocol-buffers/docs/proto3#maps for details

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ serializeEnumList()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeEnumList ( const QList< int64 > &  value,
const QMetaEnum &  metaEnum,
const QtProtobuf::QProtobufMetaProperty metaProperty 
) const
pure virtual

serializeEnumList Method called to serialize list of enum values

Parameters
[in]valueList of enum values to be serialized, represented as int64
[in]metaEnumInformation about enumeration type
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array
See also
https://developers.google.com/protocol-buffers/docs/proto3#maps for details

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ serializeListBegin()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeListBegin ( const QProtobufMetaProperty metaProperty) const
inlinevirtual

serializeListBegin Method called at the begining of object list serialization

Parameters
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array

Reimplemented in QtProtobuf::QProtobufJsonSerializer.

◆ serializeListEnd()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeListEnd ( QByteArray &  buffer,
const QProtobufMetaProperty metaProperty 
) const
inlinevirtual

serializeListEnd Method called at the end of object list serialization

Parameters
[in]bufferBuffer at and of list serialization
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array

Reimplemented in QtProtobuf::QProtobufJsonSerializer.

◆ serializeListObject()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeListObject ( const QObject *  object,
const QProtobufMetaObject &  metaObject,
const QProtobufMetaProperty metaProperty 
) const
pure virtual

serializeListObject Method called to serialize object as a part of list property

Parameters
[in]objectPointer to object that will be serialized
[in]metaObjectProtobuf meta object information for given object
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ serializeMapBegin()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeMapBegin ( const QProtobufMetaProperty metaProperty) const
inlinevirtual

serializeMapEnd Method called at the begining of map serialization

Parameters
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array

Reimplemented in QtProtobuf::QProtobufJsonSerializer.

◆ serializeMapEnd()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeMapEnd ( QByteArray &  buffer,
const QProtobufMetaProperty metaProperty 
) const
inlinevirtual

serializeMapEnd Method called at the end of map serialization

Parameters
[in]bufferBuffer at and of list serialization
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array

Reimplemented in QtProtobuf::QProtobufJsonSerializer.

◆ serializeMapPair()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeMapPair ( const QVariant &  key,
const QVariant &  value,
const QProtobufMetaProperty metaProperty 
) const
pure virtual

serializeMapPair Serializes QMap pair of key and value to raw data buffer

Parameters
[in]keyMap key
[in]valueMap value for given key
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array
See also
https://developers.google.com/protocol-buffers/docs/proto3#maps for details

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ serializeMessage()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeMessage ( const QObject *  object,
const QProtobufMetaObject &  metaObject 
) const
pure virtual

serializeMessage

Parameters
object
propertyOrdering
metaObject
Returns

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.

◆ serializeObject()

virtual QByteArray QtProtobuf::QAbstractProtobufSerializer::serializeObject ( const QObject *  object,
const QProtobufMetaObject &  metaObject,
const QProtobufMetaProperty metaProperty 
) const
pure virtual

serializeObject Serializes complete object according given propertyOrdering and metaObject information

Parameters
[in]objectPointer to object to be serialized
[in]metaObjectProtobuf meta object information for given object
[in]metaPropertyInformation about property to be serialized
Returns
Raw serialized data represented as byte array

Implemented in QtProtobuf::QProtobufSerializer, and QtProtobuf::QProtobufJsonSerializer.


The documentation for this class was generated from the following file: