Merge pull request #2 from sehraf/pr_improve_json

Multiple fixes on json handling by sehraf
This commit is contained in:
G10h4ck 2018-08-25 18:05:56 +02:00 committed by GitHub
commit 41f7235ed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 26 deletions

View File

@ -293,7 +293,7 @@ public:
std::string cipher_version; std::string cipher_version;
}; };
class RsGroupInfo class RsGroupInfo : RsSerializable
{ {
public: public:
RsGroupInfo(); RsGroupInfo();
@ -303,6 +303,15 @@ public:
uint32_t flag; uint32_t flag;
std::set<RsPgpId> peerIds; std::set<RsPgpId> 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); std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);

View File

@ -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) 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) 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) 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) 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) 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) template<> void RsTypeSerializer::print_data(const std::string& n, const time_t& V)
{ {

View File

@ -94,21 +94,25 @@
{\ {\
for (auto&& arrEl : jDoc[arrKey].GetArray())\ for (auto&& arrEl : jDoc[arrKey].GetArray())\
{\ {\
Value arrKeyT;\
arrKeyT.SetString(memberName.c_str(), memberName.length());\
\
RsGenericSerializer::SerializeContext elCtx(\ RsGenericSerializer::SerializeContext elCtx(\
nullptr, 0, ctx.mFlags, &allocator );\ nullptr, 0, ctx.mFlags, &allocator );\
elCtx.mJson.AddMember(arrKey, arrEl, allocator);\ elCtx.mJson.AddMember(arrKeyT, arrEl, allocator);\
\ \
T el;\ T el;\
serial_process(j, elCtx, el, memberName); \ serial_process(j, elCtx, el, memberName); \
ok = ok && elCtx.mOk;\ ok = ok && elCtx.mOk;\
\
ctx.mOk &= ok;\ ctx.mOk &= ok;\
if(ok) v.INSERT_FUN(el);\ if(ok) v.INSERT_FUN(el);\
else break;\ else break;\
}\ }\
}\ }\
\ else\
{\
ctx.mOk = false;\ ctx.mOk = false;\
}\
\ \
} while(false) } while(false)
@ -351,8 +355,10 @@ struct RsTypeSerializer
else break; else break;
} }
} }
else
{
ctx.mOk = false; ctx.mOk = false;
}
break; break;
} }
default: default:
@ -479,10 +485,12 @@ struct RsTypeSerializer
case RsGenericSerializer::PRINT: case RsGenericSerializer::PRINT:
{ {
if(v.empty()) if(v.empty())
std::cerr << " Empty array"<< std::endl; std::cerr << " Empty vector \"" << memberName << "\""
else
std::cerr << " Array of " << v.size() << " elements:"
<< std::endl; << std::endl;
else
std::cerr << " Vector of " << v.size() << " elements: \""
<< memberName << "\"" << std::endl;
for(uint32_t i=0;i<v.size();++i) for(uint32_t i=0;i<v.size();++i)
{ {
std::cerr << " " ; std::cerr << " " ;
@ -541,9 +549,12 @@ struct RsTypeSerializer
} }
case RsGenericSerializer::PRINT: case RsGenericSerializer::PRINT:
{ {
if(v.empty()) std::cerr << " Empty set"<< std::endl; if(v.empty())
else std::cerr << " Set of " << v.size() << " elements:" std::cerr << " Empty set \"" << memberName << "\""
<< std::endl; << std::endl;
else
std::cerr << " Set of " << v.size() << " elements: \""
<< memberName << "\"" << std::endl;
break; break;
} }
case RsGenericSerializer::TO_JSON: case RsGenericSerializer::TO_JSON:
@ -594,9 +605,12 @@ struct RsTypeSerializer
} }
case RsGenericSerializer::PRINT: case RsGenericSerializer::PRINT:
{ {
if(v.empty()) std::cerr << " Empty list"<< std::endl; if(v.empty())
else std::cerr << " List of " << v.size() << " elements:" std::cerr << " Empty list \"" << memberName << "\""
<< std::endl; << std::endl;
else
std::cerr << " List of " << v.size() << " elements: \""
<< memberName << "\"" << std::endl;
break; break;
} }
case RsGenericSerializer::TO_JSON: case RsGenericSerializer::TO_JSON: