mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-20 15:00:36 -04:00
Remove default template for to/from_JSON
This way the compiler will complain if a type is added directly to RsTypeSerializer without specify all needed serial operations
This commit is contained in:
parent
13d4a2c916
commit
ba6f2d7e81
10 changed files with 126 additions and 144 deletions
|
@ -28,6 +28,7 @@
|
|||
#include "rsitems/rsconfigitems.h"
|
||||
#include "retroshare/rspeers.h" // Needed for RsGroupInfo.
|
||||
|
||||
#include "serialiser/rsserializable.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
|
@ -89,7 +90,7 @@ void RsFileTransfer::serial_process(RsGenericSerializer::SerializeJob j,RsGeneri
|
|||
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,flags,"flags") ;
|
||||
RsTypeSerializer::serial_process<uint32_t> (j,ctx,chunk_strategy,"chunk_strategy") ;
|
||||
RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ;
|
||||
RS_SERIAL_PROCESS(compressed_chunk_map);
|
||||
}
|
||||
|
||||
void RsFileConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
|
@ -192,31 +193,7 @@ void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneri
|
|||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,stunList,"stunList") ;
|
||||
}
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const PeerBandwidthLimits& /*s*/)
|
||||
{
|
||||
return 4+4 ;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const PeerBandwidthLimits& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
ok = ok && setRawUInt32(data,size,&offset,s.max_up_rate_kbs);
|
||||
ok = ok && setRawUInt32(data,size,&offset,s.max_dl_rate_kbs);
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,PeerBandwidthLimits& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
ok = ok && getRawUInt32(data,size,&offset,&s.max_up_rate_kbs);
|
||||
ok = ok && getRawUInt32(data,size,&offset,&s.max_dl_rate_kbs);
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& /*n*/, const PeerBandwidthLimits& s)
|
||||
{
|
||||
std::cerr << " [Peer BW limit] " << s.max_up_rate_kbs << " / " << s.max_dl_rate_kbs << std::endl;
|
||||
}
|
||||
RS_REGISTER_SERIALIZABLE_TYPE_DEF(PeerBandwidthLimits)
|
||||
|
||||
RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g)
|
||||
:RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_PEER_CONFIG, RS_PKT_SUBTYPE_NODE_GROUP)
|
||||
|
|
|
@ -91,48 +91,6 @@ void RsFileTransferSingleChunkCrcItem::serial_process(RsGenericSerializer::Seria
|
|||
RsTypeSerializer::serial_process (j,ctx,check_sum, "check_sum") ;
|
||||
}
|
||||
|
||||
//===================================================================================================//
|
||||
// CompressedChunkMap //
|
||||
//===================================================================================================//
|
||||
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const CompressedChunkMap& s)
|
||||
{
|
||||
return 4 + 4*s._map.size() ;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset,const CompressedChunkMap& s)
|
||||
{
|
||||
bool ok = true ;
|
||||
|
||||
ok &= setRawUInt32(data, size, &offset, s._map.size());
|
||||
|
||||
for(uint32_t i=0;i<s._map.size() && ok;++i)
|
||||
ok &= setRawUInt32(data, size, &offset, s._map[i]);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size,uint32_t& offset,CompressedChunkMap& s)
|
||||
{
|
||||
uint32_t S =0;
|
||||
bool ok = getRawUInt32(data, size, &offset, &S);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
s._map.resize(S) ;
|
||||
|
||||
for(uint32_t i=0;i<S && ok;++i)
|
||||
ok &= getRawUInt32(data, size, &offset, &(s._map[i]));
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& n, const CompressedChunkMap& s)
|
||||
{
|
||||
std::cerr << " [Compressed chunk map] " << n << " : length=" << s._map.size() << std::endl;
|
||||
}
|
||||
|
||||
//===================================================================================================//
|
||||
// Serializer //
|
||||
//===================================================================================================//
|
||||
|
|
|
@ -97,30 +97,9 @@ void RsGxsMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
|
|||
RsTypeSerializer::serial_process(j,ctx,msgUpdateInfos,"msgUpdateInfos");
|
||||
}
|
||||
|
||||
template<> bool RsTypeSerializer::serialize(uint8_t data[], uint32_t size, uint32_t &offset, const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
||||
{
|
||||
bool ok = true ;
|
||||
RS_REGISTER_SERIALIZABLE_TYPE_DEF(RsGxsMsgUpdate::MsgUpdateInfo)
|
||||
|
||||
ok = ok && setRawUInt32(data,size,&offset,info.time_stamp);
|
||||
ok = ok && setRawUInt32(data,size,&offset,info.message_count);
|
||||
|
||||
return ok;
|
||||
}
|
||||
template<> bool RsTypeSerializer::deserialize(const uint8_t data[], uint32_t size, uint32_t &offset, RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
||||
{
|
||||
bool ok = true ;
|
||||
|
||||
ok = ok && getRawUInt32(data,size,&offset,&info.time_stamp);
|
||||
ok = ok && getRawUInt32(data,size,&offset,&info.message_count);
|
||||
|
||||
return ok;
|
||||
}
|
||||
template<> uint32_t RsTypeSerializer::serial_size(const RsGxsMsgUpdateItem::MsgUpdateInfo& /* info */) { return 8; }
|
||||
|
||||
template<> void RsTypeSerializer::print_data(const std::string& name,const RsGxsMsgUpdateItem::MsgUpdateInfo& info)
|
||||
{
|
||||
std::cerr << "[MsgUpdateInfo]: " << name << ": " << info.time_stamp << ", " << info.message_count << std::endl;
|
||||
}
|
||||
|
||||
void RsGxsServerMsgUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
|
|
|
@ -28,18 +28,11 @@
|
|||
|
||||
|
||||
|
||||
#if 0
|
||||
#include <map>
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#endif
|
||||
|
||||
#include "gxs/rsgxs.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
#include "serialiser/rsserializable.h"
|
||||
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXS_GRP_UPDATE = 0x01;
|
||||
|
@ -140,17 +133,27 @@ public:
|
|||
class RsGxsMsgUpdate
|
||||
{
|
||||
public:
|
||||
struct MsgUpdateInfo
|
||||
struct MsgUpdateInfo : RsSerializable
|
||||
{
|
||||
MsgUpdateInfo(): time_stamp(0), message_count(0) {}
|
||||
|
||||
uint32_t time_stamp ;
|
||||
uint32_t message_count ;
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RS_SERIAL_PROCESS(time_stamp);
|
||||
RS_SERIAL_PROCESS(message_count);
|
||||
}
|
||||
};
|
||||
|
||||
std::map<RsGxsGroupId, MsgUpdateInfo> msgUpdateInfos;
|
||||
};
|
||||
|
||||
RS_REGISTER_SERIALIZABLE_TYPE_DECL(RsGxsMsgUpdate::MsgUpdateInfo)
|
||||
|
||||
class RsGxsMsgUpdateItem : public RsGxsNetServiceItem, public RsGxsMsgUpdate
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue