MIRA
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
BinarySerializerCodec Class Referenceabstract

Abstract base class for codecs that can be used with BinarySerializer and BinaryDeserializer. More...

#include <serialization/BinarySerializerCodec.h>

Inheritance diagram for BinarySerializerCodec:
Inheritance graph
[legend]

Classes

struct  Fourcc
 A four-character code that is used to identify data formats and codecs. More...
 

Public Member Functions

virtual ~BinarySerializerCodec ()
 
template<typename Reflector >
void reflect (Reflector &r)
 
virtual Fourcc getFourcc () const
 Returns the Fourcc code information. More...
 
virtual TypeId getSupportedTypeId () const =0
 Returns the TypeId of the type that is supported by the codec. More...
 
template<typename T >
Buffer< uint8 > encode (const T &object)
 Encodes the given object and returns the buffer with the encoded data. More...
 
template<typename T >
void decode (const Buffer< uint8 > &data, T &ioObject)
 Decodes the given buffer into the object. More...
 
Class const & getClass () const
 call the virtual internalGetClass(). More...
 

Static Public Member Functions

template<typename T >
static BinarySerializerCodecPtr createCodec (Fourcc fourcc)
 Creates a codec with the specified FOURCC code that is suitable for encoding/decoding the specified type T. More...
 
static PseudoClass const & CLASS ()
 

Protected Member Functions

virtual Buffer< uint8 > encodeBuffer (TypedVoidConstPtr objectPtr)=0
 This methods must be implemented in derived classes. More...
 
virtual void decodeBuffer (const Buffer< uint8 > &data, TypedVoidPtr ioObjectPtr)=0
 This methods must be implemented in derived classes. More...
 
virtual Class const & internalGetClass () const =0
 

Detailed Description

Abstract base class for codecs that can be used with BinarySerializer and BinaryDeserializer.

Each codec is identified by a four character code (fourcc). Moreover, a codec usually can handle a certain type of data which can be transformed into a binary buffer using the encode() method. Vice versa, a binary buffer can be restored into the object using the decode() method.

When developing a codec, the encodeBuffer() and decodeBuffer() must be implemented. Moreover the Codec class must provide the following meta information:

Example:

class FooCodec : public BinarySerializerCodec
{
("FOURCC", "FOOC")
("Name", "Foo Codec")
("Description", "Just a dummy codec")
("Category" , "Bar"))
public:
virtual TypeId getSupportedTypeId() const;
protected:
virtual Buffer<uint8> encodeBuffer(TypedVoidConstPtr objectPtr);
virtual void decodeBuffer(const Buffer<uint8>& data, TypedVoidPtr ioObjectPtr);
};

Constructor & Destructor Documentation

◆ ~BinarySerializerCodec()

virtual ~BinarySerializerCodec ( )
inlinevirtual

Member Function Documentation

◆ reflect()

void reflect ( Reflector &  r)
inline

◆ getFourcc()

virtual Fourcc getFourcc ( ) const
inlinevirtual

Returns the Fourcc code information.

◆ getSupportedTypeId()

virtual TypeId getSupportedTypeId ( ) const
pure virtual

Returns the TypeId of the type that is supported by the codec.

Objects and instances of that type can be encoded and decoded by the codec.

◆ encode()

Buffer<uint8> encode ( const T &  object)
inline

Encodes the given object and returns the buffer with the encoded data.

◆ decode()

void decode ( const Buffer< uint8 > &  data,
T &  ioObject 
)
inline

Decodes the given buffer into the object.

◆ encodeBuffer()

virtual Buffer<uint8> encodeBuffer ( TypedVoidConstPtr  objectPtr)
protectedpure virtual

This methods must be implemented in derived classes.

The typed objects that are passed to the above encode() method, are passes as untyped void pointers through this interface. Within the implementation of this method, you can use the castObject() methods to obtain a safe reference to the passed object. castObject() will do a type check so the casts are safe.

◆ decodeBuffer()

virtual void decodeBuffer ( const Buffer< uint8 > &  data,
TypedVoidPtr  ioObjectPtr 
)
protectedpure virtual

This methods must be implemented in derived classes.

The typed objects that are passed to the above encode() method, are passes as untyped void pointers through this interface. Within the implementation of this method, you can use the castObject() methods to obtain a safe reference to the passed object. castObject() will do a type check so the casts are safe.

◆ createCodec()

static BinarySerializerCodecPtr createCodec ( Fourcc  fourcc)
inlinestatic

Creates a codec with the specified FOURCC code that is suitable for encoding/decoding the specified type T.

Exceptions
ThrowsXInvalidParameter if no such codec exists.

◆ getClass()

Class const& getClass ( ) const
inlineinherited

call the virtual internalGetClass().

◆ CLASS()

static PseudoClass const& CLASS ( )
inlinestaticinherited

◆ internalGetClass()

virtual Class const& internalGetClass ( ) const
protectedpure virtualinherited

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