switched MsgUpdate items to new serialization

This commit is contained in:
csoler 2017-04-28 16:26:59 +02:00
parent 5995e508c5
commit 2e6766569d
3 changed files with 71 additions and 684 deletions

View File

@ -23,9 +23,32 @@
*
*/
#include "serialization/rstypeserializer.h"
#include "rsgxsupdateitems.h"
#include "rsbaseserial.h"
/**********************************************************************************************/
/* SERIALIZER */
/**********************************************************************************************/
RsItem* RsGxsUpdateSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
{
if(service != SERVICE_TYPE)
return NULL ;
switch(item_subtype)
{
case RS_PKT_SUBTYPE_GXS_MSG_UPDATE: return new RsGxsMsgUpdateItem(SERVICE_TYPE);
case RS_PKT_SUBTYPE_GXS_GRP_UPDATE: return new RsGxsGrpUpdateItem(SERVICE_TYPE);
case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE: return new RsGxsServerGrpUpdateItem(SERVICE_TYPE);
case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE: return new RsGxsServerMsgUpdateItem(SERVICE_TYPE);
case RS_PKT_SUBTYPE_GXS_GRP_CONFIG: return new RsGxsGrpConfigItem(SERVICE_TYPE);
default:
return NULL ;
}
}
/**********************************************************************************************/
/* CLEAR */
/**********************************************************************************************/
@ -53,642 +76,63 @@ void RsGxsServerGrpUpdateItem::clear()
grpUpdateTS = 0;
}
/**********************************************************************************************/
/* PRINT */
/**********************************************************************************************/
std::ostream& RsGxsMsgUpdateItem::print(std::ostream& out, uint16_t indent)
{
RsPeerId peerId;
std::map<RsGxsGroupId, uint32_t> msgUpdateTS;
printRsItemBase(out, "RsGxsMsgUpdateItem", indent);
uint16_t int_Indent = indent + 2;
out << "peerId: " << peerId << std::endl;
printIndent(out, int_Indent);
std::map<RsGxsGroupId, MsgUpdateInfo>::const_iterator cit = msgUpdateInfos.begin();
out << "msgUpdateTS map:" << std::endl;
int_Indent += 2;
for(; cit != msgUpdateInfos.end(); ++cit)
{
out << "grpId: " << cit->first << std::endl;
printIndent(out, int_Indent);
out << "Msg time stamp: " << cit->second.time_stamp << std::endl;
printIndent(out, int_Indent);
out << "posts available: " << cit->second.message_count << std::endl;
printIndent(out, int_Indent);
}
return out;
}
std::ostream& RsGxsGrpUpdateItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsGrpUpdateItem", indent);
uint16_t int_Indent = indent + 2;
out << "peerId: " << peerID << std::endl;
printIndent(out, int_Indent);
out << "grpUpdateTS: " << grpUpdateTS << std::endl;
printIndent(out, int_Indent);
return out ;
}
std::ostream& RsGxsServerMsgUpdateItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsServerMsgUpdateItem", indent);
uint16_t int_Indent = indent + 2;
out << "grpId: " << grpId << std::endl;
printIndent(out, int_Indent);
out << "msgUpdateTS: " << msgUpdateTS << std::endl;
printIndent(out, int_Indent);
return out;
}
std::ostream& RsGxsServerGrpUpdateItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsServerGrpUpdateItem", indent);
uint16_t int_Indent = indent + 2;
out << "grpUpdateTS: " << grpUpdateTS << std::endl;
printIndent(out, int_Indent);
return out;
}
/**********************************************************************************************/
/* SERIALISER */
/**********************************************************************************************/
bool RsGxsNetServiceItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const
void RsGxsGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
tlvsize = serial_size() ;
offset = 0;
if (pktsize < tlvsize)
return false; /* not enough space */
pktsize = tlvsize;
if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize))
{
std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl;
return false ;
}
#ifdef RSSERIAL_DEBUG
std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl;
#endif
offset += 8;
return true ;
}
RsItem* RsGxsUpdateSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)))
return NULL; /* wrong type */
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXS_MSG_UPDATE: return deserialGxsMsgUpdate(data, size);
case RS_PKT_SUBTYPE_GXS_GRP_UPDATE: return deserialGxsGrpUpddate(data, size);
case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE: return deserialGxsServerGrpUpddate(data, size);
case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE: return deserialGxsServerMsgUpdate(data, size);
case RS_PKT_SUBTYPE_GXS_GRP_CONFIG: return deserialGxsGrpConfig(data, size);
default:
{
# ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialise() : data has no type"
<< std::endl;
# endif
return NULL;
}
}
RsTypeSerializer::serial_process (j,ctx,peerID,"peerID");
RsTypeSerializer::serial_process<uint32_t>(j,ctx,grpUpdateTS,"grpUpdateTS");
}
/**********************************************************************************************/
/* SERIAL_SIZE() */
/**********************************************************************************************/
uint32_t RsGxsGrpUpdateItem::serial_size() const
void RsGxsServerGrpUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
uint32_t s = 8; // header size
s += peerID.serial_size();
s += 4; // mUpdateTS
return s;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,grpUpdateTS,"grpUpdateTS");
}
uint32_t RsGxsServerGrpUpdateItem::serial_size() const
void RsGxsMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
uint32_t s = 8; // header size
s += 4; // time stamp
return s;
RsTypeSerializer::serial_process(j,ctx,peerID,"peerID");
RsTypeSerializer::serial_process(j,ctx,msgUpdateInfos,"msgUpdateInfos");
}
uint32_t RsGxsMsgUpdateItem::serial_size() const
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
{
uint32_t s = 8; // header size
s += peerID.serial_size() ;//GetTlvStringSize(item->peerId);
bool ok = true ;
s += msgUpdateInfos.size() * (4 + 4 + RsGxsGroupId::serial_size());
s += 4; // number of map items
return s;
}
uint32_t RsGxsServerMsgUpdateItem::serial_size() const
{
uint32_t s = 8; // header size
s += grpId.serial_size();
s += 4; // grp TS
return s;
}
uint32_t RsGxsGrpConfigItem::serial_size() const
{
uint32_t s = 8; // header size
s += grpId.serial_size();
s += 4; // msg_keep_delay
s += 4; // msg_send_delay
s += 4; // msg_req_delay
return s;
}
/**********************************************************************************************/
/* SERIALISE() */
/**********************************************************************************************/
bool RsGxsGrpUpdateItem::serialise(void* data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= peerID.serialise(data, size, offset) ;
ok &= setRawUInt32(data, size, &offset, grpUpdateTS);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
ok = ok && setRawUInt32(data,size,&offset,info.time_stamp);
ok = ok && setRawUInt32(data,size,&offset,info.message_count);
return ok;
}
bool RsGxsServerGrpUpdateItem::serialise(void* data, uint32_t& size) const
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, RsGxsMsgUpdateItem::MsgUpdateInfo& info)
{
uint32_t tlvsize,offset=0;
bool ok = true;
bool ok = true ;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* RsGxsServerGrpUpdateItem */
ok &= setRawUInt32(data, size, &offset, grpUpdateTS);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
ok = ok && getRawUInt32(data,size,&offset,&info.time_stamp);
ok = ok && getRawUInt32(data,size,&offset,&info.message_count);
return ok;
}
bool RsGxsMsgUpdateItem::serialise(void* data, uint32_t& size) const
template<> uint32_t RsTypeSerializer::serial_size(const RsGxsMsgUpdateItem::MsgUpdateInfo& /* info */) { return 8; }
template<> void RsTypeSerializer::print_data(const std::string& name,const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= peerID.serialise(data, size, offset) ;
std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>::const_iterator cit(msgUpdateInfos.begin());
uint32_t numItems = msgUpdateInfos.size();
ok &= setRawUInt32(data, size, &offset, numItems);
for(; cit != msgUpdateInfos.end(); ++cit)
{
ok &= cit->first.serialise(data, size, offset);
ok &= setRawUInt32(data, size, &offset, cit->second.time_stamp);
ok &= setRawUInt32(data, size, &offset, cit->second.message_count);
}
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
return ok;
std::cerr << "[MsgUpdateInfo]: " << name << ": " << info.time_stamp << ", " << info.message_count << std::endl;
}
bool RsGxsServerMsgUpdateItem::serialise( void* data, uint32_t& size) const
void RsGxsServerMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= grpId.serialise(data, size, offset) ;
ok &= setRawUInt32(data, size, &offset, msgUpdateTS);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
return ok;
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId");
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgUpdateTS,"msgUpdateTS");
}
bool RsGxsGrpConfigItem::serialise( void* data, uint32_t& size) const
void RsGxsGrpConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= grpId.serialise(data, size, offset) ;
ok &= setRawUInt32(data, size, &offset, msg_keep_delay);
ok &= setRawUInt32(data, size, &offset, msg_send_delay);
ok &= setRawUInt32(data, size, &offset, msg_req_delay);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
return ok;
RsTypeSerializer::serial_process (j,ctx,grpId,"grpId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_keep_delay,"msg_keep_delay") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_send_delay,"msg_send_delay") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msg_req_delay,"msg_req_delay") ;
}
/**********************************************************************************************/
/* DESERIALISE() */
/**********************************************************************************************/
RsGxsGrpConfigItem* RsGxsUpdateSerialiser::deserialGxsGrpConfig(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_GRP_CONFIG != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsGrpConfigItem* item = new RsGxsGrpConfigItem(getRsItemService(rstype));
/* skip the header */
offset += 8;
ok &= item->grpId.deserialise(data, *size, offset) ;
ok &= getRawUInt32(data, *size, &offset, &(item->msg_keep_delay));
ok &= getRawUInt32(data, *size, &offset, &(item->msg_send_delay));
ok &= getRawUInt32(data, *size, &offset, &(item->msg_req_delay));
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxxGrpUpdate() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsGrpUpddate(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(SERVICE_TYPE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXS_GRP_UPDATE != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsGrpUpdateItem* item = new RsGxsGrpUpdateItem(getRsItemService(rstype));
/* skip the header */
offset += 8;
ok &= item->peerID.deserialise(data, *size, offset) ;
ok &= getRawUInt32(data, *size, &offset, &(item->grpUpdateTS));
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxxGrpUpdate() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsServerGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerGrpUpddate(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsServerGrpUpdateItem* item = new RsGxsServerGrpUpdateItem(getRsItemService(rstype));
/* skip the header */
offset += 8;
ok &= getRawUInt32(data, *size, &offset, &(item->grpUpdateTS));
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsMsgUpdate(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_MSG_UPDATE != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsMsgUpdateItem* item = new RsGxsMsgUpdateItem(getRsItemService(rstype));
/* skip the header */
offset += 8;
ok &= item->peerID.deserialise(data, *size, offset) ;
uint32_t numUpdateItems;
ok &= getRawUInt32(data, *size, &offset, &(numUpdateItems));
std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>& msgUpdateInfos = item->msgUpdateInfos;
RsGxsGroupId pId;
RsGxsMsgUpdateItem::MsgUpdateInfo info ;
for(uint32_t i = 0; i < numUpdateItems; i++)
{
ok &= pId.deserialise(data, *size, offset);
if(!ok)
break;
ok &= getRawUInt32(data, *size, &offset, &(info.time_stamp));
ok &= getRawUInt32(data, *size, &offset, &(info.message_count));
if(!ok)
break;
msgUpdateInfos.insert(std::make_pair(pId, info));
}
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsServerMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsServerMsgUpdateItem* item = new RsGxsServerMsgUpdateItem(getRsItemService(rstype));
/* skip the header */
offset += 8;
ok &= item->grpId.deserialise(data, *size, offset) ;
ok &= getRawUInt32(data, *size, &offset, &(item->msgUpdateTS));
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}

View File

@ -55,15 +55,7 @@ public:
RsGxsNetServiceItem(uint16_t serv_type,uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE, serv_type, subtype) {}
virtual ~RsGxsNetServiceItem() {}
virtual bool serialise(void *data,uint32_t& size) const = 0 ;
virtual uint32_t serial_size() const = 0 ;
virtual void clear() = 0 ;
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0;
protected:
bool serialise_header(void *data, uint32_t& pktsize, uint32_t& tlvsize, uint32_t& offset) const;
};
class RsGxsGrpConfig
@ -96,10 +88,7 @@ public:
virtual ~RsGxsGrpConfigItem() {}
virtual void clear() {}
virtual std::ostream &print(std::ostream &out, uint16_t /*indent*/) { return out;}
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsGxsGroupId grpId ;
};
@ -121,10 +110,7 @@ public:
virtual ~RsGxsGrpUpdateItem() {}
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsPeerId peerID;
};
@ -146,10 +132,7 @@ public:
virtual ~RsGxsServerGrpUpdateItem() {}
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
};
class RsGxsMsgUpdate
@ -175,10 +158,7 @@ public:
virtual ~RsGxsMsgUpdateItem() {}
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsPeerId peerID;
};
@ -199,58 +179,21 @@ public:
virtual ~RsGxsServerMsgUpdateItem() {}
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsGxsGroupId grpId;
};
class RsGxsUpdateSerialiser : public RsSerialType
class RsGxsUpdateSerialiser : public RsServiceSerializer
{
public:
RsGxsUpdateSerialiser(uint16_t servtype) : RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) {}
RsGxsUpdateSerialiser(uint16_t servtype) : RsServiceSerializer(servtype), SERVICE_TYPE(servtype) {}
virtual ~RsGxsUpdateSerialiser() {}
virtual uint32_t size(RsItem *item)
{
RsGxsNetServiceItem *gitem = dynamic_cast<RsGxsNetServiceItem *>(item);
if (!gitem)
{
std::cerr << "(EE) trying to serialise/size an item that is not a RsGxsNetServiceItem!" << std::endl;
return 0;
}
return gitem->serial_size() ;
}
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsNetServiceItem *gitem = dynamic_cast<RsGxsNetServiceItem *>(item);
if (!gitem)
{
std::cerr << "(EE) trying to serialise an item that is not a RsGxsNetServiceItem!" << std::endl;
return false;
}
return gitem->serialise(data,*size) ;
}
virtual RsItem* deserialise(void *data, uint32_t *size);
private:
RsGxsGrpConfigItem *deserialGxsGrpConfig(void *data, uint32_t *size);
RsGxsServerMsgUpdateItem *deserialGxsServerMsgUpdate(void *data, uint32_t *size);
RsGxsMsgUpdateItem *deserialGxsMsgUpdate(void *data, uint32_t *size);
RsGxsServerGrpUpdateItem *deserialGxsServerGrpUpddate(void *data, uint32_t *size);
RsGxsGrpUpdateItem *deserialGxsGrpUpddate(void *data, uint32_t *size);
bool checkItemHeader(void *data, uint32_t *size, uint16_t service_type,uint8_t subservice_type);
virtual RsItem* create_item(uint16_t service,uint8_t item_subtype) const ;
const uint16_t SERVICE_TYPE;
};

View File

@ -88,8 +88,8 @@ class RsTypeSerializer
ctx.mOffset += 4 ;
for(typename std::map<T,U>::iterator it(v.begin());it!=v.end();++it)
{
ctx.mOffset += serial_size(it->first) ;
ctx.mOffset += serial_size(it->second) ;
serial_process(j,ctx,const_cast<T&>(it->first),"map::*it->first") ;
serial_process(j,ctx,const_cast<U&>(it->second),"map::*it->second") ;
}
}
break ;
@ -97,15 +97,15 @@ class RsTypeSerializer
case RsGenericSerializer::DESERIALIZE:
{
uint32_t n=0 ;
ctx.mOk = ctx.mOk && deserialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ;
serial_process(j,ctx,n,"temporary size");
for(uint32_t i=0;i<n;++i)
{
T t ;
U u ;
ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,t) ;
ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,u) ;
serial_process(j,ctx,t,"map::*it->first") ;
serial_process(j,ctx,u,"map::*it->second") ;
v[t] = u ;
}
@ -115,12 +115,12 @@ class RsTypeSerializer
case RsGenericSerializer::SERIALIZE:
{
uint32_t n=v.size();
ctx.mOk = ctx.mOk && serialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ;
serial_process(j,ctx,n,"temporary size");
for(typename std::map<T,U>::iterator it(v.begin());it!=v.end();++it)
{
ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,it->first) ;
ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,it->second) ;
serial_process(j,ctx,const_cast<T&>(it->first),"map::*it->first") ;
serial_process(j,ctx,const_cast<U&>(it->second),"map::*it->second") ;
}
}
break ;
@ -136,8 +136,8 @@ class RsTypeSerializer
{
std::cerr << " " ;
print_data("first",it->first) ;
print_data("second",it->second) ;
serial_process(j,ctx,const_cast<T&>(it->first),"map::*it->first") ;
serial_process(j,ctx,const_cast<U&>(it->second),"map::*it->second") ;
}
}
break;