cleaned the hierarchy of serialization classes

This commit is contained in:
csoler 2017-04-26 11:40:46 +02:00
parent 77e809ea4b
commit 9c610a736d
48 changed files with 382 additions and 326 deletions

View File

@ -62,7 +62,7 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) c
} }
} }
void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ; RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ;
RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ;
@ -80,7 +80,7 @@ RsChatAvatarItem::~RsChatAvatarItem()
} }
} }
void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, SerializeContext& ctx) void RsChatLobbyBouncingObject::serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ;
RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ;
@ -90,19 +90,19 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, Serialize
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signature,"signature") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,signature,"signature") ;
} }
void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatLobbyMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsChatMsgItem::serial_process(j,ctx) ; RsChatMsgItem::serial_process(j,ctx) ;
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
RsChatLobbyBouncingObject::serial_process(j,ctx) ; RsChatLobbyBouncingObject::serial_process(j,ctx) ;
} }
void RsChatLobbyListRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatLobbyListRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
// nothing to do. This is an empty item. // nothing to do. This is an empty item.
} }
template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name) template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name)
{ {
RsTypeSerializer::serial_process<uint64_t>(j,ctx,info.id,"info.id") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,info.id,"info.id") ;
@ -112,12 +112,12 @@ template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,Serializ
RsTypeSerializer::serial_process (j,ctx, info.flags,"info.flags") ; RsTypeSerializer::serial_process (j,ctx, info.flags,"info.flags") ;
} }
void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatLobbyListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ; RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ;
} }
void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatLobbyEventItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint8_t>(j,ctx,event_type,"event_type") ; RsTypeSerializer::serial_process<uint8_t>(j,ctx,event_type,"event_type") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ; RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ;
@ -125,24 +125,24 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex
RsChatLobbyBouncingObject::serial_process(j,ctx) ; RsChatLobbyBouncingObject::serial_process(j,ctx) ;
} }
void RsChatLobbyUnsubscribeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatLobbyUnsubscribeItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_id,"lobby_id") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_id,"lobby_id") ;
} }
void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatLobbyConnectChallengeItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t>(j,ctx,challenge_code,"challenge_code") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,challenge_code,"challenge_code") ;
} }
void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatLobbyInviteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t>(j,ctx, lobby_id, "lobby_id") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx, lobby_id, "lobby_id") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ; RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ;
RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ; RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ;
} }
void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsPrivateChatMsgConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
uint32_t x=0 ; uint32_t x=0 ;
@ -154,19 +154,19 @@ void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,Serialize
RsTypeSerializer::serial_process<uint32_t>(j,ctx, recvTime, "recvTime") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx, recvTime, "recvTime") ;
} }
void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,status_string,"status_string") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,status_string,"status_string") ;
} }
void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatAvatarItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::TlvMemBlock_proxy b(image_data,image_size) ; RsTypeSerializer::TlvMemBlock_proxy b(image_data,image_size) ;
RsTypeSerializer::serial_process(j,ctx,b,"image data") ; RsTypeSerializer::serial_process(j,ctx,b,"image data") ;
} }
void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsChatLobbyConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_Id,"lobby_Id") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_Id,"lobby_Id") ;
RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ;

View File

@ -30,6 +30,8 @@
#include "serialization/rsserializer.h" #include "serialization/rsserializer.h"
#include "serialiser/rstlvkeys.h" #include "serialiser/rstlvkeys.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/itempriorities.h"
#include "rsitems/rsitem.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvidset.h" #include "serialiser/rstlvidset.h"
@ -112,7 +114,7 @@ public:
// derived from RsItem // derived from RsItem
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear() {} virtual void clear() {}
uint32_t chatFlags; uint32_t chatFlags;
@ -142,7 +144,7 @@ protected:
// They are called by serial_size() and serialise() from children, but should not overload the serial_size() and // 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. // serialise() methods, otherwise the wrong method will be called when serialising from this top level class.
virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual uint32_t PacketId() const= 0; virtual uint32_t PacketId() const= 0;
}; };
@ -155,7 +157,7 @@ public:
virtual ~RsChatLobbyMsgItem() {} virtual ~RsChatLobbyMsgItem() {}
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; } virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ; virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
ChatLobbyMsgId parent_msg_id ; // Used for threaded chat. ChatLobbyMsgId parent_msg_id ; // Used for threaded chat.
@ -171,7 +173,7 @@ public:
virtual ~RsChatLobbyEventItem() {} virtual ~RsChatLobbyEventItem() {}
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; } virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
// //
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
// members. // members.
// //
@ -189,7 +191,7 @@ class RsChatLobbyListRequestItem: public RsChatItem
RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {} RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {}
virtual ~RsChatLobbyListRequestItem() {} virtual ~RsChatLobbyListRequestItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
struct VisibleChatLobbyInfo struct VisibleChatLobbyInfo
@ -207,7 +209,7 @@ class RsChatLobbyListItem: public RsChatItem
RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {} RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {}
virtual ~RsChatLobbyListItem() {} virtual ~RsChatLobbyListItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
std::vector<VisibleChatLobbyInfo> lobbies ; std::vector<VisibleChatLobbyInfo> lobbies ;
}; };
@ -219,7 +221,7 @@ class RsChatLobbyUnsubscribeItem: public RsChatItem
virtual ~RsChatLobbyUnsubscribeItem() {} virtual ~RsChatLobbyUnsubscribeItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint64_t lobby_id ; uint64_t lobby_id ;
}; };
@ -231,7 +233,7 @@ class RsChatLobbyConnectChallengeItem: public RsChatItem
virtual ~RsChatLobbyConnectChallengeItem() {} virtual ~RsChatLobbyConnectChallengeItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint64_t challenge_code ; uint64_t challenge_code ;
}; };
@ -242,7 +244,7 @@ class RsChatLobbyInviteItem: public RsChatItem
RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {} RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {}
virtual ~RsChatLobbyInviteItem() {} virtual ~RsChatLobbyInviteItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
ChatLobbyId lobby_id ; ChatLobbyId lobby_id ;
std::string lobby_name ; std::string lobby_name ;
@ -262,7 +264,7 @@ class RsPrivateChatMsgConfigItem: public RsChatItem
virtual ~RsPrivateChatMsgConfigItem() {} virtual ~RsPrivateChatMsgConfigItem() {}
virtual void clear() {} virtual void clear() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */ /* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags); void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags);
@ -286,7 +288,7 @@ public:
virtual void clear() { lobby_Id = 0; } virtual void clear() { lobby_Id = 0; }
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint64_t lobby_Id; uint64_t lobby_Id;
uint32_t flags ; uint32_t flags ;
@ -301,7 +303,7 @@ class RsChatStatusItem: public RsChatItem
virtual ~RsChatStatusItem() {} virtual ~RsChatStatusItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t flags ; uint32_t flags ;
std::string status_string; std::string status_string;
@ -315,7 +317,7 @@ class RsChatAvatarItem: public RsChatItem
RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;} RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;}
virtual ~RsChatAvatarItem() ; virtual ~RsChatAvatarItem() ;
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t image_size ; // size of data in bytes uint32_t image_size ; // size of data in bytes
unsigned char *image_data ; // image unsigned char *image_data ; // image
@ -325,7 +327,7 @@ class RsChatSerialiser: public RsServiceSerializer
{ {
public: public:
RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE)
:RsServiceSerializer(RS_SERVICE_TYPE_CHAT,SerializeContext::FORMAT_BINARY,flags) {} :RsServiceSerializer(RS_SERVICE_TYPE_CHAT,RsGenericSerializer::FORMAT_BINARY,flags) {}
virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ; virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ;
}; };

View File

@ -24,16 +24,18 @@
*/ */
#include "serialiser/rsbaseserial.h" #include "serialiser/rsbaseserial.h"
#include "serialization/rstypeserializer.h"
#include "file_sharing/rsfilelistitems.h" #include "file_sharing/rsfilelistitems.h"
void RsFileListsSyncRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsFileListsSyncRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags ,"flags") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags ,"flags") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ;
RsTypeSerializer::serial_process<uint64_t>(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,request_id,"request_id") ;
} }
void RsFileListsSyncResponseItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsFileListsSyncResponseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ;
RsTypeSerializer::serial_process (j,ctx,checksum,"checksum") ; RsTypeSerializer::serial_process (j,ctx,checksum,"checksum") ;

View File

@ -28,6 +28,7 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/itempriorities.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h" #include "serialiser/rstlvbase.h"
#include "serialiser/rstlvitem.h" #include "serialiser/rstlvitem.h"
@ -78,7 +79,7 @@ public:
virtual void clear(){} virtual void clear(){}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsFileHash entry_hash ; // hash of the directory to sync RsFileHash entry_hash ; // hash of the directory to sync
uint32_t flags; // used to say that it's a request or a response, say that the directory has been removed, ask for further update, etc. uint32_t flags; // used to say that it's a request or a response, say that the directory has been removed, ask for further update, etc.
@ -94,7 +95,7 @@ public:
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsFileHash entry_hash ; // hash of the directory to sync RsFileHash entry_hash ; // hash of the directory to sync
RsFileHash checksum ; // checksum of the bindary data, for checking RsFileHash checksum ; // checksum of the bindary data, for checking

View File

