switched RsGxsIdItems to new serialization

This commit is contained in:
csoler 2017-04-26 14:17:38 +02:00
parent fb34fa19c0
commit c0d8735251
3 changed files with 110 additions and 61 deletions

View File

@ -31,8 +31,36 @@
#include "serialiser/rstlvstring.h"
#include "util/rsstring.h"
#include "serialization/rstypeserializer.h"
#define GXSID_DEBUG 1
RsItem *RsGxsIdSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
{
if(service_id != RS_SERVICE_GXS_TYPE_GXSID)
return NULL ;
switch(item_subtype)
{
case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM : return new RsGxsIdGroupItem ();
case RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM: return new RsGxsIdLocalInfoItem() ;
default:
return NULL ;
}
}
void RsGxsIdLocalInfoItem::clear()
{
mTimeStamps.clear() ;
}
void RsGxsIdGroupItem::clear()
{
mPgpIdHash.clear();
mPgpIdSign.clear();
mRecognTags.clear();
mImage.TlvClear();
}
#ifdef TO_REMOVE
RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
{
/* get the type and size */
@ -84,18 +112,8 @@ bool RsGxsIdItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsiz
/*****************************************************************************************/
void RsGxsIdLocalInfoItem::clear()
{
mTimeStamps.clear() ;
}
void RsGxsIdGroupItem::clear()
{
mPgpIdHash.clear();
mPgpIdSign.clear();
mRecognTags.clear();
mImage.TlvClear();
}
uint32_t RsGxsIdLocalInfoItem::serial_size()
{
uint32_t s = 8 ; // header
@ -160,8 +178,15 @@ uint32_t RsGxsIdGroupItem::serial_size()
return s;
}
#endif
void RsGxsIdLocalInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,mTimeStamps,"mTimeStamps") ;
RsTypeSerializer::serial_process(j,ctx,mContacts,"mContacts") ;
}
#ifdef TO_REMOVE
bool RsGxsIdLocalInfoItem::serialise(void *data, uint32_t& size)
{
uint32_t tlvsize,offset=0;
@ -199,7 +224,20 @@ bool RsGxsIdLocalInfoItem::serialise(void *data, uint32_t& size)
return ok;
}
#endif
void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,mPgpIdHash,"mPgpIdHash") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_SIGN,mPgpIdSign,"mPgpIdSign") ;
RsTlvStringSetRef rset(TLV_TYPE_RECOGNSET,mRecognTags) ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,rset,"mRecognTags") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mImage,"mImage") ;
}
#ifdef TO_REMOVE
bool RsGxsIdGroupItem::serialise(void *data, uint32_t& size)
{
uint32_t tlvsize,offset=0;
@ -234,7 +272,7 @@ bool RsGxsIdGroupItem::serialise(void *data, uint32_t& size)
return ok;
}
#endif
bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
{
@ -275,6 +313,8 @@ bool RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage)
}
return true ;
}
#ifdef TO_REMOVE
RsGxsIdGroupItem* RsGxsIdSerialiser::deserialise_GxsIdGroupItem(void *data, uint32_t *size)
{
/* get the type and size */
@ -427,6 +467,7 @@ RsGxsIdLocalInfoItem *RsGxsIdSerialiser::deserialise_GxsIdLocalInfoItem(void *da
return item;
}
#endif
/*****************************************************************************************/
@ -692,8 +733,3 @@ RsGxsIdCommentItem* RsGxsIdSerialiser::deserialise_GxsIdCommentItem(void *data,
}
#endif
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View File

@ -45,14 +45,6 @@ class RsGxsIdItem: public RsGxsGrpItem
{
public:
RsGxsIdItem(uint8_t item_subtype) : RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSID,item_subtype) {}
virtual bool serialise(void *data,uint32_t& size) = 0 ;
virtual uint32_t serial_size() = 0 ;
virtual void clear() = 0 ;
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0;
bool serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) ;
};
class RsGxsIdGroupItem : public RsGxsIdItem
@ -62,11 +54,8 @@ public:
RsGxsIdGroupItem(): RsGxsIdItem(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) {}
virtual ~RsGxsIdGroupItem() {}
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
bool fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage);
bool toGxsIdGroup(RsGxsIdGroup &group, bool moveImage);
@ -91,10 +80,8 @@ public:
virtual ~RsGxsIdLocalInfoItem() {}
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
std::map<RsGxsId,time_t> mTimeStamps ;
std::set<RsGxsId> mContacts ;
@ -133,39 +120,13 @@ public:
};
#endif
class RsGxsIdSerialiser : public RsSerialType
class RsGxsIdSerialiser : public RsServiceSerializer
{
public:
RsGxsIdSerialiser() :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXS_TYPE_GXSID) {}
RsGxsIdSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_GXSID) {}
virtual ~RsGxsIdSerialiser() {}
virtual uint32_t size (RsItem *item)
{
RsGxsIdItem *idItem = dynamic_cast<RsGxsIdItem *>(item);
if (!idItem)
{
return 0;
}
return idItem->serial_size() ;
}
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsIdItem *idItem = dynamic_cast<RsGxsIdItem *>(item);
if (!idItem)
{
return false;
}
return idItem->serialise(data,*size) ;
}
virtual RsItem *deserialise (void *data, uint32_t *size) ;
private:
#if 0
static RsGxsIdOpinionItem *deserialise_GxsIdOpinionItem(void *data, uint32_t *size);
static RsGxsIdCommentItem *deserialise_GxsIdCommentItem(void *data, uint32_t *size);
#endif
static RsGxsIdGroupItem *deserialise_GxsIdGroupItem(void *data, uint32_t *size);
static RsGxsIdLocalInfoItem *deserialise_GxsIdLocalInfoItem(void *data, uint32_t *size);
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
};
#endif /* RS_GXS_IDENTITY_ITEMS_H */

View File

@ -199,6 +199,58 @@ class RsTypeSerializer
break;
}
}
//=================================================================================================//
// std::set<T> //
//=================================================================================================//
template<typename T>
static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::set<T>& v,const std::string& member_name)
{
switch(j)
{
case RsGenericSerializer::SIZE_ESTIMATE:
{
ctx.mOffset += 4 ;
for(typename std::set<T>::iterator it(v.begin());it!=v.end();++it)
serial_process(j,ctx,const_cast<T&>(*it) ,member_name) ;
}
break ;
case RsGenericSerializer::DESERIALIZE:
{ uint32_t n=0 ;
serial_process(j,ctx,n,"temporary size") ;
for(uint32_t i=0;i<n;++i)
{
T tmp;
serial_process<T>(j,ctx,tmp,member_name) ;
v.insert(tmp);
}
}
break ;
case RsGenericSerializer::SERIALIZE:
{
uint32_t n=v.size();
serial_process(j,ctx,n,"temporary size") ;
for(typename std::set<T>::iterator it(v.begin());it!=v.end();++it)
serial_process(j,ctx,const_cast<T&>(*it) ,member_name) ;
}
break ;
case RsGenericSerializer::PRINT:
{
if(v.empty())
std::cerr << " Empty set"<< std::endl;
else
std::cerr << " Set of " << v.size() << " elements:" << std::endl;
}
break;
default:
break;
}
}
//=================================================================================================//
// std::list<T> //