mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 07:59:29 -05:00
moved rsserializer and rstypeserializer to serialiser/
This commit is contained in:
parent
4f92f483fa
commit
e401b90e02
@ -29,7 +29,7 @@
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#include "chat/rschatitems.h"
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include "openssl/bn.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#include "file_sharing/rsfilelistitems.h"
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
// These items have "flag type" numbers, but this is not used.
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <rsitems/itempriorities.h>
|
||||
#include <ft/ftturtlefiletransferitem.h>
|
||||
|
||||
#include <serialization/rstypeserializer.h>
|
||||
#include <serialiser/rstypeserializer.h>
|
||||
|
||||
void RsTurtleFileMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "grouteritems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/**********************************************************************************************/
|
||||
/* SERIALISER STUFF */
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <time.h>
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
|
@ -770,11 +770,11 @@ SOURCES += gxstunnel/p3gxstunnel.cc \
|
||||
gxstunnel/rsgxstunnelitems.cc
|
||||
|
||||
# new serialization code
|
||||
HEADERS += serialization/rsserializer.h \
|
||||
serialization/rstypeserializer.h
|
||||
HEADERS += serialiser/rsserializer.h \
|
||||
serialiser/rstypeserializer.h
|
||||
|
||||
SOURCES += serialization/rsserializer.cc \
|
||||
serialization/rstypeserializer.cc
|
||||
SOURCES += serialiser/rsserializer.cc \
|
||||
serialiser/rstypeserializer.cc
|
||||
|
||||
# Identity Service
|
||||
HEADERS += retroshare/rsidentity.h \
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsbanlistitems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "serialiser/rstlvbanlist.h"
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM_deprecated 0x01
|
||||
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM_deprecated 0x02
|
||||
|
@ -32,8 +32,8 @@
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM 0x01
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rspeers.h" // Needed for RsGroupInfo.
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define RSSERIAL_ERROR_DEBUG 1
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include "serialiser/rstlvkeyvalue.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
class RsGroupInfo;
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "rsitems/rsdiscovery2items.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#if 0
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02;
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "rsitems/rsfiletransferitems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_DATA_REQUEST = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_FT_DATA = 0x02;
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
RsItem *RsGxsChannelSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
#include "retroshare/rsgxschannels.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include "rsgxscircleitems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
//#define CIRCLE_DEBUG 1
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "rsgxscommentitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
//#define GXSCOMMENT_DEBUG 1
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include "rsgxsforumitems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
//#define GXSFORUM_DEBUG 1
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "serialiser/rstlvstring.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define GXSID_DEBUG 1
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "rsitems/rsgxsrecognitems.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "rsitems/rsgxsreputationitems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated2 0x02
|
||||
|
@ -23,7 +23,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "rsgxsupdateitems.h"
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "util/smallobject.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
class RsItem: public RsMemoryManagement::SmallObject
|
||||
{
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "rsitems/rsmsgitems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "util/rsprint.h"
|
||||
#include <iomanip>
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "rsitems/rsphotoitems.h"
|
||||
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define GXS_PHOTO_SERIAL_DEBUG
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#include "retroshare/rsphoto.h"
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
const uint8_t RS_PKT_CLASS_PLUGIN_SUBTYPE_HASHSET = 0x01 ;
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "rsitems/rsposteditems.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "rsitems/rsserviceinfoitems.h"
|
||||
|
||||
/***
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "rsitems/itempriorities.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include "rsitems/rswikiitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define GXSID_DEBUG 1
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include "rswireitems.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#define WIRE_DEBUG 1
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include "rsitems/rsitem.h"
|
||||
|
||||
#include "util/rsprint.h"
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 );
|
||||
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 );
|
@ -7,7 +7,7 @@
|
||||
#include "retroshare/rsflags.h"
|
||||
#include "retroshare/rsids.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
|
||||
class RsTypeSerializer
|
@ -1,196 +0,0 @@
|
||||
// COMPILE_LINE: g++ -g serial_test.cc -I.. -o serial_test ../lib/libretroshare.a -lssl -lcrypto -lstdc++ -lpthread
|
||||
//
|
||||
//
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "util/rsmemory.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
#include "rsserializer.h"
|
||||
#include "rstypeserializer.h"
|
||||
|
||||
#define GET_VARIABLE_NAME(str) #str
|
||||
|
||||
static const uint16_t RS_SERVICE_TYPE_TEST = 0xffff;
|
||||
static const uint8_t RS_ITEM_SUBTYPE_TEST1 = 0x01 ;
|
||||
|
||||
// Template serialization of RsTypeSerialiser::serial_process() for unknown/new types
|
||||
// Here we do it for std::set<uint32_t> as an example.
|
||||
//
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const std::set<uint32_t>& s)
|
||||
{
|
||||
return s.size() * 4 + 4 ;
|
||||
}
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const std::set<uint32_t>& member)
|
||||
{
|
||||
uint32_t tlvsize = serial_size(member) ;
|
||||
bool ok = true ;
|
||||
uint32_t offset_save = offset ;
|
||||
|
||||
if(tlvsize + offset > size)
|
||||
{
|
||||
std::cerr << "RsTypeSerializer::serialize: error. tlvsize+offset > size, where tlvsize=" << tlvsize << ", offset=" << offset << ", size=" << size << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
ok = ok && RsTypeSerializer::serialize<uint32_t>(data,size,offset,member.size()) ;
|
||||
|
||||
for(std::set<uint32_t>::const_iterator it(member.begin());it!=member.end();++it)
|
||||
ok = ok && RsTypeSerializer::serialize<uint32_t>(data,size,offset,*it) ;
|
||||
|
||||
if(!ok)
|
||||
{
|
||||
std::cerr << "(EE) Cannot serialize std::set<uint32_t>" << std::endl;
|
||||
offset = offset_save ; // return the data in the same condition
|
||||
}
|
||||
return ok ;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, std::set<uint32_t>& member)
|
||||
{
|
||||
bool ok = true ;
|
||||
uint32_t n = 0 ;
|
||||
uint32_t offset_save = offset ;
|
||||
member.clear();
|
||||
|
||||
ok = ok && RsTypeSerializer::deserialize(data,size,offset,n);
|
||||
|
||||
for(uint32_t i=0;i<n && ok;++i)
|
||||
{
|
||||
uint32_t x;
|
||||
ok = ok && RsTypeSerializer::deserialize(data,size,offset,x) ;
|
||||
|
||||
member.insert(x);
|
||||
}
|
||||
|
||||
if(!ok)
|
||||
{
|
||||
std::cerr << "(EE) Cannot deserialize std::set<uint32_t>" << std::endl;
|
||||
offset = offset_save ; // return the data in the same condition
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& s,const std::set<uint32_t>& set)
|
||||
{
|
||||
std::cerr << " [set<uint32_t>] " << s << " : set of size " << set.size() << std::endl;
|
||||
}
|
||||
|
||||
// New item class. This class needs to define:
|
||||
// - a serial_process method that tells which members to serialize
|
||||
// - overload the clear() and print() methods of RsItem
|
||||
//
|
||||
class RsTestItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsTestItem() : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TEST,RS_ITEM_SUBTYPE_TEST1)
|
||||
{
|
||||
str = "test string";
|
||||
ts = time(NULL) ;
|
||||
|
||||
int_set.push_back(lrand48()) ;
|
||||
int_set.push_back(lrand48()) ;
|
||||
int_set.push_back(lrand48()) ;
|
||||
}
|
||||
|
||||
// Derived from RsItem
|
||||
//
|
||||
virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::TlvString_proxy tt(str,TLV_TYPE_STR_DESCR) ;
|
||||
|
||||
RsTypeSerializer::serial_process(j,ctx,ts ,GET_VARIABLE_NAME(ts) ) ;
|
||||
RsTypeSerializer::serial_process(j,ctx,tt ,GET_VARIABLE_NAME(str) ) ;
|
||||
RsTypeSerializer::serial_process(j,ctx,int_set,GET_VARIABLE_NAME(int_set) ) ;
|
||||
}
|
||||
|
||||
// Derived from RsItem, because they are pure virtuals. Normally print() should disappear soon.
|
||||
//
|
||||
virtual void clear() {}
|
||||
virtual std::ostream& print(std::ostream&,uint16_t) {}
|
||||
|
||||
private:
|
||||
std::string str ;
|
||||
uint64_t ts ;
|
||||
std::vector<uint32_t> int_set ;
|
||||
|
||||
friend int main(int argc,char *argv[]);
|
||||
};
|
||||
|
||||
// New user-defined serializer class.
|
||||
// The only required member is the create_item() method, which creates the correct RsItem
|
||||
// that corresponds to a specific (service,subtype) couple.
|
||||
//
|
||||
class RsTestSerializer: public RsSerializer
|
||||
{
|
||||
public:
|
||||
RsTestSerializer() : RsSerializer(RS_SERVICE_TYPE_TEST) {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t subtype)
|
||||
{
|
||||
if(service_id != RS_SERVICE_TYPE_TEST)
|
||||
return NULL ;
|
||||
|
||||
switch(subtype)
|
||||
{
|
||||
case RS_ITEM_SUBTYPE_TEST1: return new RsTestItem();
|
||||
|
||||
default:
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Methods to check the equality of items.
|
||||
//
|
||||
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 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[])
|
||||
{
|
||||
try
|
||||
{
|
||||
RsTestItem t1 ;
|
||||
|
||||
uint32_t size = RsTestSerializer().size(&t1);
|
||||
|
||||
std::cerr << "t1.serial_size() = " << size << std::endl;
|
||||
|
||||
// Allocate some memory to serialise to
|
||||
//
|
||||
RsTemporaryMemory mem1(size);
|
||||
|
||||
std::cerr << "Item to be serialized:" << std::endl;
|
||||
|
||||
RsTestSerializer().print(&t1) ;
|
||||
RsTestSerializer().serialise(&t1,mem1,&size);
|
||||
|
||||
std::cerr << "Serialized t1: " << RsUtil::BinToHex(mem1,mem1.size()) << std::endl;
|
||||
|
||||
// Now deserialise into a new item
|
||||
//
|
||||
RsItem *t2 = RsTestSerializer().deserialise(mem1,&size);
|
||||
|
||||
// make sure t1 is equal to t2
|
||||
//
|
||||
check(t1.str,dynamic_cast<RsTestItem*>(t2)->str) ;
|
||||
check(t1.ts,dynamic_cast<RsTestItem*>(t2)->ts) ;
|
||||
check(t1.int_set,dynamic_cast<RsTestItem*>(t2)->int_set) ;
|
||||
|
||||
delete t2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception caught: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "rsturtleitem.h"
|
||||
#include "turtleclientservice.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
//#define P3TURTLE_DEBUG
|
||||
// -----------------------------------------------------------------------------------//
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "turtle/turtletypes.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
const uint8_t RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST = 0x01 ;
|
||||
const uint8_t RS_TURTLE_SUBTYPE_SEARCH_RESULT = 0x02 ;
|
||||
|
Loading…
Reference in New Issue
Block a user