@ -32,37 +32,37 @@
#include <serialization/rstypeserializer.h> #include <serialization/rstypeserializer.h>
void RsTurtleFileMapRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleFileMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,direction,"direction") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,direction,"direction") ;
} }
void RsTurtleFileMapItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleFileMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,direction,"direction") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,direction,"direction") ;
RsTypeSerializer::serial_process (j,ctx,compressed_map._map,"map") ; RsTypeSerializer::serial_process (j,ctx,compressed_map._map,"map") ;
} }
void RsTurtleChunkCrcRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
} }
void RsTurtleChunkCrcItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
RsTypeSerializer::serial_process (j,ctx,check_sum,"check_sum") ; RsTypeSerializer::serial_process (j,ctx,check_sum,"check_sum") ;
} }
void RsTurtleFileRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleFileRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
RsTypeSerializer::serial_process<uint64_t>(j,ctx,chunk_offset,"chunk_offset") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,chunk_offset,"chunk_offset") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_size,"chunk_size") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_size,"chunk_size") ;
} }
void RsTurtleFileDataItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleFileDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id,"tunnel_id") ;
RsTypeSerializer::serial_process<uint64_t>(j,ctx,chunk_offset,"chunk_offset") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,chunk_offset,"chunk_offset") ;

View File

@ -43,7 +43,7 @@ class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem
void clear() {} void clear() {}
protected: protected:
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem
@ -67,7 +67,7 @@ class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem
uint32_t chunk_size ; // size of the file chunk uint32_t chunk_size ; // size of the file chunk
void *chunk_data ; // actual data. void *chunk_data ; // actual data.
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem
@ -78,7 +78,7 @@ class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem
virtual bool shouldStampTunnel() const { return false ; } virtual bool shouldStampTunnel() const { return false ; }
void clear() {} void clear() {}
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
@ -93,7 +93,7 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem
// with the default file map for this source. // with the default file map for this source.
void clear() { compressed_map._map.clear() ;} void clear() { compressed_map._map.clear() ;}
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
@ -107,7 +107,7 @@ class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem
uint32_t chunk_number ; // id of the chunk to CRC. uint32_t chunk_number ; // id of the chunk to CRC.
void clear() {} void clear() {}
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem
@ -122,5 +122,5 @@ class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem
Sha1CheckSum check_sum ; Sha1CheckSum check_sum ;
void clear() { check_sum.clear() ;} void clear() { check_sum.clear() ;}
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };

View File

@ -3,6 +3,8 @@
#include "serialiser/rstlvbase.h" #include "serialiser/rstlvbase.h"
#include "grouteritems.h" #include "grouteritems.h"
#include "serialization/rstypeserializer.h"
/**********************************************************************************************/ /**********************************************************************************************/
/* SERIALISER STUFF */ /* SERIALISER STUFF */
/**********************************************************************************************/ /**********************************************************************************************/
@ -28,7 +30,7 @@ RsItem *RsGRouterSerialiser::create_item(uint16_t service_id,uint8_t subtype) co
} }
} }
void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsGRouterTransactionChunkItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t>(j,ctx,propagation_id,"propagation_id") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,propagation_id,"propagation_id") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_start ,"chunk_start") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_start ,"chunk_start") ;
@ -37,7 +39,7 @@ void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeConte
// Hack for backward compatibility (the chunk size is not directly next to the chunk data) // Hack for backward compatibility (the chunk size is not directly next to the chunk data)
if(j == RsItem::DESERIALIZE) if(j == RsGenericSerializer::DESERIALIZE)
{ {
if(chunk_size > ctx.mSize || ctx.mOffset > ctx.mSize - chunk_size) // better than if(chunk_size + offset > size) if(chunk_size > ctx.mSize || ctx.mOffset > ctx.mSize - chunk_size) // better than if(chunk_size + offset > size)
{ {
@ -54,12 +56,12 @@ void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeConte
memcpy(chunk_data,&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_size) ; memcpy(chunk_data,&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_size) ;
ctx.mOffset += chunk_size ; ctx.mOffset += chunk_size ;
} }
else if(j== RsItem::SERIALIZE) else if(j== RsGenericSerializer::SERIALIZE)
{ {
memcpy(&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_data,chunk_size) ; memcpy(&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_data,chunk_size) ;
ctx.mOffset += chunk_size ; ctx.mOffset += chunk_size ;
} }
else if(j== RsItem::SIZE_ESTIMATE) else if(j== RsGenericSerializer::SIZE_ESTIMATE)
ctx.mOffset += chunk_size ; ctx.mOffset += chunk_size ;
else else
std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl; std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl;
@ -112,7 +114,7 @@ RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransac
} }
#endif #endif
void RsGRouterTransactionAcknItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsGRouterTransactionAcknItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t>(j,ctx,propagation_id,"propagation_id") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,propagation_id,"propagation_id") ;
} }
@ -140,7 +142,7 @@ RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransact
} }
#endif #endif
void RsGRouterGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t>(j,ctx,routing_id,"routing_id") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,routing_id,"routing_id") ;
RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ; RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ;
@ -157,7 +159,7 @@ void RsGRouterGenericDataItem::serial_process(SerializeJob j,SerializeContext& c
RsTypeSerializer::serial_process<uint32_t>(j,ctx,duplication_factor,"duplication_factor") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,duplication_factor,"duplication_factor") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ;
if(j == RsItem::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more. if(j == RsGenericSerializer::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more.
{ {
if(duplication_factor < 1) if(duplication_factor < 1)
{ {
@ -242,7 +244,7 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI
} }
#endif #endif
void RsGRouterSignedReceiptItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t> (j,ctx,routing_id,"routing_id") ; RsTypeSerializer::serial_process<uint64_t> (j,ctx,routing_id,"routing_id") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ; RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
@ -283,7 +285,7 @@ RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedRece
} }
#endif #endif
void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,data_status,"data_status") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,data_status,"data_status") ;
@ -304,7 +306,7 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c
// Hack for backward compatibility. Normally we should need a single commandline to serialise/deserialise a single item here. // Hack for backward compatibility. Normally we should need a single commandline to serialise/deserialise a single item here.
// But the full item is serialised, so we need the header. // But the full item is serialised, so we need the header.
if(j == RsItem::DESERIALIZE) if(j == RsGenericSerializer::DESERIALIZE)
{ {
data_item = new RsGRouterGenericDataItem() ; data_item = new RsGRouterGenericDataItem() ;
@ -321,7 +323,7 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c
else else
receipt_item = NULL ; receipt_item = NULL ;
} }
else if(j == RsItem::SERIALIZE) else if(j == RsGenericSerializer::SERIALIZE)
{ {
uint32_t remaining_size = ctx.mSize - ctx.mOffset; uint32_t remaining_size = ctx.mSize - ctx.mOffset;
ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size) ; ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size) ;
@ -330,18 +332,18 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c
if(receipt_item != NULL) if(receipt_item != NULL)
{ {
remaining_size = ctx.mSize - ctx.mOffset; remaining_size = ctx.mSize - ctx.mOffset;
ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size); ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(receipt_item,ctx.mData,&remaining_size);
ctx.mOffset += RsGRouterSerialiser().size(data_item) ; ctx.mOffset += RsGRouterSerialiser().size(receipt_item) ;
} }
} }
else if(j == RsItem::PRINT) else if(j == RsGenericSerializer::PRINT)
{ {
std::cerr << " [Serialized data] " << std::endl; std::cerr << " [Serialized data] " << std::endl;
if(receipt_item != NULL) if(receipt_item != NULL)
std::cerr << " [Receipt item ]" << std::endl; std::cerr << " [Receipt item ]" << std::endl;
} }
else if(j == RsItem::SIZE_ESTIMATE) else if(j == RsGenericSerializer::SIZE_ESTIMATE)
{ {
ctx.mOffset += RsGRouterSerialiser().size(data_item) ; ctx.mOffset += RsGRouterSerialiser().size(data_item) ;
@ -410,7 +412,7 @@ RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoI
} }
#endif #endif
void RsGRouterMatrixFriendListItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsGRouterMatrixFriendListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ; RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ;
} }
@ -443,7 +445,7 @@ RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixF
} }
#endif #endif
void RsGRouterMatrixTrackItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ; RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ;
RsTypeSerializer::serial_process(j,ctx,message_id,"message_id") ; RsTypeSerializer::serial_process(j,ctx,message_id,"message_id") ;
@ -474,13 +476,13 @@ RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackI
} }
#endif #endif
void RsGRouterMatrixCluesItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsGRouterMatrixCluesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ; RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ;
RsTypeSerializer::serial_process(j,ctx,clues,"clues") ; RsTypeSerializer::serial_process(j,ctx,clues,"clues") ;
} }
template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,RoutingMatrixHitEntry& s,const std::string& name) template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,RoutingMatrixHitEntry& s,const std::string& name)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,s.friend_id,name+":friend_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,s.friend_id,name+":friend_id") ;
RsTypeSerializer::serial_process<float> (j,ctx,s.weight,name+":weight") ; RsTypeSerializer::serial_process<float> (j,ctx,s.weight,name+":weight") ;

View File

