mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Add more consistency checks to serialization code
As suggested by Cyril
This commit is contained in:
parent
3094146c13
commit
dd55ddea95
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user