Hyperspace::KeyValueSerializer Class Referenceabstract

The base class for automatic Key/Value (de)serialization of payloads. More...

#include <HyperspaceCore/KeyValueSerializer>

Inheritance diagram for Hyperspace::KeyValueSerializer:

Public Member Functions

QList< QByteArray > contentTypes () const
 
QList< QByteArray > dataTypes () const
 
virtual QByteArray serialize (const QVariantMap &data)=0
 
virtual QVariantMap deserialize (const QByteArray &data)=0
 

Protected Member Functions

 KeyValueSerializer (const QList< QByteArray > &contentType, const QList< QByteArray > &dataTypes)
 Creates a new Key/Value Serializer. More...
 

Detailed Description

The base class for automatic Key/Value (de)serialization of payloads.

KeyValueSerializer is an interface for implementing Key/Value (de)serializers for different standards. It can be extended to support specific content types, both for requests and responses.

The global KeyValueSerializerPool is used to keep track of which KeyValueSerializers are available for a specific set of Gates.

See also
Hyperspace::KeyValueSerializerPool

Constructor & Destructor Documentation

Hyperspace::KeyValueSerializer::KeyValueSerializer ( const QList< QByteArray > &  contentType,
const QList< QByteArray > &  dataTypes 
)
explicitprotected

Creates a new Key/Value Serializer.

contentTypes The content types the serializer supports. dataTypes The data types the serializer supports.

Member Function Documentation

QList< QByteArray > Hyperspace::KeyValueSerializer::contentTypes ( ) const

Returns the content types (message content) the serializer supports. For example, a serializer object might want to support "application/json" and "text/json" or "application/xml".

Usually, these correspond to what kind of HTML Content-Type this serializer supports.

Returns
Content types the serializer supports
QList< QByteArray > Hyperspace::KeyValueSerializer::dataTypes ( ) const

Returns the return type(s) the developer wants his data to be serialized to. A simple example could include json, xml or even a custom return format.

Usually, these correspond to the extension an explicit resource request, e.g.: hyperspace://dev/my.cap/my/target/resource.json

Returns
Data types the serializer supports
virtual QByteArray Hyperspace::KeyValueSerializer::serialize ( const QVariantMap &  data)
pure virtual

Reimplement this function to implement serialization for a Key/Value map.

data A Key/Value map

Returns
A ByteArray representing the serialized data

Implemented in Hyperspace::KeyValueJsonSerializer.

virtual QVariantMap Hyperspace::KeyValueSerializer::deserialize ( const QByteArray &  data)
pure virtual

Reimplement this function to implement deserialization for a Key/Value payload.

data A Key/Value payload

Returns
A VariantMap representing the deserialized data

Implemented in Hyperspace::KeyValueJsonSerializer.