@ -112,7 +112,7 @@ class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRoute
data_bytes=NULL; data_bytes=NULL;
} }
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsGRouterGenericDataItem *duplicate() const ; RsGRouterGenericDataItem *duplicate() const ;
@ -130,7 +130,7 @@ class RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem
virtual ~RsGRouterSignedReceiptItem() {} virtual ~RsGRouterSignedReceiptItem() {}
virtual void clear() {} virtual void clear() {}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsGRouterSignedReceiptItem *duplicate() const ; RsGRouterSignedReceiptItem *duplicate() const ;
@ -161,7 +161,7 @@ public:
virtual ~RsGRouterTransactionChunkItem() { free(chunk_data) ; } virtual ~RsGRouterTransactionChunkItem() { free(chunk_data) ; }
virtual void clear() {} virtual void clear() {}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual RsGRouterTransactionItem *duplicate() const virtual RsGRouterTransactionItem *duplicate() const
{ {
@ -188,7 +188,7 @@ public:
RsGRouterTransactionAcknItem() : RsGRouterTransactionItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } RsGRouterTransactionAcknItem() : RsGRouterTransactionItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; }
virtual ~RsGRouterTransactionAcknItem() {} virtual ~RsGRouterTransactionAcknItem() {}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear() {} virtual void clear() {}
@ -206,7 +206,7 @@ class RsGRouterMatrixCluesItem: public RsGRouterItem
{ setPriorityLevel(0) ; } // this item is never sent through the network { setPriorityLevel(0) ; } // this item is never sent through the network
virtual void clear() {} virtual void clear() {}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
// packet data // packet data
// //
@ -220,7 +220,7 @@ class RsGRouterMatrixTrackItem: public RsGRouterItem
RsGRouterMatrixTrackItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK) RsGRouterMatrixTrackItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK)
{ setPriorityLevel(0) ; } // this item is never sent through the network { setPriorityLevel(0) ; } // this item is never sent through the network
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear() {} virtual void clear() {}
@ -236,7 +236,7 @@ class RsGRouterMatrixFriendListItem: public RsGRouterItem
RsGRouterMatrixFriendListItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST) RsGRouterMatrixFriendListItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST)
{ setPriorityLevel(0) ; } // this item is never sent through the network { setPriorityLevel(0) ; } // this item is never sent through the network
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear() {} virtual void clear() {}
// packet data // packet data
@ -252,7 +252,7 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo,
virtual ~RsGRouterRoutingInfoItem() { clear() ; } virtual ~RsGRouterRoutingInfoItem() { clear() ; }
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear() virtual void clear()
{ {
@ -271,7 +271,7 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo,
class RsGRouterSerialiser: public RsServiceSerializer class RsGRouterSerialiser: public RsServiceSerializer
{ {
public: public:
RsGRouterSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsServiceSerializer(RS_SERVICE_TYPE_GROUTER,SerializeContext::FORMAT_BINARY,flags) {} RsGRouterSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsServiceSerializer(RS_SERVICE_TYPE_GROUTER,RsGenericSerializer::FORMAT_BINARY,flags) {}
virtual RsItem *create_item(uint16_t service,uint8_t subtype) const ; virtual RsItem *create_item(uint16_t service,uint8_t subtype) const ;
}; };

View File

@ -27,9 +27,12 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include "rsitems/rsserviceids.h"
#include "rsitems/itempriorities.h"
#include "rsitems/rsitem.h"
#include "retroshare/rstypes.h" #include "retroshare/rstypes.h"
#include "serialiser/rstlvkeys.h" #include "serialiser/rstlvkeys.h"
#include "rsitems/rsserviceids.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvidset.h" #include "serialiser/rstlvidset.h"

View File

@ -452,7 +452,8 @@ HEADERS += grouter/groutercache.h \
grouter/groutertypes.h \ grouter/groutertypes.h \
grouter/rsgrouterclient.h grouter/rsgrouterclient.h
HEADERS += rsitems/itempriorities.h \ HEADERS += rsitems/rsitem.h \
rsitems/itempriorities.h \
serialiser/rsbaseserial.h \ serialiser/rsbaseserial.h \
rsitems/rsfiletransferitems.h \ rsitems/rsfiletransferitems.h \
serialiser/rsserviceserialiser.h \ serialiser/rsserviceserialiser.h \

View File

@ -27,6 +27,7 @@
#include "p3servicecontrol.h" #include "p3servicecontrol.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/rsitem.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rsbaseserial.h" #include "serialiser/rsbaseserial.h"
#include "pqi/p3cfgmgr.h" #include "pqi/p3cfgmgr.h"

View File

@ -27,8 +27,7 @@
#ifndef PQI_TOP_HEADER #ifndef PQI_TOP_HEADER
#define PQI_TOP_HEADER #define PQI_TOP_HEADER
#include "serialiser/rsserial.h" #include "rsitems/rsitem.h"
class P3Interface class P3Interface
{ {

View File

@ -11,7 +11,9 @@ const uint32_t pqiQoS::MAX_PACKET_COUNTER_VALUE = (1 << 24) ;
pqiQoS::pqiQoS(uint32_t nb_levels,float alpha) pqiQoS::pqiQoS(uint32_t nb_levels,float alpha)
: _item_queues(nb_levels),_alpha(alpha) : _item_queues(nb_levels),_alpha(alpha)
{ {
#ifdef DEBUG
assert(pow(alpha,nb_levels) < 1e+20) ; assert(pow(alpha,nb_levels) < 1e+20) ;
#endif
float c = 1.0f ; float c = 1.0f ;
float inc = alpha ; float inc = alpha ;
@ -110,7 +112,9 @@ void *pqiQoS::out_rsItem(uint32_t max_slice_size, uint32_t& size, bool& starts,
if(last >= 0) if(last >= 0)
{ {
#ifdef DEBUG
assert(_nb_items > 0) ; assert(_nb_items > 0) ;
#endif
// now chop a slice of this item // now chop a slice of this item

View File

@ -40,6 +40,7 @@
* *
*/ */
#include "rsitems/rsitem.h"
#include "pqi/pqistore.h" #include "pqi/pqistore.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include <iostream> #include <iostream>

View File

@ -41,12 +41,12 @@ void RsBanListItem::clear()
peerList.TlvClear(); peerList.TlvClear();
} }
void RsBanListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsBanListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,peerList,"peerList") ; RsTypeSerializer::serial_process(j,ctx,peerList,"peerList") ;
} }
void RsBanListConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsBanListConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,type,"type") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,type,"type") ;
RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ;

View File

@ -29,6 +29,8 @@
#include <map> #include <map>
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/rsitem.h"
#include "rsitems/itempriorities.h"
#include "serialiser/rstlvbanlist.h" #include "serialiser/rstlvbanlist.h"
#include "serialization/rsserializer.h" #include "serialization/rsserializer.h"
@ -50,7 +52,7 @@ class RsBanListItem: public RsItem
virtual ~RsBanListItem(){} virtual ~RsBanListItem(){}
virtual void clear(); virtual void clear();
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsTlvBanList peerList; RsTlvBanList peerList;
}; };
@ -64,7 +66,7 @@ public:
virtual ~RsBanListConfigItem(){} virtual ~RsBanListConfigItem(){}
virtual void clear() { banned_peers.TlvClear() ; } virtual void clear() { banned_peers.TlvClear() ; }
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t type ; uint32_t type ;
RsPeerId peerId ; RsPeerId peerId ;

View File

@ -52,7 +52,7 @@ void RsBwCtrlAllowedItem::clear()
allowedBw = 0; allowedBw = 0;
} }
void RsBwCtrlAllowedItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ;
} }

View File

@ -28,9 +28,9 @@
#include <map> #include <map>
#include "rsitems/rsitem.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "serialiser/rsserial.h" #include "rsitems/itempriorities.h"
#include "serialiser/rstlvbase.h"
#include "serialization/rsserializer.h" #include "serialization/rsserializer.h"
#include "serialization/rstypeserializer.h" #include "serialization/rstypeserializer.h"
@ -51,7 +51,7 @@ public:
virtual ~RsBwCtrlAllowedItem() {} virtual ~RsBwCtrlAllowedItem() {}
virtual void clear(); virtual void clear();
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t allowedBw; // Units are bytes/sec => 4Gb/s; uint32_t allowedBw; // Units are bytes/sec => 4Gb/s;
}; };

View File

@ -28,6 +28,7 @@
#include "rsitems/rsconfigitems.h" #include "rsitems/rsconfigitems.h"
#include "retroshare/rspeers.h" // Needed for RsGroupInfo. #include "retroshare/rspeers.h" // Needed for RsGroupInfo.
#include "serialization/rstypeserializer.h"
/*** /***
* #define RSSERIAL_DEBUG 1 * #define RSSERIAL_DEBUG 1
* #define RSSERIAL_ERROR_DEBUG 1 * #define RSSERIAL_ERROR_DEBUG 1
@ -69,7 +70,7 @@ void RsFileTransfer::clear()
} }
void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx) void RsFileTransfer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,allPeerIds,"allPeerIds") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,allPeerIds,"allPeerIds") ;
@ -91,7 +92,7 @@ void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx)
RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ; RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ;
} }
void RsFileConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsFileConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file,"file") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ; RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
@ -111,7 +112,7 @@ RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_su
} }
} }
void RsConfigKeyValueSet::serial_process(SerializeJob j,SerializeContext& ctx) void RsConfigKeyValueSet::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,tlvkvs,"tlvkvs") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,tlvkvs,"tlvkvs") ;
} }
@ -156,7 +157,7 @@ void RsPeerNetItem::clear()
domain_addr.clear(); domain_addr.clear();
domain_port = 0; domain_port = 0;
} }
void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsPeerNetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ; RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ;
RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ;
@ -181,12 +182,12 @@ void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx)
RsTypeSerializer::serial_process<uint16_t>(j,ctx,domain_port,"domain_port") ; RsTypeSerializer::serial_process<uint16_t>(j,ctx,domain_port,"domain_port") ;
} }
void RsPeerBandwidthLimitsItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsPeerBandwidthLimitsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,peers,"peers") ; RsTypeSerializer::serial_process(j,ctx,peers,"peers") ;
} }
void RsPeerStunItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,stunList,"stunList") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,stunList,"stunList") ;
} }
@ -226,7 +227,7 @@ RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g)
pgpList.ids = g.peerIds; pgpList.ids = g.peerIds;
} }
void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsNodeGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
uint32_t v=0 ; uint32_t v=0 ;
@ -237,14 +238,14 @@ void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx)
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpList,"pgpList") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpList,"pgpList") ;
} }
void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsPeerServicePermissionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
// We need to hack this because of backward compatibility. The correct way to do it would be: // We need to hack this because of backward compatibility. The correct way to do it would be:
// //
// RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ; // RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ;
// RsTypeSerializer::serial_process(j,ctx,service_flags,"service_flags") ; // RsTypeSerializer::serial_process(j,ctx,service_flags,"service_flags") ;
if(j == RsItem::DESERIALIZE) if(j == RsGenericSerializer::DESERIALIZE)
{ {
uint32_t v=0 ; uint32_t v=0 ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,v,"pgp_ids.size()") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,v,"pgp_ids.size()") ;

View File

@ -29,6 +29,8 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include "rsitems/rsitem.h"
#include "retroshare/rstypes.h" #include "retroshare/rstypes.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
@ -77,7 +79,7 @@ public:
virtual ~RsPeerNetItem(){} virtual ~RsPeerNetItem(){}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
/* networking information */ /* networking information */
RsPeerId peerId; /* Mandatory */ RsPeerId peerId; /* Mandatory */
@ -115,7 +117,7 @@ class RsPeerServicePermissionItem : public RsItem
pgp_ids.clear() ; pgp_ids.clear() ;
service_flags.clear() ; service_flags.clear() ;
} }
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
/* Mandatory */ /* Mandatory */
@ -132,7 +134,7 @@ class RsPeerBandwidthLimitsItem : public RsItem
{ {
peers.clear() ; peers.clear() ;
} }
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
/* Mandatory */ /* Mandatory */
std::map<RsPgpId,PeerBandwidthLimits> peers ; std::map<RsPgpId,PeerBandwidthLimits> peers ;
@ -172,7 +174,7 @@ public:
explicit RsNodeGroupItem(const RsGroupInfo&) ; explicit RsNodeGroupItem(const RsGroupInfo&) ;
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
// /* set data from RsGroupInfo to RsPeerGroupItem */ // /* set data from RsGroupInfo to RsPeerGroupItem */
// void set(RsGroupInfo &groupInfo); // void set(RsGroupInfo &groupInfo);
@ -197,7 +199,7 @@ public:
virtual ~RsPeerStunItem(){} virtual ~RsPeerStunItem(){}
virtual void clear() { stunList.TlvClear() ;} virtual void clear() { stunList.TlvClear() ;}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsTlvPeerIdSet stunList; /* Mandatory */ RsTlvPeerIdSet stunList; /* Mandatory */
}; };
@ -277,7 +279,7 @@ class RsFileTransfer: public RsItem
virtual ~RsFileTransfer(){} virtual ~RsFileTransfer(){}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsTlvFileItem file; RsTlvFileItem file;
RsTlvPeerIdSet allPeerIds; RsTlvPeerIdSet allPeerIds;
@ -331,7 +333,7 @@ public:
virtual ~RsFileConfigItem() {} virtual ~RsFileConfigItem() {}
virtual void clear() { parent_groups.TlvClear(); } virtual void clear() { parent_groups.TlvClear(); }
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsTlvFileItem file; RsTlvFileItem file;
uint32_t flags; uint32_t flags;
@ -359,7 +361,7 @@ public:
virtual ~RsConfigKeyValueSet(){} virtual ~RsConfigKeyValueSet(){}
virtual void clear() { tlvkvs.TlvClear();} virtual void clear() { tlvkvs.TlvClear();}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsTlvKeyValueSet tlvkvs; RsTlvKeyValueSet tlvkvs;
}; };

View File

@ -73,7 +73,7 @@ void RsDiscPgpListItem::clear()
pgpIdSet.TlvClear(); pgpIdSet.TlvClear();
} }
void RsDiscPgpListItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsDiscPgpListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mode,"mode") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,mode,"mode") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ;
@ -86,7 +86,7 @@ void RsDiscPgpCertItem::clear()
} }
void RsDiscPgpCertItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsDiscPgpCertItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ;
@ -121,7 +121,7 @@ void RsDiscContactItem::clear()
extAddrList.TlvClear(); extAddrList.TlvClear();
} }
void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsDiscContactItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,pgpId,"pgpId"); RsTypeSerializer::serial_process (j,ctx,pgpId,"pgpId");
RsTypeSerializer::serial_process (j,ctx,sslId,"sslId"); RsTypeSerializer::serial_process (j,ctx,sslId,"sslId");
@ -134,7 +134,7 @@ void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx)
// This is a hack. Normally we should have to different item types, in order to avoid this nonesense. // This is a hack. Normally we should have to different item types, in order to avoid this nonesense.
if(j == RsItem::DESERIALIZE) if(j == RsGenericSerializer::DESERIALIZE)
isHidden = ( GetTlvType( &(((uint8_t *) ctx.mData)[ctx.mOffset]) )==TLV_TYPE_STR_DOMADDR); isHidden = ( GetTlvType( &(((uint8_t *) ctx.mData)[ctx.mOffset]) )==TLV_TYPE_STR_DOMADDR);
if(isHidden) if(isHidden)

View File

@ -32,6 +32,8 @@
#include "serialiser/rstlvidset.h" #include "serialiser/rstlvidset.h"
#include "serialiser/rstlvaddrs.h" #include "serialiser/rstlvaddrs.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/rsitem.h"
#include "rsitems/itempriorities.h"
#include "serialization/rsserializer.h" #include "serialization/rsserializer.h"
@ -65,7 +67,7 @@ public:
virtual ~RsDiscPgpListItem(){} virtual ~RsDiscPgpListItem(){}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
uint32_t mode; uint32_t mode;
RsTlvPgpIdSet pgpIdSet; RsTlvPgpIdSet pgpIdSet;
@ -86,7 +88,7 @@ public:
virtual ~RsDiscPgpCertItem(){} virtual ~RsDiscPgpCertItem(){}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
RsPgpId pgpId; RsPgpId pgpId;
std::string pgpCert; std::string pgpCert;
@ -106,7 +108,7 @@ public:
virtual ~RsDiscContactItem() {} virtual ~RsDiscContactItem() {}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
RsPgpId pgpId; RsPgpId pgpId;
RsPeerId sslId; RsPeerId sslId;

View File

@ -53,38 +53,38 @@ void RsFileTransferDataItem::clear()
fd.TlvClear(); fd.TlvClear();
} }
void RsFileTransferDataRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsFileTransferDataRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint64_t> (j,ctx,fileoffset,"fileoffset") ; RsTypeSerializer::serial_process<uint64_t> (j,ctx,fileoffset,"fileoffset") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunksize, "chunksize") ; RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunksize, "chunksize") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file, "file") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,file, "file") ;
} }
void RsFileTransferDataItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsFileTransferDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,fd,"fd") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,fd,"fd") ;
} }
void RsFileTransferChunkMapRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsFileTransferChunkMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<bool> (j,ctx,is_client,"is_client") ; RsTypeSerializer::serial_process<bool> (j,ctx,is_client,"is_client") ;
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
} }
void RsFileTransferChunkMapItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsFileTransferChunkMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<bool> (j,ctx,is_client, "is_client") ; RsTypeSerializer::serial_process<bool> (j,ctx,is_client, "is_client") ;
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
RsTypeSerializer::serial_process (j,ctx,compressed_map,"compressed_map") ; RsTypeSerializer::serial_process (j,ctx,compressed_map,"compressed_map") ;
} }
void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;
} }
void RsFileTransferSingleChunkCrcItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsFileTransferSingleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process (j,ctx,hash, "hash") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,chunk_number,"chunk_number") ;

View File

@ -30,7 +30,9 @@
#include "retroshare/rstypes.h" #include "retroshare/rstypes.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvfileitem.h" #include "serialiser/rstlvfileitem.h"
#include "rsitems/rsitem.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/itempriorities.h"
#include "serialization/rsserializer.h" #include "serialization/rsserializer.h"
@ -70,7 +72,7 @@ class RsFileTransferDataRequestItem: public RsFileTransferItem
virtual ~RsFileTransferDataRequestItem() {} virtual ~RsFileTransferDataRequestItem() {}
virtual void clear(); virtual void clear();
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
// Private data part. // Private data part.
// //
@ -90,7 +92,7 @@ class RsFileTransferDataItem: public RsFileTransferItem
} }
virtual ~RsFileTransferDataItem() { clear() ; } virtual ~RsFileTransferDataItem() { clear() ; }
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear(); virtual void clear();
@ -109,7 +111,7 @@ class RsFileTransferChunkMapRequestItem: public RsFileTransferItem
virtual ~RsFileTransferChunkMapRequestItem() {} virtual ~RsFileTransferChunkMapRequestItem() {}
virtual void clear() {} virtual void clear() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
// Private data part. // Private data part.
// //
@ -127,7 +129,7 @@ class RsFileTransferChunkMapItem: public RsFileTransferItem
} }
virtual ~RsFileTransferChunkMapItem() {} virtual ~RsFileTransferChunkMapItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear() {} virtual void clear() {}
// Private data part. // Private data part.
@ -146,7 +148,7 @@ class RsFileTransferSingleChunkCrcRequestItem: public RsFileTransferItem
} }
virtual ~RsFileTransferSingleChunkCrcRequestItem() {} virtual ~RsFileTransferSingleChunkCrcRequestItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear() {} virtual void clear() {}
// Private data part. // Private data part.
@ -164,7 +166,7 @@ class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem
} }
virtual ~RsFileTransferSingleChunkCrcItem() {} virtual ~RsFileTransferSingleChunkCrcItem() {}
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
virtual void clear() {} virtual void clear() {}
// Private data part. // Private data part.

