36#undef MONERO_DEFAULT_LOG_CATEGORY
37#define MONERO_DEFAULT_LOG_CATEGORY "serialization"
39#ifdef EPEE_PORTABLE_STORAGE_RECURSION_LIMIT
40#define EPEE_PORTABLE_STORAGE_RECURSION_LIMIT_INTERNAL EPEE_PORTABLE_STORAGE_RECURSION_LIMIT
42#define EPEE_PORTABLE_STORAGE_RECURSION_LIMIT_INTERNAL 100
51 static constexpr const size_t strict = 4096;
70 void read(
void* target,
size_t count);
72 template<
class t_pod_type>
73 void read(t_pod_type& pod_val);
74 template<
class t_type>
76 template<
class type_name>
80 template<
class t_type>
86 template<
class t_type>
88 void set_limits(
size_t objects,
size_t fields,
size_t strings);
100 CHECK_AND_ASSERT_THROW_MES(
m_counter_ref != 0,
"Internal error: m_counter_ref == 0 while ~recursuion_limitation_guard()");
104#define RECURSION_LIMITATION() recursuion_limitation_guard rl(m_recursion_count)
121 throw std::runtime_error(
"throwable_buffer_reader: ptr==nullptr");
123 throw std::runtime_error(
"throwable_buffer_reader: sz==0");
131 max_fields = std::numeric_limits<size_t>::max();
138 CHECK_AND_ASSERT_THROW_MES(
m_count >= count,
" attempt to read " << count <<
" bytes from buffer with " <<
m_count <<
" bytes remained");
149 CHECK_AND_ASSERT_THROW_MES(name_len > 0,
"Section name is missing");
150 sce_name.resize(name_len);
151 read((
void*)sce_name.data(), name_len);
154 template<
class t_pod_type>
158 static_assert(std::is_pod<t_pod_type>::value,
"POD type expected");
159 read(&pod_val,
sizeof(pod_val));
167 static_assert(std::is_pod<bool>::value,
"POD type expected");
168 static_assert(
sizeof(bool) ==
sizeof(
uint8_t),
"We really shouldn't use bool directly in serialization code. Replace it with uint8_t if this assert triggers!");
171 CHECK_AND_ASSERT_THROW_MES(t <= 1,
"Invalid bool value " << t);
175 template<
class t_type>
185 template<
class type_name>
193 if (std::is_same<type_name, section>())
198 else if (std::is_same<type_name, std::string>())
232 CHECK_AND_ASSERT_THROW_MES(
false,
"unknown entry_type code = " << type);
240 CHECK_AND_ASSERT_THROW_MES(
m_count >= 1,
"empty buff, expected place for varint");
250 CHECK_AND_ASSERT_THROW_MES(
false,
"unknown varint size_mask = " << size_mask);
256 template<
class t_type>
269 CHECK_AND_ASSERT_THROW_MES(m_strings + 1 <= max_strings,
"Too many strings");
283 section& section_entry = boost::get<section>(se);
323 CHECK_AND_ASSERT_THROW_MES(
false,
"unknown entry_type code = " << ent_type);
337 std::string sec_name;
339 const auto insert_loc = sec.
m_entries.lower_bound(sec_name);
340 CHECK_AND_ASSERT_THROW_MES(insert_loc == sec.
m_entries.end() || insert_loc->first != sec_name,
"duplicate key: " << sec_name);
350 CHECK_AND_ASSERT_THROW_MES(
m_count >= len,
"string len count value " << len <<
" goes out of remain storage len " <<
m_count);
352 str.assign((
const char*)
m_ptr, len);
360 CHECK_AND_ASSERT_THROW_MES(
false,
"Reading array entry is not supported");
#define s(x, c)
Definition aesb.c:47
void * memcpy(void *a, const void *b, size_t c)
Definition glibc_compat.cpp:16
boost::variant< uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, section, array_entry > storage_entry
Definition portable_storage_base.h:161
storage_entry throwable_buffer_reader::read_se< std::string >()
Definition portable_storage_from_bin.h:266
boost::make_recursive_variant< array_entry_t< section >, array_entry_t< uint64_t >, array_entry_t< uint32_t >, array_entry_t< uint16_t >, array_entry_t< uint8_t >, array_entry_t< int64_t >, array_entry_t< int32_t >, array_entry_t< int16_t >, array_entry_t< int8_t >, array_entry_t< double >, array_entry_t< bool >, array_entry_t< std::string >, array_entry_t< section >, array_entry_t< boost::recursive_variant_ > >::type array_entry
Definition portable_storage_base.h:159
TODO: (mj-xmr) This will be reduced in an another PR.
Definition byte_slice.h:40
Definition binary_utils.h:36
#define PORTABLE_RAW_SIZE_MARK_WORD
Definition portable_storage_base.h:43
#define SERIALIZE_FLAG_ARRAY
Definition portable_storage_base.h:66
#define PORTABLE_RAW_SIZE_MARK_DWORD
Definition portable_storage_base.h:44
#define SERIALIZE_TYPE_UINT32
Definition portable_storage_base.h:57
#define SERIALIZE_TYPE_INT32
Definition portable_storage_base.h:53
#define MAX_STRING_LEN_POSSIBLE
Definition portable_storage_base.h:48
#define SERIALIZE_TYPE_UINT8
Definition portable_storage_base.h:59
#define PORTABLE_RAW_SIZE_MARK_MASK
Definition portable_storage_base.h:41
#define SERIALIZE_TYPE_UINT16
Definition portable_storage_base.h:58
#define PORTABLE_RAW_SIZE_MARK_BYTE
Definition portable_storage_base.h:42
#define PORTABLE_RAW_SIZE_MARK_INT64
Definition portable_storage_base.h:45
#define SERIALIZE_TYPE_INT64
Definition portable_storage_base.h:52
#define SERIALIZE_TYPE_UINT64
Definition portable_storage_base.h:56
#define SERIALIZE_TYPE_INT8
Definition portable_storage_base.h:55
#define SERIALIZE_TYPE_DOUBLE
Definition portable_storage_base.h:60
#define SERIALIZE_TYPE_STRING
Definition portable_storage_base.h:61
#define SERIALIZE_TYPE_INT16
Definition portable_storage_base.h:54
#define SERIALIZE_TYPE_OBJECT
Definition portable_storage_base.h:63
#define SERIALIZE_TYPE_ARRAY
Definition portable_storage_base.h:64
#define SERIALIZE_TYPE_BOOL
Definition portable_storage_base.h:62
#define CONVERT_POD(x)
Definition portable_storage_bin_utils.h:43
#define EPEE_PORTABLE_STORAGE_RECURSION_LIMIT_INTERNAL
Definition portable_storage_from_bin.h:42
#define RECURSION_LIMITATION()
Definition portable_storage_from_bin.h:104
const char *const str
Definition portlistingparse.c:23
signed short int16_t
Definition stdint.h:122
unsigned short uint16_t
Definition stdint.h:125
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
signed int int32_t
Definition stdint.h:123
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
signed char int8_t
Definition stdint.h:121
Definition portable_storage_base.h:83
void reserve(size_t n)
Definition portable_storage_base.h:134
entry_container< t_entry_type >::type m_array
Definition portable_storage_base.h:139
static constexpr const size_t strict
Definition portable_storage_from_bin.h:65
static constexpr const size_t strict
Definition portable_storage_from_bin.h:62
static constexpr const size_t strict
Definition portable_storage_from_bin.h:61
static constexpr const size_t strict
Definition portable_storage_from_bin.h:58
static constexpr const size_t strict
Definition portable_storage_from_bin.h:56
static constexpr const size_t strict
Definition portable_storage_from_bin.h:54
static constexpr const size_t strict
Definition portable_storage_from_bin.h:60
static constexpr const size_t strict
Definition portable_storage_from_bin.h:64
static constexpr const size_t strict
Definition portable_storage_from_bin.h:63
static constexpr const size_t strict
Definition portable_storage_from_bin.h:57
static constexpr const size_t strict
Definition portable_storage_from_bin.h:55
static constexpr const size_t strict
Definition portable_storage_from_bin.h:53
static constexpr const size_t strict
Definition portable_storage_from_bin.h:59
Definition portable_storage_from_bin.h:50
static constexpr const size_t strict
Definition portable_storage_from_bin.h:51
Definition portable_storage_base.h:169
std::map< std::string, storage_entry > m_entries
Definition portable_storage_base.h:170
recursuion_limitation_guard(size_t &counter)
Definition portable_storage_from_bin.h:93
~recursuion_limitation_guard() noexcept(false)
Definition portable_storage_from_bin.h:98
size_t & m_counter_ref
Definition portable_storage_from_bin.h:92
size_t read_varint()
Definition portable_storage_from_bin.h:237
size_t max_strings
Definition portable_storage_from_bin.h:115
storage_entry read_se()
Definition portable_storage_from_bin.h:257
t_type read()
Definition portable_storage_from_bin.h:176
void read_sec_name(std::string &sce_name)
Definition portable_storage_from_bin.h:144
const uint8_t * m_ptr
Definition portable_storage_from_bin.h:106
size_t m_count
Definition portable_storage_from_bin.h:107
size_t max_objects
Definition portable_storage_from_bin.h:113
storage_entry read_ae()
Definition portable_storage_from_bin.h:186
storage_entry load_storage_array_entry(uint8_t type)
Definition portable_storage_from_bin.h:212
throwable_buffer_reader(const void *ptr, size_t sz)
Definition portable_storage_from_bin.h:118
size_t m_strings
Definition portable_storage_from_bin.h:111
size_t m_fields
Definition portable_storage_from_bin.h:110
size_t m_recursion_count
Definition portable_storage_from_bin.h:108
storage_entry load_storage_entry()
Definition portable_storage_from_bin.h:299
void set_limits(size_t objects, size_t fields, size_t strings)
Definition portable_storage_from_bin.h:363
size_t m_objects
Definition portable_storage_from_bin.h:109
size_t max_fields
Definition portable_storage_from_bin.h:114
void read(void *target, size_t count)
Definition portable_storage_from_bin.h:135