mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
added two new classes for config/service serialisers and a base generic serialiser class
This commit is contained in:
parent
dc2df071a5
commit
8ae6541ceb
@ -2,11 +2,11 @@
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
|
||||
const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 );
|
||||
const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 );
|
||||
const SerializationFlags RsServiceSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 );
|
||||
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 );
|
||||
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 );
|
||||
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_SIGNATURE ( 0x0002 );
|
||||
|
||||
RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size)
|
||||
RsItem *RsGenericSerializer::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t rstype = getRsItemId(const_cast<void*>((const void*)data)) ;
|
||||
|
||||
@ -37,7 +37,7 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size)
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
bool RsServiceSerializer::serialise(RsItem *item,void *data,uint32_t *size)
|
||||
bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size)
|
||||
{
|
||||
SerializeContext ctx(static_cast<uint8_t*>(data),0,mFormat,mFlags);
|
||||
|
||||
@ -64,7 +64,7 @@ bool RsServiceSerializer::serialise(RsItem *item,void *data,uint32_t *size)
|
||||
return true ;
|
||||
}
|
||||
|
||||
uint32_t RsServiceSerializer::size(RsItem *item)
|
||||
uint32_t RsGenericSerializer::size(RsItem *item)
|
||||
{
|
||||
SerializeContext ctx(NULL,0,mFormat,mFlags);
|
||||
|
||||
@ -74,7 +74,7 @@ uint32_t RsServiceSerializer::size(RsItem *item)
|
||||
return ctx.mOffset ;
|
||||
}
|
||||
|
||||
void RsServiceSerializer::print(RsItem *item)
|
||||
void RsGenericSerializer::print(RsItem *item)
|
||||
{
|
||||
SerializeContext ctx(NULL,0,mFormat,mFlags);
|
||||
|
||||
|
@ -10,9 +10,11 @@
|
||||
|
||||
#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : "
|
||||
|
||||
class RsServiceSerializer: public RsSerialType
|
||||
class RsGenericSerializer: public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
// These are convenience flags to be used by the items when processing the data. The names of the flags
|
||||
// are not very important. What matters is that the serial_process() method of each item correctly
|
||||
// deals with the data when it sees the flags, if the serialiser sets them. By default the flags are not
|
||||
@ -23,12 +25,6 @@ class RsServiceSerializer: public RsSerialType
|
||||
static const SerializationFlags SERIALIZATION_FLAG_CONFIG ; // 0x0001
|
||||
static const SerializationFlags SERIALIZATION_FLAG_SIGNATURE ; // 0x0002
|
||||
|
||||
RsServiceSerializer(uint16_t service_id,
|
||||
SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY,
|
||||
SerializationFlags flags = SERIALIZATION_FLAG_NONE)
|
||||
|
||||
: RsSerialType(RS_PKT_VERSION_SERVICE,service_id),mFormat(format),mFlags(flags) {}
|
||||
|
||||
/*! create_item
|
||||
* should be overloaded to create the correct type of item depending on the data
|
||||
*/
|
||||
@ -41,10 +37,48 @@ class RsServiceSerializer: public RsSerialType
|
||||
uint32_t size(RsItem *item) ;
|
||||
void print(RsItem *item) ;
|
||||
|
||||
protected:
|
||||
RsGenericSerializer(uint8_t serial_class,
|
||||
uint8_t serial_type,
|
||||
SerializeContext::SerializationFormat format,
|
||||
SerializationFlags flags )
|
||||
: RsSerialType(RS_PKT_VERSION1,serial_class,serial_type), mFormat(format),mFlags(flags)
|
||||
{}
|
||||
|
||||
RsGenericSerializer(uint16_t service,
|
||||
SerializeContext::SerializationFormat format,
|
||||
SerializationFlags flags )
|
||||
: RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags)
|
||||
{}
|
||||
|
||||
private:
|
||||
SerializeContext::SerializationFormat mFormat ;
|
||||
SerializationFlags mFlags ;
|
||||
|
||||
};
|
||||
|
||||
class RsServiceSerializer: public RsGenericSerializer
|
||||
{
|
||||
public:
|
||||
RsServiceSerializer(uint16_t service_id,
|
||||
SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY,
|
||||
SerializationFlags flags = SERIALIZATION_FLAG_NONE)
|
||||
|
||||
: RsGenericSerializer(service_id,format,flags) {}
|
||||
};
|
||||
|
||||
class RsConfigSerializer: public RsGenericSerializer
|
||||
{
|
||||
public:
|
||||
RsConfigSerializer(uint8_t config_class,
|
||||
uint8_t config_type,
|
||||
SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY,
|
||||
SerializationFlags flags = RsGenericSerializer::SERIALIZATION_FLAG_NONE)
|
||||
|
||||
: RsGenericSerializer(config_class,config_type,format,flags) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user