switched PluginItems to new serialization

This commit is contained in:
csoler 2017-04-28 16:39:54 +02:00
parent 45eaf27deb
commit d32a8caf06
3 changed files with 24 additions and 31 deletions

View File

@ -34,8 +34,8 @@
#include "rsgxsitems.h"
#include "retroshare/rsphoto.h"
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04;
class RsGxsPhotoAlbumItem : public RsGxsGrpItem

View File

@ -1,5 +1,6 @@
#include "rspluginitems.h"
#ifdef TO_REMOVE
#ifndef WINDOWS_SYS
#include <stdexcept>
#endif
@ -130,3 +131,5 @@ std::ostream& RsPluginHashSetItem::print(std::ostream& o, uint16_t)
}
#endif

View File

@ -26,14 +26,10 @@
#pragma once
#include "serialiser/rsserial.h"
#include "rsitems/rsitem.h"
#include "rsitems/rsconfigitems.h"
#include "serialiser/rsbaseserial.h"
#if 0
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h"
#endif
#include "serialization/rstypeserializer.h"
const uint8_t RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET = 0x01 ;
@ -43,41 +39,35 @@ class RsPluginItem: public RsItem
RsPluginItem(uint8_t plugin_item_subtype): RsItem(RS_PKT_VERSION1,RS_PKT_CLASS_CONFIG,RS_PKT_TYPE_PLUGIN_CONFIG,plugin_item_subtype) {}
virtual ~RsPluginItem() {}
virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialise themselves ?
virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor
virtual void clear() {}
};
class RsPluginSerialiser: public RsSerialType
{
public:
RsPluginSerialiser() : RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PLUGIN_CONFIG) {}
virtual uint32_t size (RsItem *item)
{
return dynamic_cast<RsPluginItem *>(item)->serial_size() ;
}
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
{
return dynamic_cast<RsPluginItem *>(item)->serialise(data,*size) ;
}
virtual RsItem *deserialise (void *data, uint32_t *size) ;
};
class RsPluginHashSetItem: public RsPluginItem
{
public:
RsPluginHashSetItem() : RsPluginItem(RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET) {}
RsPluginHashSetItem(void *data,uint32_t size) ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,hashes,"hashes");
}
RsTlvHashSet hashes ;
};
virtual std::ostream& print(std::ostream& o, uint16_t) ;
class RsPluginSerialiser: public RsConfigSerializer
{
public:
RsPluginSerialiser() : RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PLUGIN_CONFIG) {}
protected:
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual RsItem *create_item(uint8_t class_type, uint8_t item_type) const
{
if(class_type == RS_PKT_TYPE_PLUGIN_CONFIG && item_type == RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET)
return new RsPluginHashSetItem() ;
return NULL ;
}
};