View File

@ -53,21 +53,21 @@ void RsGxsReputationBannedNodeSetItem::clear()
mKnownIdentities.TlvClear(); mKnownIdentities.TlvClear();
} }
void RsGxsReputationConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsGxsReputationConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,mPeerId,"mPeerId") ; RsTypeSerializer::serial_process (j,ctx,mPeerId,"mPeerId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastQuery,"mLastQuery") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastQuery,"mLastQuery") ;
} }
void RsGxsReputationBannedNodeSetItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsGxsReputationBannedNodeSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,mPgpId,"mPgpId") ; RsTypeSerializer::serial_process (j,ctx,mPgpId,"mPgpId") ;
RsTypeSerializer::serial_process<uint32_t> (j,ctx,mLastActivityTS,"mLastActivityTS") ; RsTypeSerializer::serial_process<uint32_t> (j,ctx,mLastActivityTS,"mLastActivityTS") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mKnownIdentities,"mKnownIdentities") ; RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mKnownIdentities,"mKnownIdentities") ;
} }
void RsGxsReputationSetItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsGxsReputationSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,mGxsId,"mGxsId") ; RsTypeSerializer::serial_process (j,ctx,mGxsId,"mGxsId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mOwnOpinion,"mOwnOpinion") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,mOwnOpinion,"mOwnOpinion") ;
@ -78,12 +78,12 @@ void RsGxsReputationSetItem::serial_process(RsItem::SerializeJob j,SerializeCont
RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ; RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ;
} }
void RsGxsReputationUpdateItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsGxsReputationUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLatestUpdate,"mLatestUpdate") ;
RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ; RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ;
} }
void RsGxsReputationRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUpdate,"mLastUpdate") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,mLastUpdate,"mLastUpdate") ;
} }

View File

@ -29,6 +29,9 @@
#include <map> #include <map>
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/rsitem.h"
#include "rsitems/itempriorities.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvidset.h" #include "serialiser/rstlvidset.h"
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
@ -66,7 +69,7 @@ public:
virtual ~RsGxsReputationConfigItem() {} virtual ~RsGxsReputationConfigItem() {}
virtual void clear() {} virtual void clear() {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
RsPeerId mPeerId; RsPeerId mPeerId;
uint32_t mLatestUpdate; // timestamp they returned. uint32_t mLatestUpdate; // timestamp they returned.
@ -110,7 +113,7 @@ public:
virtual ~RsGxsReputationSetItem() {} virtual ~RsGxsReputationSetItem() {}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
RsGxsId mGxsId; RsGxsId mGxsId;
uint32_t mOwnOpinion; uint32_t mOwnOpinion;
@ -128,7 +131,7 @@ public:
virtual ~RsGxsReputationBannedNodeSetItem() {} virtual ~RsGxsReputationBannedNodeSetItem() {}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
RsPgpId mPgpId ; RsPgpId mPgpId ;
uint32_t mLastActivityTS ; uint32_t mLastActivityTS ;
@ -143,7 +146,7 @@ public:
virtual ~RsGxsReputationUpdateItem() {} virtual ~RsGxsReputationUpdateItem() {}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
uint32_t mLatestUpdate; uint32_t mLatestUpdate;
std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion. std::map<RsGxsId, uint32_t> mOpinions; // GxsId -> Opinion.
@ -157,7 +160,7 @@ public:
virtual ~RsGxsReputationRequestItem() {} virtual ~RsGxsReputationRequestItem() {}
virtual void clear() {} virtual void clear() {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ;
uint32_t mLastUpdate; uint32_t mLastUpdate;
}; };

View File

@ -29,13 +29,15 @@
#include "serialiser/rsbaseserial.h" #include "serialiser/rsbaseserial.h"
#include "serialiser/rstlvbase.h" #include "serialiser/rstlvbase.h"
#include "serialization/rstypeserializer.h"
/*** /***
#define RSSERIAL_DEBUG 1 #define RSSERIAL_DEBUG 1
***/ ***/
#include <iostream> #include <iostream>
void RsHistoryMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsHistoryMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
uint16_t version=0; uint16_t version=0;

View File

@ -42,7 +42,7 @@ public:
virtual ~RsHistoryMsgItem() {} virtual ~RsHistoryMsgItem() {}
virtual void clear() {} virtual void clear() {}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsPeerId chatPeerId; // empty for global chat RsPeerId chatPeerId; // empty for global chat
bool incoming; bool incoming;

View File

@ -0,0 +1,90 @@
#pragma once
#include "util/smallobject.h"
#include "retroshare/rstypes.h"
#include "serialization/rsserializer.h"
class RsItem: public RsMemoryManagement::SmallObject
{
public:
RsItem(uint32_t t);
RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype);
#ifdef DO_STATISTICS
void *operator new(size_t s) ;
void operator delete(void *,size_t s) ;
#endif
virtual ~RsItem();
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t /* indent */ = 0)
{
RsGenericSerializer::SerializeContext ctx(NULL,0,RsGenericSerializer::FORMAT_BINARY,RsGenericSerializer::SERIALIZATION_FLAG_NONE);
serial_process(RsGenericSerializer::PRINT,ctx) ;
return out;
}
void print_string(std::string &out, uint16_t indent = 0);
/* source / destination id */
const RsPeerId& PeerId() const { return peerId; }
void PeerId(const RsPeerId& id) { peerId = id; }
/* complete id */
uint32_t PacketId() const;
/* id parts */
uint8_t PacketVersion();
uint8_t PacketClass();
uint8_t PacketType();
uint8_t PacketSubType() const;
/* For Service Packets */
RsItem(uint8_t ver, uint16_t service, uint8_t subtype);
uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */
void setPacketService(uint16_t service);
inline uint8_t priority_level() const { return _priority_level ;}
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
/**
* @brief serialize this object to the given buffer
* @param Job to do: serialise or deserialize.
* @param data Chunk of memory were to dump the serialized data
* @param size Size of memory chunk
* @param offset Readed to determine at witch offset start writing data,
* written to inform caller were written data ends, the updated value
* is usually passed by the caller to serialize of another
* RsSerializable so it can write on the same chunk of memory just
* after where this RsSerializable has been serialized.
* @return true if serialization successed, false otherwise
*/
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */)
{
std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! Class is " << typeid(*this).name() << std::endl;
}
protected:
uint32_t type;
RsPeerId peerId;
uint8_t _priority_level ;
};
class RsRawItem: public RsItem
{
public:
RsRawItem(uint32_t t, uint32_t size) : RsItem(t), len(size)
{ data = rs_malloc(len); }
virtual ~RsRawItem() { free(data); }
uint32_t getRawLength() { return len; }
void * getRawData() { return data; }
virtual void clear() {}
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
private:
void *data;
uint32_t len;
};

View File

@ -80,25 +80,25 @@ void RsMsgItem::clear()
attachment.TlvClear(); attachment.TlvClear();
} }
void RsPublicMsgInviteConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsPublicMsgInviteConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_SHA1,hash,"hash") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_SHA1,hash,"hash") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,(uint32_t&)time_stamp,"time_stamp") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,(uint32_t&)time_stamp,"time_stamp") ;
} }
void RsMsgTagType::serial_process(SerializeJob j,SerializeContext& ctx) void RsMsgTagType::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,text,"text") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,text,"text") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,rgb_color,"rgb_color") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,rgb_color,"rgb_color") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tagId,"tagId") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tagId,"tagId") ;
} }
void RsMsgTags::serial_process(SerializeJob j,SerializeContext& ctx) void RsMsgTags::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
#warning this is not the correct way to serialise here. We should directly call serial_process<std::vector<uint32_t> >() but for backward compatibility, we cannot #warning this is not the correct way to serialise here. We should directly call serial_process<std::vector<uint32_t> >() but for backward compatibility, we cannot
if(j == RsItem::DESERIALIZE) if(j == RsGenericSerializer::DESERIALIZE)
while(ctx.mOffset < ctx.mSize) while(ctx.mOffset < ctx.mSize)
{ {
uint32_t n ; uint32_t n ;
@ -110,13 +110,13 @@ void RsMsgTags::serial_process(SerializeJob j,SerializeContext& ctx)
RsTypeSerializer::serial_process<uint32_t>(j,ctx,*it,"tagIds element") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,*it,"tagIds element") ;
} }
void RsMsgSrcId::serial_process(SerializeJob j,SerializeContext& ctx) void RsMsgSrcId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
RsTypeSerializer::serial_process (j,ctx,srcId,"srcId") ; RsTypeSerializer::serial_process (j,ctx,srcId,"srcId") ;
} }
void RsMsgGRouterMap::serial_process(SerializeJob j,SerializeContext& ctx) void RsMsgGRouterMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,ongoing_msgs,"ongoing_msgs") ; RsTypeSerializer::serial_process(j,ctx,ongoing_msgs,"ongoing_msgs") ;
} }
@ -128,18 +128,18 @@ void RsMsgGRouterMap::clear()
return; return;
} }
void RsMsgDistantMessagesHashMap::serial_process(SerializeJob j,SerializeContext& ctx) void RsMsgDistantMessagesHashMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process(j,ctx,hash_map,"hash_map") ; RsTypeSerializer::serial_process(j,ctx,hash_map,"hash_map") ;
} }
void RsMsgParentId::serial_process(SerializeJob j,SerializeContext& ctx) void RsMsgParentId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgId,"msgId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgParentId,"msgParentId") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgParentId,"msgParentId") ;
} }
void RsMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgFlags,"msgFlags"); RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgFlags,"msgFlags");
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime"); RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime");

View File

@ -101,7 +101,7 @@ class RsMsgItem: public RsMessageItem
virtual ~RsMsgItem() {} virtual ~RsMsgItem() {}
virtual void clear(); virtual void clear();
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
// ----------- Specific fields ------------- // // ----------- Specific fields ------------- //
@ -130,7 +130,7 @@ class RsMsgTagType : public RsMessageItem
public: public:
RsMsgTagType() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAG_TYPE) {} RsMsgTagType() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAG_TYPE) {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
virtual ~RsMsgTagType() {} virtual ~RsMsgTagType() {}
virtual void clear(); virtual void clear();
@ -148,7 +148,7 @@ public:
RsMsgTags() RsMsgTags()
:RsMessageItem(RS_PKT_SUBTYPE_MSG_TAGS) {} :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAGS) {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
virtual ~RsMsgTags() {} virtual ~RsMsgTags() {}
virtual void clear(); virtual void clear();
@ -164,7 +164,7 @@ class RsMsgSrcId : public RsMessageItem
public: public:
RsMsgSrcId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_SRC_TAG) {} RsMsgSrcId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_SRC_TAG) {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
virtual ~RsMsgSrcId() {} virtual ~RsMsgSrcId() {}
virtual void clear(){} virtual void clear(){}
@ -180,7 +180,7 @@ class RsPublicMsgInviteConfigItem : public RsMessageItem
public: public:
RsPublicMsgInviteConfigItem() : RsMessageItem(RS_PKT_SUBTYPE_MSG_INVITE) {} RsPublicMsgInviteConfigItem() : RsMessageItem(RS_PKT_SUBTYPE_MSG_INVITE) {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
virtual ~RsPublicMsgInviteConfigItem() {} virtual ~RsPublicMsgInviteConfigItem() {}
virtual void clear(); virtual void clear();
@ -196,7 +196,7 @@ class RsMsgGRouterMap : public RsMessageItem
public: public:
RsMsgGRouterMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_GROUTER_MAP) {} RsMsgGRouterMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_GROUTER_MAP) {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
virtual ~RsMsgGRouterMap() {} virtual ~RsMsgGRouterMap() {}
virtual void clear(); virtual void clear();
@ -210,7 +210,7 @@ class RsMsgDistantMessagesHashMap : public RsMessageItem
public: public:
RsMsgDistantMessagesHashMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP) {} RsMsgDistantMessagesHashMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP) {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
virtual ~RsMsgDistantMessagesHashMap() {} virtual ~RsMsgDistantMessagesHashMap() {}
virtual void clear() { hash_map.clear() ;} virtual void clear() { hash_map.clear() ;}
@ -224,7 +224,7 @@ class RsMsgParentId : public RsMessageItem
public: public:
RsMsgParentId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_PARENT_TAG) {} RsMsgParentId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_PARENT_TAG) {}
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
virtual ~RsMsgParentId() {} virtual ~RsMsgParentId() {}
virtual void clear(){} virtual void clear(){}
@ -239,7 +239,7 @@ class RsMsgSerialiser: public RsServiceSerializer
{ {
public: public:
RsMsgSerialiser(SerializationFlags flags) RsMsgSerialiser(SerializationFlags flags)
:RsServiceSerializer(RS_SERVICE_TYPE_MSG,SerializeContext::FORMAT_BINARY,flags){} :RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){}
virtual ~RsMsgSerialiser() {} virtual ~RsMsgSerialiser() {}

View File

@ -32,6 +32,8 @@
#include <iostream> #include <iostream>
#include "serialization/rstypeserializer.h"
/*************************************************************************/ /*************************************************************************/
RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const
@ -48,13 +50,13 @@ RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const
} }
} }
void RsRttPingItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsRttPingItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mSeqNo,"mSeqNo") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,mSeqNo,"mSeqNo") ;
RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPingTS,"mPingTS") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPingTS,"mPingTS") ;
} }
void RsRttPongItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsRttPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mSeqNo,"mSeqNo") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,mSeqNo,"mSeqNo") ;
RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPingTS,"mPingTS") ; RsTypeSerializer::serial_process<uint64_t>(j,ctx,mPingTS,"mPingTS") ;

View File

@ -28,7 +28,9 @@
#include <map> #include <map>
#include "rsitems/rsitem.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/itempriorities.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialization/rsserializer.h" #include "serialization/rsserializer.h"
@ -56,7 +58,7 @@ class RsRttPingItem: public RsRttItem
virtual ~RsRttPingItem(){} virtual ~RsRttPingItem(){}
virtual void clear(){} virtual void clear(){}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t mSeqNo; uint32_t mSeqNo;
uint64_t mPingTS; uint64_t mPingTS;
@ -70,7 +72,7 @@ class RsRttPongItem: public RsRttItem
virtual ~RsRttPongItem(){} virtual ~RsRttPongItem(){}
virtual void clear(){} virtual void clear(){}
virtual void serial_process(SerializeJob j,SerializeContext& ctx); virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
uint32_t mSeqNo; uint32_t mSeqNo;
uint64_t mPingTS; uint64_t mPingTS;

View File

@ -26,6 +26,7 @@
* *
*/ */
#include "rsitems/rsitem.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
//#include "serialiser/rstlvtypes.h" //#include "serialiser/rstlvtypes.h"

View File

@ -28,7 +28,10 @@
#include <map> #include <map>
#include "rsitems/rsitem.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/itempriorities.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvkeys.h" #include "serialiser/rstlvkeys.h"
#include "serialiser/rstlvidset.h" #include "serialiser/rstlvidset.h"

View File

@ -30,6 +30,8 @@
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/rsitem.h"
#include "rsitems/itempriorities.h"
const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01; const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01;

View File

@ -31,6 +31,7 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/itempriorities.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h" #include "serialiser/rstlvbase.h"
#include "serialiser/rstlvitem.h" #include "serialiser/rstlvitem.h"

View File

@ -25,11 +25,14 @@
*/ */
#include "serialiser/rsbaseserial.h" #include "serialiser/rsbaseserial.h"
#include "serialiser/rsserial.h"
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "util/rsstring.h" #include "util/rsstring.h"
#include "util/rsprint.h" #include "util/rsprint.h"
#include "rsitems/rsitem.h"
#include "rsitems/itempriorities.h"
#include <math.h> #include <math.h>
#include <map> #include <map>
#include <vector> #include <vector>

View File

@ -34,9 +34,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "util/rsmemory.h"
#include "retroshare/rstypes.h"
/******************************************************************* /*******************************************************************
* This is the Top-Level serialiser/deserialise, * This is the Top-Level serialiser/deserialise,
* *
@ -59,9 +56,6 @@
* 8 bits: SubType * 8 bits: SubType
******************************************************************/ ******************************************************************/
#include <util/smallobject.h>
#include "rsitems/itempriorities.h"
const uint8_t RS_PKT_VERSION1 = 0x01; const uint8_t RS_PKT_VERSION1 = 0x01;
const uint8_t RS_PKT_VERSION_SERVICE = 0x02; const uint8_t RS_PKT_VERSION_SERVICE = 0x02;
@ -70,74 +64,7 @@ const uint8_t RS_PKT_CLASS_CONFIG = 0x02;
const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */ const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */
class SerializeContext ; class RsItem ;
class RsItem: public RsMemoryManagement::SmallObject
{
public:
RsItem(uint32_t t);
RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype);
#ifdef DO_STATISTICS
void *operator new(size_t s) ;
void operator delete(void *,size_t s) ;
#endif
virtual ~RsItem();
virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0)
{
std::cerr << "(EE) RsItem::print() called by an item using new serialization classes, but not derived! " << std::endl;
#warning This method should normally call serial_process(PRINT,ctx)
return out;
}
void print_string(std::string &out, uint16_t indent = 0);
/* source / destination id */
const RsPeerId& PeerId() const { return peerId; }
void PeerId(const RsPeerId& id) { peerId = id; }
/* complete id */
uint32_t PacketId() const;
/* id parts */
uint8_t PacketVersion();
uint8_t PacketClass();
uint8_t PacketType();
uint8_t PacketSubType() const;
/* For Service Packets */
RsItem(uint8_t ver, uint16_t service, uint8_t subtype);
uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */
void setPacketService(uint16_t service);
inline uint8_t priority_level() const { return _priority_level ;}
inline void setPriorityLevel(uint8_t l) { _priority_level = l ;}
/**
* @brief serialize this object to the given buffer
* @param Job to do: serialise or deserialize.
* @param data Chunk of memory were to dump the serialized data
* @param size Size of memory chunk
* @param offset Readed to determine at witch offset start writing data,
* written to inform caller were written data ends, the updated value
* is usually passed by the caller to serialize of another
* RsSerializable so it can write on the same chunk of memory just
* after where this RsSerializable has been serialized.
* @return true if serialization successed, false otherwise
*/
typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ;
virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */)
{
std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! " << std::endl;
}
protected:
uint32_t type;
RsPeerId peerId;
uint8_t _priority_level ;
};
class RsSerialType class RsSerialType
{ {
@ -201,23 +128,4 @@ std::ostream &printRsItemEnd(std::ostream &o, std::string n, uint16_t i);
std::ostream &printIndent(std::ostream &out, uint16_t indent); std::ostream &printIndent(std::ostream &out, uint16_t indent);
/* Wrapper class for data that is serialised somewhere else */ /* Wrapper class for data that is serialised somewhere else */
class RsRawItem: public RsItem
{
public:
RsRawItem(uint32_t t, uint32_t size) : RsItem(t), len(size)
{ data = rs_malloc(len); }
virtual ~RsRawItem() { free(data); }
uint32_t getRawLength() { return len; }
void * getRawData() { return data; }
virtual void clear() {}
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
private:
void *data;
uint32_t len;
};
#endif /* RS_BASE_SERIALISER_H */ #endif /* RS_BASE_SERIALISER_H */

View File

@ -31,6 +31,9 @@
#include <map> #include <map>
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "rsitems/rsitem.h"
#include "rsitems/itempriorities.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h" #include "serialiser/rstlvbase.h"
#include "serialiser/rstlvgenericmap.h" #include "serialiser/rstlvgenericmap.h"

View File

@ -23,6 +23,7 @@
* *
*/ */
#include "rsitems/rsitem.h"
#include "rsserviceserialiser.h" #include "rsserviceserialiser.h"
uint32_t RsServiceSerialiser::size(RsItem *i) uint32_t RsServiceSerialiser::size(RsItem *i)

View File

@ -27,7 +27,8 @@
*/ */
#include "rsitems/rsserviceids.h" #include "rsitems/rsserviceids.h"
#include "serialiser/rsserial.h" #include "rsitems/itempriorities.h"
#include "rsitems/rsitem.h"
/**************************************************************************/ /**************************************************************************/

View File

@ -1,5 +1,7 @@
#include <typeinfo> #include <typeinfo>
#include "rsitems/rsitem.h"
#include "util/rsprint.h" #include "util/rsprint.h"
#include "serialization/rsserializer.h" #include "serialization/rsserializer.h"
#include "serialization/rstypeserializer.h" #include "serialization/rstypeserializer.h"
@ -31,7 +33,7 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size)
SerializeContext ctx(const_cast<uint8_t*>(static_cast<uint8_t*>(data)),*size,mFormat,mFlags); SerializeContext ctx(const_cast<uint8_t*>(static_cast<uint8_t*>(data)),*size,mFormat,mFlags);
ctx.mOffset = 8 ; ctx.mOffset = 8 ;
item->serial_process(RsItem::DESERIALIZE, ctx) ; item->serial_process(RsGenericSerializer::DESERIALIZE, ctx) ;
if(ctx.mSize != ctx.mOffset) if(ctx.mSize != ctx.mOffset)
{ {
@ -67,7 +69,7 @@ RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size)
SerializeContext ctx(const_cast<uint8_t*>(static_cast<uint8_t*>(data)),*size,mFormat,mFlags); SerializeContext ctx(const_cast<uint8_t*>(static_cast<uint8_t*>(data)),*size,mFormat,mFlags);
ctx.mOffset = 8 ; ctx.mOffset = 8 ;
item->serial_process(RsItem::DESERIALIZE, ctx) ; item->serial_process(DESERIALIZE, ctx) ;
if(ctx.mSize != ctx.mOffset) if(ctx.mSize != ctx.mOffset)
{ {
@ -105,7 +107,7 @@ bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size)
ctx.mSize = tlvsize; ctx.mSize = tlvsize;
item->serial_process(RsItem::SERIALIZE,ctx) ; item->serial_process(RsGenericSerializer::SERIALIZE,ctx) ;
if(ctx.mSize != ctx.mOffset) if(ctx.mSize != ctx.mOffset)
{ {
@ -123,7 +125,7 @@ uint32_t RsGenericSerializer::size(RsItem *item)
ctx.mOffset = 0; ctx.mOffset = 0;
else else
ctx.mOffset = 8 ; // header size ctx.mOffset = 8 ; // header size
item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; item->serial_process(SIZE_ESTIMATE, ctx) ;
return ctx.mOffset ; return ctx.mOffset ;
} }
@ -133,7 +135,7 @@ void RsGenericSerializer::print(RsItem *item)
SerializeContext ctx(NULL,0,mFormat,mFlags); SerializeContext ctx(NULL,0,mFormat,mFlags);
std::cerr << "***** RsItem class: \"" << typeid(*item).name() << "\" *****" << std::endl; std::cerr << "***** RsItem class: \"" << typeid(*item).name() << "\" *****" << std::endl;
item->serial_process(RsItem::PRINT, ctx) ; item->serial_process(PRINT, ctx) ;
std::cerr << "******************************" << std::endl; std::cerr << "******************************" << std::endl;
} }

View File

@ -5,15 +5,34 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "retroshare/rsflags.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialization/rstypeserializer.h"
class RsItem ;
#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : "
class RsGenericSerializer: public RsSerialType class RsGenericSerializer: public RsSerialType
{ {
public: public:
typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ;
typedef enum { FORMAT_BINARY = 0x01, FORMAT_JSON = 0x02 } SerializationFormat ;
class SerializeContext
{
public:
SerializeContext(uint8_t *data,uint32_t size,SerializationFormat format,SerializationFlags flags)
: mData(data),mSize(size),mOffset(0),mOk(true),mFormat(format),mFlags(flags) {}
unsigned char *mData ;
uint32_t mSize ;
uint32_t mOffset ;
bool mOk ;
SerializationFormat mFormat ;
SerializationFlags mFlags ;
};
// These are convenience flags to be used by the items when processing the data. The names of the flags // 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 // are not very important. What matters is that the serial_process() method of each item correctly
@ -36,18 +55,18 @@ public:
protected: protected:
RsGenericSerializer(uint8_t serial_class, RsGenericSerializer(uint8_t serial_class,
uint8_t serial_type, uint8_t serial_type,
SerializeContext::SerializationFormat format, SerializationFormat format,
SerializationFlags flags ) SerializationFlags flags )
: RsSerialType(RS_PKT_VERSION1,serial_class,serial_type), mFormat(format),mFlags(flags) : RsSerialType(RS_PKT_VERSION1,serial_class,serial_type), mFormat(format),mFlags(flags)
{} {}
RsGenericSerializer(uint16_t service, RsGenericSerializer(uint16_t service,
SerializeContext::SerializationFormat format, SerializationFormat format,
SerializationFlags flags ) SerializationFlags flags )
: RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags) : RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags)
{} {}
SerializeContext::SerializationFormat mFormat ; SerializationFormat mFormat ;
SerializationFlags mFlags ; SerializationFlags mFlags ;
}; };
@ -56,8 +75,8 @@ class RsServiceSerializer: public RsGenericSerializer
{ {
public: public:
RsServiceSerializer(uint16_t service_id, RsServiceSerializer(uint16_t service_id,
SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, SerializationFormat format = FORMAT_BINARY,
SerializationFlags flags = SERIALIZATION_FLAG_NONE) SerializationFlags flags = SERIALIZATION_FLAG_NONE)
: RsGenericSerializer(service_id,format,flags) {} : RsGenericSerializer(service_id,format,flags) {}
@ -74,8 +93,8 @@ class RsConfigSerializer: public RsGenericSerializer
public: public:
RsConfigSerializer(uint8_t config_class, RsConfigSerializer(uint8_t config_class,
uint8_t config_type, uint8_t config_type,
SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, SerializationFormat format = FORMAT_BINARY,
SerializationFlags flags = RsGenericSerializer::SERIALIZATION_FLAG_NONE) SerializationFlags flags = SERIALIZATION_FLAG_NONE)
: RsGenericSerializer(config_class,config_type,format,flags) {} : RsGenericSerializer(config_class,config_type,format,flags) {}

View File

@ -7,25 +7,7 @@
#include "retroshare/rsflags.h" #include "retroshare/rsflags.h"
#include "retroshare/rsids.h" #include "retroshare/rsids.h"
class SerializeContext #include "serialization/rsserializer.h"
{
public:
enum SerializationFormat {
FORMAT_BINARY = 0x01 ,
FORMAT_JSON = 0x02
};
SerializeContext(uint8_t *data,uint32_t size,SerializationFormat format,SerializationFlags flags)
: mData(data),mSize(size),mOffset(0),mOk(true),mFormat(format),mFlags(flags) {}
unsigned char *mData ;
uint32_t mSize ;
uint32_t mOffset ;
bool mOk ;
SerializationFormat mFormat ;
SerializationFlags mFlags ;
};
class RsTypeSerializer class RsTypeSerializer
@ -44,20 +26,20 @@ class RsTypeSerializer
//=================================================================================================// //=================================================================================================//
template<typename T> template<typename T>
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name) static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,T& member,const std::string& member_name)
{ {
switch(j) switch(j)
{ {
case RsItem::SIZE_ESTIMATE: ctx.mOffset += serial_size(member) ; case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += serial_size(member) ;
break ; break ;
case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; case RsGenericSerializer::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ;
break ; break ;
case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; case RsGenericSerializer::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ;
break ; break ;
case RsItem::PRINT: case RsGenericSerializer::PRINT:
print_data(member_name,member); print_data(member_name,member);
break; break;
default: default:
@ -71,20 +53,20 @@ class RsTypeSerializer
//=================================================================================================// //=================================================================================================//
template<typename T> template<typename T>
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,uint16_t type_id,T& member,const std::string& member_name) static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,uint16_t type_id,T& member,const std::string& member_name)
{ {
switch(j) switch(j)
{ {
case RsItem::SIZE_ESTIMATE: ctx.mOffset += serial_size(type_id,member) ; case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += serial_size(type_id,member) ;
break ; break ;
case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; case RsGenericSerializer::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ;
break ; break ;
case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; case RsGenericSerializer::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ;
break ; break ;
case RsItem::PRINT: case RsGenericSerializer::PRINT:
print_data(member_name,type_id,member); print_data(member_name,type_id,member);
break; break;
default: default:
@ -97,11 +79,11 @@ class RsTypeSerializer
//=================================================================================================// //=================================================================================================//
template<typename T,typename U> template<typename T,typename U>
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::map<T,U>& v,const std::string& member_name) static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::map<T,U>& v,const std::string& member_name)
{ {
switch(j) switch(j)
{ {
case RsItem::SIZE_ESTIMATE: case RsGenericSerializer::SIZE_ESTIMATE:
{ {
ctx.mOffset += 4 ; ctx.mOffset += 4 ;
for(typename std::map<T,U>::iterator it(v.begin());it!=v.end();++it) for(typename std::map<T,U>::iterator it(v.begin());it!=v.end();++it)
@ -112,7 +94,7 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::DESERIALIZE: case RsGenericSerializer::DESERIALIZE:
{ {
uint32_t n=0 ; uint32_t n=0 ;
ctx.mOk = ctx.mOk && deserialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ; ctx.mOk = ctx.mOk && deserialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ;
@ -130,7 +112,7 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::SERIALIZE: case RsGenericSerializer::SERIALIZE:
{ {
uint32_t n=v.size(); uint32_t n=v.size();
ctx.mOk = ctx.mOk && serialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ; ctx.mOk = ctx.mOk && serialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ;
@ -143,12 +125,12 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::PRINT: case RsGenericSerializer::PRINT:
{ {
if(v.empty()) if(v.empty())
std::cerr << " Empty map"<< std::endl; std::cerr << " Empty map \"" << member_name << "\"" << std::endl;
else else
std::cerr << " std::map of " << v.size() << " elements:" << std::endl; std::cerr << " std::map of " << v.size() << " elements: \"" << member_name << "\"" << std::endl;
for(typename std::map<T,U>::iterator it(v.begin());it!=v.end();++it) for(typename std::map<T,U>::iterator it(v.begin());it!=v.end();++it)
{ {
@ -169,11 +151,11 @@ class RsTypeSerializer
//=================================================================================================// //=================================================================================================//
template<typename T> template<typename T>
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::vector<T>& v,const std::string& member_name) static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::vector<T>& v,const std::string& member_name)
{ {
switch(j) switch(j)
{ {
case RsItem::SIZE_ESTIMATE: case RsGenericSerializer::SIZE_ESTIMATE:
{ {
ctx.mOffset += 4 ; ctx.mOffset += 4 ;
for(uint32_t i=0;i<v.size();++i) for(uint32_t i=0;i<v.size();++i)
@ -181,7 +163,7 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::DESERIALIZE: case RsGenericSerializer::DESERIALIZE:
{ uint32_t n=0 ; { uint32_t n=0 ;
serial_process(j,ctx,n,"temporary size") ; serial_process(j,ctx,n,"temporary size") ;
@ -191,7 +173,7 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::SERIALIZE: case RsGenericSerializer::SERIALIZE:
{ {
uint32_t n=v.size(); uint32_t n=v.size();
serial_process(j,ctx,n,"temporary size") ; serial_process(j,ctx,n,"temporary size") ;
@ -200,7 +182,7 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::PRINT: case RsGenericSerializer::PRINT:
{ {
if(v.empty()) if(v.empty())
std::cerr << " Empty array"<< std::endl; std::cerr << " Empty array"<< std::endl;
@ -223,11 +205,11 @@ class RsTypeSerializer
//=================================================================================================// //=================================================================================================//
template<typename T> template<typename T>
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::list<T>& v,const std::string& member_name) static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::list<T>& v,const std::string& member_name)
{ {
switch(j) switch(j)
{ {
case RsItem::SIZE_ESTIMATE: case RsGenericSerializer::SIZE_ESTIMATE:
{ {
ctx.mOffset += 4 ; ctx.mOffset += 4 ;
for(typename std::list<T>::iterator it(v.begin());it!=v.end();++it) for(typename std::list<T>::iterator it(v.begin());it!=v.end();++it)
@ -235,7 +217,7 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::DESERIALIZE: case RsGenericSerializer::DESERIALIZE:
{ uint32_t n=0 ; { uint32_t n=0 ;
serial_process(j,ctx,n,"temporary size") ; serial_process(j,ctx,n,"temporary size") ;
@ -248,7 +230,7 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::SERIALIZE: case RsGenericSerializer::SERIALIZE:
{ {
uint32_t n=v.size(); uint32_t n=v.size();
serial_process(j,ctx,n,"temporary size") ; serial_process(j,ctx,n,"temporary size") ;
@ -257,7 +239,7 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::PRINT: case RsGenericSerializer::PRINT:
{ {
if(v.empty()) if(v.empty())
std::cerr << " Empty list"<< std::endl; std::cerr << " Empty list"<< std::endl;
@ -275,14 +257,14 @@ class RsTypeSerializer
//=================================================================================================// //=================================================================================================//
template<int N> template<int N>
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,t_RsFlags32<N>& v,const std::string& member_name) static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,t_RsFlags32<N>& v,const std::string& member_name)
{ {
switch(j) switch(j)
{ {
case RsItem::SIZE_ESTIMATE: ctx.mOffset += 4 ; case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += 4 ;
break ; break ;
case RsItem::DESERIALIZE: case RsGenericSerializer::DESERIALIZE:
{ {
uint32_t n=0 ; uint32_t n=0 ;
deserialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ; deserialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ;
@ -290,14 +272,14 @@ class RsTypeSerializer
} }
break ; break ;
case RsItem::SERIALIZE: case RsGenericSerializer::SERIALIZE:
{ {
uint32_t n=v.toUInt32() ; uint32_t n=v.toUInt32() ;
serialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ; serialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ;
} }
break ; break ;
case RsItem::PRINT: case RsGenericSerializer::PRINT:
std::cerr << " Flags of type " << std::hex << N << " : " << v.toUInt32() << std::endl; std::cerr << " Flags of type " << std::hex << N << " : " << v.toUInt32() << std::endl;
break ; break ;
} }

View File

@ -23,6 +23,8 @@
* *
*/ */
#include "rsitems/itempriorities.h"
#include "pqi/pqi.h" #include "pqi/pqi.h"
#include "util/rsstring.h" #include "util/rsstring.h"
#include "services/p3service.h" #include "services/p3service.h"

View File

@ -48,14 +48,14 @@ RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype) c
return NULL ; return NULL ;
} }
void RsTurtleStringSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleStringSearchRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_VALUE,match_string,"match_string") ; RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_VALUE,match_string,"match_string") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ; RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
} }
void RsTurtleRegExpSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleRegExpSearchRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth,"depth") ; RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth,"depth") ;
@ -140,7 +140,7 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsRegul
std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl; std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl;
} }
void RsTurtleSearchResultItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ; RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
@ -193,7 +193,7 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleF
std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl; std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl;
} }
void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleOpenTunnelItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ; RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id ,"request_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id ,"request_id") ;
@ -201,13 +201,13 @@ void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx
RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ; RsTypeSerializer::serial_process<uint16_t>(j,ctx,depth ,"depth") ;
} }
void RsTurtleTunnelOkItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleTunnelOkItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id ,"tunnel_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id ,"tunnel_id") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,request_id,"request_id") ;
} }
void RsTurtleGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) void RsTurtleGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{ {
RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id ,"tunnel_id") ; RsTypeSerializer::serial_process<uint32_t>(j,ctx,tunnel_id ,"tunnel_id") ;

View File

@ -1,12 +1,16 @@
#pragma once #pragma once
#include "rsitems/rsserviceids.h"
#include "rsitems/rsitem.h"
#include "rsitems/itempriorities.h"
#include "serialiser/rsserial.h" #include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h" #include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h" #include "serialiser/rsbaseserial.h"
#include "retroshare/rsturtle.h" #include "retroshare/rsturtle.h"
#include "retroshare/rsexpr.h" #include "retroshare/rsexpr.h"
#include "retroshare/rstypes.h" #include "retroshare/rstypes.h"
#include "rsitems/rsserviceids.h"
#include "turtle/turtletypes.h" #include "turtle/turtletypes.h"
#include "serialization/rsserializer.h" #include "serialization/rsserializer.h"
@ -58,7 +62,7 @@ class RsTurtleSearchResultItem: public RsTurtleItem
void clear() { result.clear() ; } void clear() { result.clear() ; }
protected: protected:
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
@ -87,7 +91,7 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem
void clear() { match_string.clear() ; } void clear() { match_string.clear() ; }
protected: protected:
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
@ -102,7 +106,7 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem
void clear() { expr = RsRegularExpression::LinearizedExpression(); } void clear() { expr = RsRegularExpression::LinearizedExpression(); }
protected: protected:
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
/***********************************************************************************/ /***********************************************************************************/
@ -121,7 +125,7 @@ class RsTurtleOpenTunnelItem: public RsTurtleItem
void clear() { file_hash.clear() ;} void clear() { file_hash.clear() ;}
protected: protected:
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
class RsTurtleTunnelOkItem: public RsTurtleItem class RsTurtleTunnelOkItem: public RsTurtleItem
@ -134,7 +138,7 @@ class RsTurtleTunnelOkItem: public RsTurtleItem
void clear() {} void clear() {}
protected: protected:
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
/***********************************************************************************/ /***********************************************************************************/
@ -198,7 +202,7 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem
data_size = 0; data_size = 0;
} }
protected: protected:
void serial_process(SerializeJob j,SerializeContext& ctx); void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
}; };
/***********************************************************************************/ /***********************************************************************************/