From 4d03b906b88ea63770561568c4da2f6298110bfb Mon Sep 17 00:00:00 2001 From: sehraf Date: Sat, 25 Aug 2018 16:51:49 +0200 Subject: [PATCH 1/3] convert values properly to string --- libretroshare/src/serialiser/rstypeserializer.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/serialiser/rstypeserializer.cc b/libretroshare/src/serialiser/rstypeserializer.cc index 9a21eef0f..f620f7af0 100644 --- a/libretroshare/src/serialiser/rstypeserializer.cc +++ b/libretroshare/src/serialiser/rstypeserializer.cc @@ -169,23 +169,23 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const bool & } template<> void RsTypeSerializer::print_data(const std::string& n, const int32_t& V) { - std::cerr << " [int32_t ] " << n << ": " << V << std::endl; + std::cerr << " [int32_t ] " << n << ": " << std::to_string(V) << std::endl; } template<> void RsTypeSerializer::print_data(const std::string& n, const uint8_t & V) { - std::cerr << " [uint8_t ] " << n << ": " << V << std::endl; + std::cerr << " [uint8_t ] " << n << ": " << std::to_string(V) << std::endl; } template<> void RsTypeSerializer::print_data(const std::string& n, const uint16_t& V) { - std::cerr << " [uint16_t ] " << n << ": " << V << std::endl; + std::cerr << " [uint16_t ] " << n << ": " << std::to_string(V) << std::endl; } template<> void RsTypeSerializer::print_data(const std::string& n, const uint32_t& V) { - std::cerr << " [uint32_t ] " << n << ": " << V << std::endl; + std::cerr << " [uint32_t ] " << n << ": " << std::to_string(V) << std::endl; } template<> void RsTypeSerializer::print_data(const std::string& n, const uint64_t& V) { - std::cerr << " [uint64_t ] " << n << ": " << V << std::endl; + std::cerr << " [uint64_t ] " << n << ": " << std::to_string(V) << std::endl; } template<> void RsTypeSerializer::print_data(const std::string& n, const time_t& V) { From 588295e1e541b438af17db985887ffcef71121bf Mon Sep 17 00:00:00 2001 From: sehraf Date: Sat, 25 Aug 2018 16:52:46 +0200 Subject: [PATCH 2/3] make RsGroupInfo serializable --- libretroshare/src/retroshare/rspeers.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 01fb7ba8d..a77a5c4b3 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -293,16 +293,25 @@ public: std::string cipher_version; }; -class RsGroupInfo +class RsGroupInfo : RsSerializable { public: - RsGroupInfo(); + RsGroupInfo(); - RsNodeGroupId id; - std::string name; - uint32_t flag; + RsNodeGroupId id; + std::string name; + uint32_t flag; - std::set peerIds; + std::set peerIds; + + // RsSerializable interface +public: + void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { + RS_SERIAL_PROCESS(id); + RS_SERIAL_PROCESS(name); + RS_SERIAL_PROCESS(flag); + RS_SERIAL_PROCESS(peerIds); + } }; std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail); From c754435944d77b149ae5560640989263d94ad625 Mon Sep 17 00:00:00 2001 From: sehraf Date: Sat, 25 Aug 2018 17:10:01 +0200 Subject: [PATCH 3/3] fix deserialisation and improve PRINT job --- .../src/serialiser/rstypeserializer.h | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/libretroshare/src/serialiser/rstypeserializer.h b/libretroshare/src/serialiser/rstypeserializer.h index fd4984ef6..fc13d42e4 100644 --- a/libretroshare/src/serialiser/rstypeserializer.h +++ b/libretroshare/src/serialiser/rstypeserializer.h @@ -94,21 +94,25 @@ {\ for (auto&& arrEl : jDoc[arrKey].GetArray())\ {\ + Value arrKeyT;\ + arrKeyT.SetString(memberName.c_str(), memberName.length());\ +\ RsGenericSerializer::SerializeContext elCtx(\ nullptr, 0, ctx.mFlags, &allocator );\ - elCtx.mJson.AddMember(arrKey, arrEl, allocator);\ + elCtx.mJson.AddMember(arrKeyT, arrEl, allocator);\ \ T el;\ serial_process(j, elCtx, el, memberName); \ ok = ok && elCtx.mOk;\ -\ ctx.mOk &= ok;\ if(ok) v.INSERT_FUN(el);\ else break;\ }\ }\ -\ - ctx.mOk = false;\ + else\ + {\ + ctx.mOk = false;\ + }\ \ } while(false) @@ -351,8 +355,10 @@ struct RsTypeSerializer else break; } } - - ctx.mOk = false; + else + { + ctx.mOk = false; + } break; } default: @@ -479,10 +485,12 @@ struct RsTypeSerializer case RsGenericSerializer::PRINT: { if(v.empty()) - std::cerr << " Empty array"<< std::endl; - else - std::cerr << " Array of " << v.size() << " elements:" + std::cerr << " Empty vector \"" << memberName << "\"" << std::endl; + else + std::cerr << " Vector of " << v.size() << " elements: \"" + << memberName << "\"" << std::endl; + for(uint32_t i=0;i