Add more consistency checks to serialization code

As suggested by Cyril
This commit is contained in:
Gioacchino Mazzurco 2018-08-28 15:20:41 +02:00
parent 3094146c13
commit dd55ddea95
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
2 changed files with 30 additions and 5 deletions

View File

@ -26,6 +26,7 @@
#include "util/rsprint.h"
#include "serialiser/rsserializer.h"
#include "serialiser/rstypeserializer.h"
#include "util/stacktrace.h"
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_NONE ( 0x0000 );
const SerializationFlags RsGenericSerializer::SERIALIZATION_FLAG_CONFIG ( 0x0001 );
@ -241,3 +242,31 @@ RsItem *RsRawSerialiser::deserialise(void *data, uint32_t *pktsize)
return item;
}
RsGenericSerializer::SerializeContext::SerializeContext(
uint8_t* data, uint32_t size, SerializationFlags flags,
RsJson::AllocatorType* allocator ) :
mData(data), mSize(size), mOffset(0), mOk(true), mFlags(flags),
mJson(rapidjson::kObjectType, allocator)
{
if(data)
{
if(size == 0)
{
std::cerr << __PRETTY_FUNCTION__ << " data passed without "
<< "size! This make no sense report to developers!"
<< std::endl;
print_stacktrace();
}
if(flags & SERIALIZATION_FLAG_YIELDING)
{
std::cerr << __PRETTY_FUNCTION__ << " Attempt to create a "
<< "binary serialization context with "
<< "SERIALIZATION_FLAG_YIELDING! "
<< "This make no sense report to developers!"
<< std::endl;
print_stacktrace();
}
}
}

View File

@ -159,8 +159,6 @@
struct RsItem;
#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : "
// This is the base class for serializers.
class RsSerialType
@ -222,9 +220,7 @@ struct RsGenericSerializer : RsSerialType
SerializeContext(
uint8_t* data = nullptr, uint32_t size = 0,
SerializationFlags flags = SERIALIZATION_FLAG_NONE,
RsJson::AllocatorType* allocator = nullptr) :
mData(data), mSize(size), mOffset(0), mOk(true), mFlags(flags),
mJson(rapidjson::kObjectType, allocator) {}
RsJson::AllocatorType* allocator = nullptr);
RS_DEPRECATED SerializeContext(
uint8_t *data, uint32_t size, SerializationFormat format,