progress in converting Chat items to new serialization model

This commit is contained in:
csoler 2017-04-04 16:37:57 +02:00
parent 32ce9aea3a
commit f2fa70e395
6 changed files with 136 additions and 116 deletions

View File

@ -89,10 +89,10 @@ bool DistantChatService::handleOutgoingItem(RsChatItem *item)
std::cerr << "p3ChatService::handleOutgoingItem(): sending to " << item->PeerId() << ": interpreted as a distant chat virtual peer id." << std::endl;
#endif
uint32_t size = item->serial_size() ;
uint32_t size = RsChatSerialiser().size(item) ;
RsTemporaryMemory mem(size) ;
if(!item->serialise(mem,size))
if(!RsChatSerialiser().serialise(item,mem,size))
{
std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl;
return false;
@ -149,10 +149,10 @@ bool DistantChatService::acceptDataFromPeer(const RsGxsId& gxs_id,const RsGxsTun
// we do not use handleOutGoingItem() because there's no distant chat contact, as the chat is refused.
uint32_t size = item->serial_size() ;
uint32_t size = RsChatSerialiser().size(item) ;
RsTemporaryMemory mem(size) ;
if(!item->serialise(mem,size))
if(!RsChatSerialiser().serialise(item,mem,size))
{
std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl;
return false;

View File

@ -415,7 +415,7 @@ void DistributedChatService::checkSizeAndSendLobbyMessage(RsChatItem *msg)
//
static const uint32_t MAX_ITEM_SIZE = 32000 ;
if(msg->serial_size() > MAX_ITEM_SIZE)
if(RsChatSerialiser().size(msg) > MAX_ITEM_SIZE)
{
std::cerr << "(EE) Chat item exceeds maximum serial size. It will be dropped." << std::endl;
delete msg ;

View File

@ -234,7 +234,6 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id)
{
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ;
case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ;
case RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG: return new RsPrivateChatDistantInviteConfigItem() ;
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ;
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ;
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ;
@ -253,7 +252,7 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id)
void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::TlvString tt(str,TLV_TYPE_STR_MSG) ;
RsTypeSerializer::TlvString tt(message,TLV_TYPE_STR_MSG) ;
RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ;
RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ;
@ -475,9 +474,9 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize)
}
#endif
bool RsChatLobbyBouncingObject::serialise_to_memory(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature)
void RsChatLobbyBouncingObject::serial_process_special(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature)
{
TlvString tt(nick,TLV_TYPE_STR_NAME) ;
RsTypeSerializer::TlvString tt(nick,TLV_TYPE_STR_NAME) ;
RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ;
RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ;
@ -485,8 +484,6 @@ bool RsChatLobbyBouncingObject::serialise_to_memory(RsItem::SerializeJob j,Seria
if(include_signature)
RsTypeSerializer::serial_process(j,ctx,signature,"signature") ;
return true ;
}
void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
@ -495,7 +492,7 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext&
if(j == RsItem::SERIALIZE)
{
SerializeContext ctx2 ;
SerializeContext ctx2(NULL,0) ;
serial_process(RsItem::SIZE_ESTIMATE,ctx2);
setRsItemHeader(ctx.mData, ctx.mSize, PacketId(), ctx2.mOffset); // correct header!
@ -503,7 +500,7 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext&
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
ctx.mOk &= RsChatLobbyBouncingObject::serialise_to_memory(j,ctx,true) ;
RsChatLobbyBouncingObject::serial_process_special(j,ctx,true) ;
}
#ifdef TO_BE_REMOVED
@ -561,7 +558,7 @@ bool RsChatLobbyMsgItem::serialise_signed_part(void *data, uint32_t& pktsize)
// The signature is at the end of the serialised data, so that the signed data is *before* the signature.
ok &= RsChatLobbyBouncingObject::serialise_to_memory(data,tlvsize,offset,false) ;
ok &= RsChatLobbyBouncingObject::serial_process_special(data,tlvsize,offset,false) ;
/* add mandatory parts first */
if (offset != tlvsize)
@ -706,6 +703,12 @@ bool RsChatLobbyEventItem::serialise_signed_part(void *data, uint32_t& pktsize)
return ok ;
}
void RsChatLobbyUnsubscribeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_id,"lobby_id") ;
}
#ifdef TO_BE_REMOVED
bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
@ -730,6 +733,14 @@ bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize)
pktsize = tlvsize ;
return ok ;
}
#endif
void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,challenge_code,"challenge_code") ;
}
#ifdef TO_BE_REMOVED
bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
@ -754,7 +765,19 @@ bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize)
pktsize = tlvsize ;
return ok ;
}
#endif
void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_id,"lobby_id") ;
TlvString s(message,TLV_TYPE_STR_NAME) ;
RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lobby_flags.toUInt32(),"lobby_flags") ;
}
#ifdef TO_BE_REMOVED
bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
@ -781,7 +804,22 @@ bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize)
pktsize = tlvsize ;
return ok ;
}
#endif
void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
uint32_t x=0 ;
TlvString s(message,TLV_TYPE_STR_MSG) ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,x,"place holder value") ;
RsTypeSerializer::serial_process (j,ctx,configPeerId,"configPeerId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chatFlags,"chatFlags") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime") ;
RsTypeSerializer::serial_process (j,ctx,s,"message") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime") ;
}
#ifdef TO_BE_REMOVED
bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
@ -821,6 +859,7 @@ bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize)
return ok;
}
bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
@ -863,6 +902,18 @@ bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsi
return ok;
}
#endif
void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ;
RsTypeSerializer::TlvString tt(status_string,TLV_TYPE_STR_MSG) ;
RsTypeSerializer::serial_process(j,ctx,tt,"status_string") ;
}
#ifdef TO_BE_REMOVED
bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
@ -901,7 +952,14 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize)
return ok;
}
#endif
void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<RsTypeSerializer::BinaryDataBlock>(j,ctx,RsTypeSerializer::BinaryDataBlock(data,image_size)) ;
}
#ifdef TO_BE_REMOVED
bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
@ -942,6 +1000,15 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
return ok;
}
#endif
void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lobby_Id,"lobby_Id") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ;
}
#ifdef TO_BE_REMOVED
bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
@ -1067,6 +1134,7 @@ RsChatLobbyListItem::RsChatLobbyListItem(void *data,uint32_t)
if (!ok)
std::cerr << "Unknown error while deserializing." << std::endl ;
}
#endif
bool RsChatLobbyBouncingObject::deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset)
{
@ -1103,6 +1171,8 @@ RsChatLobbyEventItem::RsChatLobbyEventItem(void *data,uint32_t /*size*/)
if (!ok)
std::cerr << "Unknown error while deserializing." << std::endl ;
}
#ifdef TO_BE_REMOVED
RsChatLobbyUnsubscribeItem::RsChatLobbyUnsubscribeItem(void *data,uint32_t /*size*/)
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE)
{
@ -1246,6 +1316,7 @@ RsChatLobbyConfigItem::RsChatLobbyConfigItem(void *data,uint32_t /*size*/)
if (!ok)
std::cerr << "Unknown error while deserializing." << std::endl ;
}
#endif
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const RsPeerId& /*peerId*/, uint32_t confFlags)
@ -1270,6 +1341,7 @@ void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci)
ci->recvTime = recvTime;
}
#ifdef TO_BE_REMOVED
RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/)
: RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS)
{
@ -1319,4 +1391,5 @@ RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/)
std::cerr << "Unknown error while deserializing." << std::endl ;
}
#endif

View File

@ -91,7 +91,7 @@ class RsChatItem: public RsItem
}
virtual ~RsChatItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) {} // derived from RsItem, but should be removed
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) { return out; } // derived from RsItem, but should be removed
virtual void clear() {}
};
@ -136,7 +136,6 @@ public:
RsTlvKeySignature signature ;
virtual RsChatLobbyBouncingObject *duplicate() const = 0 ;
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
// returns the size in bytes of the data chunk to sign.
@ -148,9 +147,7 @@ protected:
// They are called by serial_size() and serialise() from children, but should not overload the serial_size() and
// serialise() methods, otherwise the wrong method will be called when serialising from this top level class.
uint32_t serialized_size(bool include_signature) ;
bool serialise_to_memory(RsItem::SerializeJob j, SerializeContext &ctx, bool include_signature) ;
bool deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset) ;
void serial_process_special(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature);
};
class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject
@ -158,14 +155,10 @@ class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject
public:
RsChatLobbyMsgItem() :RsChatMsgItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG) {}
RsChatLobbyMsgItem(void *data,uint32_t size) ; // deserialization /// TODO!!!
virtual ~RsChatLobbyMsgItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ;
virtual uint32_t signed_serial_size() ;
virtual bool serialise_signed_part(void *data,uint32_t& size) ;// Isn't it better that items can serialize themselves ?
@ -177,14 +170,11 @@ class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject
{
public:
RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {}
RsChatLobbyEventItem(void *data,uint32_t size) ; // deserialization /// TODO!!!
virtual ~RsChatLobbyEventItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
//
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
virtual uint32_t signed_serial_size() ;
virtual bool serialise_signed_part(void *data,uint32_t& size) ;
@ -200,13 +190,9 @@ class RsChatLobbyListRequestItem: public RsChatItem
{
public:
RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {}
RsChatLobbyListRequestItem(void *data,uint32_t size) ;
virtual ~RsChatLobbyListRequestItem() {}
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
};
struct VisibleChatLobbyInfo
@ -222,13 +208,9 @@ class RsChatLobbyListItem: public RsChatItem
{
public:
RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {}
RsChatLobbyListItem(void *data,uint32_t size) ;
virtual ~RsChatLobbyListItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() ;
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
std::vector<VisibleChatLobbyInfo> lobbies ;
};
@ -237,48 +219,38 @@ class RsChatLobbyUnsubscribeItem: public RsChatItem
{
public:
RsChatLobbyUnsubscribeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE) {}
RsChatLobbyUnsubscribeItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatLobbyUnsubscribeItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
uint64_t lobby_id ;
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
};
class RsChatLobbyConnectChallengeItem: public RsChatItem
{
public:
RsChatLobbyConnectChallengeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE) {}
RsChatLobbyConnectChallengeItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatLobbyConnectChallengeItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
uint64_t challenge_code ;
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
};
class RsChatLobbyInviteItem: public RsChatItem
{
public:
RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {}
RsChatLobbyInviteItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatLobbyInviteItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
ChatLobbyId lobby_id ;
std::string lobby_name ;
std::string lobby_topic ;
ChatLobbyFlags lobby_flags ;
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
};
/*!
@ -289,14 +261,11 @@ class RsPrivateChatMsgConfigItem: public RsChatItem
{
public:
RsPrivateChatMsgConfigItem() :RsChatItem(RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG) {}
RsPrivateChatMsgConfigItem(void *data,uint32_t size) ; // deserialization
virtual ~RsPrivateChatMsgConfigItem() {}
virtual void clear() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags);
@ -310,40 +279,16 @@ class RsPrivateChatMsgConfigItem: public RsChatItem
std::string message;
uint32_t recvTime;
};
class RsPrivateChatDistantInviteConfigItem: public RsChatItem
{
public:
RsPrivateChatDistantInviteConfigItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG) {}
RsPrivateChatDistantInviteConfigItem(void *data,uint32_t size) ; // deserialization
virtual ~RsPrivateChatDistantInviteConfigItem() {}
virtual void clear() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
unsigned char aes_key[16] ;
RsFileHash hash ;
std::string encrypted_radix64_string ;
RsPgpId destination_pgp_id ;
uint32_t time_of_validity ;
uint32_t last_hit_time ;
uint32_t flags ;
};
class RsChatLobbyConfigItem: public RsChatItem
{
public:
RsChatLobbyConfigItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG) { lobby_Id = 0; }
RsChatLobbyConfigItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatLobbyConfigItem() {}
virtual void clear() { lobby_Id = 0; }
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
uint64_t lobby_Id;
uint32_t flags ;
@ -355,13 +300,10 @@ class RsChatStatusItem: public RsChatItem
{
public:
RsChatStatusItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) {}
RsChatStatusItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatStatusItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
uint32_t flags ;
std::string status_string;
@ -373,13 +315,9 @@ class RsChatAvatarItem: public RsChatItem
{
public:
RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;}
RsChatAvatarItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatAvatarItem() ;
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
uint32_t image_size ; // size of data in bytes
unsigned char *image_data ; // image
@ -392,13 +330,10 @@ class RsChatDHPublicKeyItem: public RsChatItem
{
public:
RsChatDHPublicKeyItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;}
RsChatDHPublicKeyItem(void *data,uint32_t size) ; // deserialization
virtual ~RsChatDHPublicKeyItem() { BN_free(public_key) ; }
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
// Private data to DH public key item
//

View File

@ -9,19 +9,6 @@
#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : "
class SerializeContext
{
public:
SerializeContext(uint8_t *data,uint32_t size)
: mData(data),mSize(size),mOffset(0),mOk(true) {}
unsigned char *mData ;
uint32_t mSize ;
uint32_t mOffset ;
bool mOk ;
};
class RsSerializer: public RsSerialType
{
public:

View File

@ -1,6 +1,22 @@
#pragma once
#include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
class SerializeContext
{
public:
SerializeContext(uint8_t *data,uint32_t size)
: mData(data),mSize(size),mOffset(0),mOk(true) {}
unsigned char *mData ;
uint32_t mSize ;
uint32_t mOffset ;
bool mOk ;
};
class RsTypeSerializer
{
public:
@ -8,6 +24,15 @@ class RsTypeSerializer
typedef std::pair<std::string&,uint16_t> TlvString;
class BinaryDataBlock_ref
{
public:
BinaryDataBlock_ref(unsigned char *& _mem,uint32_t& _size) : mem(&_mem),size(&_size){}
unsigned char **mem ;
uint32_t *size ;
};
template<typename T>
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name)
{