Many serialization and related stuff improvements

Fix bug in array-like containers serialization which could cause almost infinite
  loop on malformed input
Implement VLQ integer serialization
Unify sequence containers serialization code
Add support for VLQ serialization also for string size
Use VLQ compression for file links
Add templated function to fix endiannes for all integer types
Use bitset to print flags in binary form
Unify serialization code for integral types
Serialize 64bit integers types to JSON object with both string and integer
  representation, so it is posible to have this representation also for
  containers types like std::vetor or std::map this breaks retrocompatibility
  but is necessary to support clients written in languages which doesn't have
  64 bit integers support such as JavaScript or Dart
This commit is contained in:
Gioacchino Mazzurco 2020-03-16 16:20:06 +01:00
parent d203f31d0c
commit 39bde58c29
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
9 changed files with 985 additions and 752 deletions

View file

@ -3,7 +3,9 @@
* *
* libretroshare: retroshare core library *
* *
* Copyright 2018 by Retroshare Team <retroshare.project@gmail.com> *
* Copyright (C) 2018 Retroshare Team <contact@retroshare.cc> *
* Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org> *
* Copyright (C) 2020 Asociación Civil Altermundi <info@altermundi.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -58,7 +60,8 @@ RsFileTree::fromBase64(const std::string& base64)
if( (ec = RsBase64::decode(base64, mem)) ) return failure(ec);
RsGenericSerializer::SerializeContext ctx(
mem.data(), static_cast<uint32_t>(mem.size()) );
mem.data(), static_cast<uint32_t>(mem.size()),
SerializationFlags::fromEFT(RsSerializationFlags::INTEGER_VLQ) );
std::unique_ptr<RsFileTree> ft(new RsFileTree);
ft->serial_process(
RsGenericSerializer::SerializeJob::DESERIALIZE, ctx);
@ -70,6 +73,7 @@ RsFileTree::fromBase64(const std::string& base64)
std::string RsFileTree::toBase64() const
{
RsGenericSerializer::SerializeContext ctx;
ctx.mFlags = SerializationFlags::fromEFT(RsSerializationFlags::INTEGER_VLQ);
RsFileTree* ncThis = const_cast<RsFileTree*>(this);
ncThis->serial_process(
RsGenericSerializer::SerializeJob::SIZE_ESTIMATE, ctx );