mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 08:59:37 -05:00
fixed compilation
This commit is contained in:
parent
48688eae3f
commit
5b3e488b42
@ -593,10 +593,10 @@ template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,Serializ
|
|||||||
TlvString tt1(info.name ,TLV_TYPE_STR_NAME) ;
|
TlvString tt1(info.name ,TLV_TYPE_STR_NAME) ;
|
||||||
TlvString tt2(info.topic,TLV_TYPE_STR_NAME) ;
|
TlvString tt2(info.topic,TLV_TYPE_STR_NAME) ;
|
||||||
|
|
||||||
RsTypeSerializer::serial_process(j,ctx,info.name,"info.name") ;
|
RsTypeSerializer::serial_process(j,ctx,tt1,"info.name") ;
|
||||||
RsTypeSerializer::serial_process(j,ctx,info.topic,"info.topic") ;
|
RsTypeSerializer::serial_process(j,ctx,tt2,"info.topic") ;
|
||||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,info.count,"info.count") ;
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,info.count,"info.count") ;
|
||||||
RsTypeSerializer::serial_process<ChatLobbyFlags>(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(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
@ -641,7 +641,7 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex
|
|||||||
RsTypeSerializer::TlvString tt(string1,TLV_TYPE_STR_NAME) ;
|
RsTypeSerializer::TlvString tt(string1,TLV_TYPE_STR_NAME) ;
|
||||||
|
|
||||||
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,string1,"string1") ;
|
RsTypeSerializer::serial_process (j,ctx,tt ,"string1") ;
|
||||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime ,"sendTime") ;
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime ,"sendTime") ;
|
||||||
|
|
||||||
RsChatLobbyBouncingObject::serial_process(j,ctx,true) ;
|
RsChatLobbyBouncingObject::serial_process(j,ctx,true) ;
|
||||||
@ -781,7 +781,7 @@ void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeConte
|
|||||||
RsTypeSerializer::TlvString s(lobby_name,TLV_TYPE_STR_NAME) ;
|
RsTypeSerializer::TlvString s(lobby_name,TLV_TYPE_STR_NAME) ;
|
||||||
|
|
||||||
RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ;
|
RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ;
|
||||||
RsTypeSerializer::serial_process<ChatLobbyFlags>(j,ctx,lobby_flags,"lobby_flags") ;
|
RsTypeSerializer::serial_process(j,ctx,lobby_flags,"lobby_flags") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TO_BE_REMOVED
|
#ifdef TO_BE_REMOVED
|
||||||
@ -913,7 +913,7 @@ bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsi
|
|||||||
|
|
||||||
void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
{
|
{
|
||||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ;
|
RsTypeSerializer::serial_process(j,ctx,flags,"flags") ;
|
||||||
|
|
||||||
RsTypeSerializer::TlvString tt(status_string,TLV_TYPE_STR_MSG) ;
|
RsTypeSerializer::TlvString tt(status_string,TLV_TYPE_STR_MSG) ;
|
||||||
|
|
||||||
@ -1012,7 +1012,7 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,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<uint32_t>(j,ctx,flags,"flags") ;
|
RsTypeSerializer::serial_process(j,ctx,flags,"flags") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TO_BE_REMOVED
|
#ifdef TO_BE_REMOVED
|
||||||
|
@ -120,7 +120,7 @@ template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> c
|
|||||||
offset += SIZE_IN_BYTES ;
|
offset += SIZE_IN_BYTES ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
bool deserialise(void *data,uint32_t pktsize,uint32_t& offset)
|
bool deserialise(const void *data,uint32_t pktsize,uint32_t& offset)
|
||||||
{
|
{
|
||||||
if(offset + SIZE_IN_BYTES > pktsize)
|
if(offset + SIZE_IN_BYTES > pktsize)
|
||||||
return false ;
|
return false ;
|
||||||
|
@ -122,7 +122,7 @@ class RsItem: public RsMemoryManagement::SmallObject
|
|||||||
*/
|
*/
|
||||||
typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ;
|
typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ;
|
||||||
|
|
||||||
virtual void serial_process(SerializeJob j,SerializeContext& ctx)
|
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;
|
std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! " << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class RsSerializer: public RsSerialType
|
|||||||
/*! create_item
|
/*! create_item
|
||||||
* should be overloaded to create the correct type of item depending on the data
|
* should be overloaded to create the correct type of item depending on the data
|
||||||
*/
|
*/
|
||||||
virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id)
|
virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */)
|
||||||
{
|
{
|
||||||
return NULL ;
|
return NULL ;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <typeinfo>
|
|
||||||
|
|
||||||
#include "serialiser/rsserial.h"
|
#include "serialiser/rsserial.h"
|
||||||
#include "serialiser/rstlvbase.h"
|
#include "serialiser/rstlvbase.h"
|
||||||
|
|
||||||
|
#include "retroshare/rsflags.h"
|
||||||
|
#include "retroshare/rsids.h"
|
||||||
|
|
||||||
class SerializeContext
|
class SerializeContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -44,6 +45,10 @@ protected:
|
|||||||
|
|
||||||
static BinaryDataBlock_ref& block_ref(unsigned char *mem,uint32_t& size) { return BinaryDataBlock_ref(mem,size).modifiable() ; }
|
static BinaryDataBlock_ref& block_ref(unsigned char *mem,uint32_t& size) { return BinaryDataBlock_ref(mem,size).modifiable() ; }
|
||||||
|
|
||||||
|
//=================================================================================================//
|
||||||
|
// Generic types //
|
||||||
|
//=================================================================================================//
|
||||||
|
|
||||||
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(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name)
|
||||||
{
|
{
|
||||||
@ -67,7 +72,9 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arrays of stuff
|
//=================================================================================================//
|
||||||
|
// std::vector<T> //
|
||||||
|
//=================================================================================================//
|
||||||
|
|
||||||
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(RsItem::SerializeJob j,SerializeContext& ctx,std::vector<T>& v,const std::string& member_name)
|
||||||
@ -106,7 +113,7 @@ protected:
|
|||||||
if(v.empty())
|
if(v.empty())
|
||||||
std::cerr << " Empty array"<< std::endl;
|
std::cerr << " Empty array"<< std::endl;
|
||||||
else
|
else
|
||||||
std::cerr << " Array of \"" << typeid(v[0]).name() << "\"" << " with " << v.size() << " elements:";
|
std::cerr << " Array of " << v.size() << " elements:" << std::endl;
|
||||||
for(uint32_t i=0;i<v.size();++i)
|
for(uint32_t i=0;i<v.size();++i)
|
||||||
{
|
{
|
||||||
std::cerr << " " ;
|
std::cerr << " " ;
|
||||||
@ -118,6 +125,39 @@ protected:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//=================================================================================================//
|
||||||
|
// t_RsFlags32<> types //
|
||||||
|
//=================================================================================================//
|
||||||
|
|
||||||
|
template<int N>
|
||||||
|
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,t_RsFlags32<N>& v,const std::string& member_name)
|
||||||
|
{
|
||||||
|
switch(j)
|
||||||
|
{
|
||||||
|
case RsItem::SIZE_ESTIMATE: ctx.mOffset += 4 ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case RsItem::DESERIALIZE:
|
||||||
|
{
|
||||||
|
uint32_t n=0 ;
|
||||||
|
deserialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ;
|
||||||
|
v = t_RsFlags32<N>(n) ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case RsItem::SERIALIZE:
|
||||||
|
{
|
||||||
|
uint32_t n=v.toUInt32() ;
|
||||||
|
serialize<uint32_t>(ctx.mData,ctx.mSize,ctx.mOffset,n) ;
|
||||||
|
}
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case RsItem::PRINT:
|
||||||
|
std::cerr << " Flags of type " << std::hex << N << " : " << v.toUInt32() << std::endl;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<class T> static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member);
|
template<class T> static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const T& member);
|
||||||
@ -125,7 +165,36 @@ protected:
|
|||||||
template<class T> static uint32_t serial_size(const T& /* member */);
|
template<class T> static uint32_t serial_size(const T& /* member */);
|
||||||
template<class T> static void print_data(const std::string& name,const T& /* member */);
|
template<class T> static void print_data(const std::string& name,const T& /* member */);
|
||||||
|
|
||||||
|
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> static bool serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member);
|
||||||
|
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> static bool deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member);
|
||||||
|
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> static uint32_t serial_size(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& /* member */);
|
||||||
|
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER> static void print_data(const std::string& name,const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& /* member */);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//=================================================================================================//
|
||||||
|
// t_RsGenericId<> //
|
||||||
|
//=================================================================================================//
|
||||||
|
|
||||||
|
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
|
||||||
|
bool RsTypeSerializer::serialize (uint8_t data[], uint32_t size, uint32_t &offset, const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member)
|
||||||
|
{
|
||||||
|
return (*const_cast<const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER> *>(&member)).serialise(data,size,offset) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
|
||||||
|
bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member)
|
||||||
|
{
|
||||||
|
return member.deserialise(data,size,offset) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
|
||||||
|
uint32_t RsTypeSerializer::serial_size(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member)
|
||||||
|
{
|
||||||
|
return member.serial_size();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<uint32_t ID_SIZE_IN_BYTES,bool UPPER_CASE,uint32_t UNIQUE_IDENTIFIER>
|
||||||
|
void RsTypeSerializer::print_data(const std::string& name,const t_RsGenericIdType<ID_SIZE_IN_BYTES,UPPER_CASE,UNIQUE_IDENTIFIER>& member)
|
||||||
|
{
|
||||||
|
std::cerr << " [RsGenericId<" << std::hex << UNIQUE_IDENTIFIER << ">] : " << member << std::endl;
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "util/rsmemory.h"
|
#include "util/rsmemory.h"
|
||||||
#include "util/rsprint.h"
|
#include "util/rsprint.h"
|
||||||
@ -90,9 +91,9 @@ class RsTestItem: public RsItem
|
|||||||
str = "test string";
|
str = "test string";
|
||||||
ts = time(NULL) ;
|
ts = time(NULL) ;
|
||||||
|
|
||||||
int_set.insert(lrand48()) ;
|
int_set.push_back(lrand48()) ;
|
||||||
int_set.insert(lrand48()) ;
|
int_set.push_back(lrand48()) ;
|
||||||
int_set.insert(lrand48()) ;
|
int_set.push_back(lrand48()) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derived from RsItem
|
// Derived from RsItem
|
||||||
@ -114,7 +115,7 @@ class RsTestItem: public RsItem
|
|||||||
private:
|
private:
|
||||||
std::string str ;
|
std::string str ;
|
||||||
uint64_t ts ;
|
uint64_t ts ;
|
||||||
std::set<uint32_t> int_set ;
|
std::vector<uint32_t> int_set ;
|
||||||
|
|
||||||
friend int main(int argc,char *argv[]);
|
friend int main(int argc,char *argv[]);
|
||||||
};
|
};
|
||||||
@ -148,6 +149,7 @@ class RsTestSerializer: public RsSerializer
|
|||||||
void check(const std::string& s1,const std::string& s2) { assert(s1 == s2) ; }
|
void check(const std::string& s1,const std::string& s2) { assert(s1 == s2) ; }
|
||||||
void check(const uint64_t& s1,const uint64_t& s2) { assert(s1 == s2) ; }
|
void check(const uint64_t& s1,const uint64_t& s2) { assert(s1 == s2) ; }
|
||||||
void check(const std::set<uint32_t>& s1,const std::set<uint32_t>& s2) { assert(s1 == s2) ; }
|
void check(const std::set<uint32_t>& s1,const std::set<uint32_t>& s2) { assert(s1 == s2) ; }
|
||||||
|
void check(const std::vector<uint32_t>& s1,const std::vector<uint32_t>& s2) { assert(s1 == s2) ; }
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int main(int argc,char *argv[])
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user