Electroneum
Loading...
Searching...
No Matches
epee::serialization::throwable_buffer_reader Struct Reference

#include <portable_storage_from_bin.h>

Public Member Functions

 throwable_buffer_reader (const void *ptr, size_t sz)
void read (void *target, size_t count)
void read_sec_name (std::string &sce_name)
template<class t_pod_type>
void read (t_pod_type &pod_val)
template<class t_type>
t_type read ()
template<class type_name>
storage_entry read_ae ()
storage_entry load_storage_array_entry (uint8_t type)
size_t read_varint ()
template<class t_type>
storage_entry read_se ()
storage_entry load_storage_entry ()
void read (section &sec)
void read (std::string &str)
void read (array_entry &ae)
template<>
storage_entry read_se ()
template<>
storage_entry read_se ()

Detailed Description

Definition at line 44 of file portable_storage_from_bin.h.

Constructor & Destructor Documentation

◆ throwable_buffer_reader()

epee::serialization::throwable_buffer_reader::throwable_buffer_reader ( const void * ptr,
size_t sz )
inline

Definition at line 85 of file portable_storage_from_bin.h.

86 {
87 if(!ptr)
88 throw std::runtime_error("throwable_buffer_reader: ptr==nullptr");
89 if(!sz)
90 throw std::runtime_error("throwable_buffer_reader: sz==0");
91 m_ptr = (uint8_t*)ptr;
92 m_count = sz;
93 m_recursion_count = 0;
94 }
unsigned char uint8_t
Definition stdint.h:124

Member Function Documentation

◆ load_storage_array_entry()

storage_entry epee::serialization::throwable_buffer_reader::load_storage_array_entry ( uint8_t type)
inline

Definition at line 148 of file portable_storage_from_bin.h.

149 {
151 type &= ~SERIALIZE_FLAG_ARRAY;
152 switch(type)
153 {
163 case SERIALIZE_TYPE_BOOL: return read_ae<bool>();
167 default:
168 CHECK_AND_ASSERT_THROW_MES(false, "unknown entry_type code = " << type);
169 }
170 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
#define SERIALIZE_TYPE_UINT32
#define SERIALIZE_TYPE_INT32
#define SERIALIZE_TYPE_DUOBLE
#define SERIALIZE_TYPE_UINT8
#define SERIALIZE_TYPE_UINT16
#define SERIALIZE_TYPE_INT64
#define SERIALIZE_TYPE_UINT64
#define SERIALIZE_TYPE_INT8
#define SERIALIZE_TYPE_STRING
#define SERIALIZE_TYPE_INT16
#define SERIALIZE_TYPE_OBJECT
#define SERIALIZE_TYPE_ARRAY
#define SERIALIZE_TYPE_BOOL
#define RECURSION_LIMITATION()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_storage_entry()

storage_entry epee::serialization::throwable_buffer_reader::load_storage_entry ( )
inline

Definition at line 231 of file portable_storage_from_bin.h.

232 {
234 uint8_t ent_type = 0;
235 read(ent_type);
236 if(ent_type&SERIALIZE_FLAG_ARRAY)
237 return load_storage_array_entry(ent_type);
238
239 switch(ent_type)
240 {
250 case SERIALIZE_TYPE_BOOL: return read_se<bool>();
254 default:
255 CHECK_AND_ASSERT_THROW_MES(false, "unknown entry_type code = " << ent_type);
256 }
257 }
storage_entry throwable_buffer_reader::read_se< std::string >()
#define SERIALIZE_FLAG_ARRAY
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read() [1/6]

template<class t_type>
t_type epee::serialization::throwable_buffer_reader::read ( )

Definition at line 123 of file portable_storage_from_bin.h.

124 {
126 t_type v;
127 read(v);
128 return v;
129 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read() [2/6]

void epee::serialization::throwable_buffer_reader::read ( array_entry & ae)
inline

Definition at line 285 of file portable_storage_from_bin.h.

286 {
288 CHECK_AND_ASSERT_THROW_MES(false, "Reading array entry is not supported");
289 }

◆ read() [3/6]

void epee::serialization::throwable_buffer_reader::read ( section & sec)
inline

Definition at line 259 of file portable_storage_from_bin.h.

260 {
262 sec.m_entries.clear();
263 size_t count = read_varint();
264 while(count--)
265 {
266 //read section name string
267 std::string sec_name;
268 read_sec_name(sec_name);
269 sec.m_entries.insert(std::make_pair(sec_name, load_storage_entry()));
270 }
271 }
mdb_size_t count(MDB_cursor *cur)
Here is the call graph for this function:

◆ read() [4/6]

void epee::serialization::throwable_buffer_reader::read ( std::string & str)
inline

Definition at line 273 of file portable_storage_from_bin.h.

274 {
276 size_t len = read_varint();
277 CHECK_AND_ASSERT_THROW_MES(len < MAX_STRING_LEN_POSSIBLE, "to big string len value in storage: " << len);
278 CHECK_AND_ASSERT_THROW_MES(m_count >= len, "string len count value " << len << " goes out of remain storage len " << m_count);
279 //do this manually to avoid double memory write in huge strings (first time at resize, second at read)
280 str.assign((const char*)m_ptr, len);
281 m_ptr+=len;
282 m_count -= len;
283 }
#define MAX_STRING_LEN_POSSIBLE
Here is the call graph for this function:

◆ read() [5/6]

template<class t_pod_type>
void epee::serialization::throwable_buffer_reader::read ( t_pod_type & pod_val)

Definition at line 115 of file portable_storage_from_bin.h.

116 {
118 static_assert(std::is_pod<t_pod_type>::value, "POD type expected");
119 read(&pod_val, sizeof(pod_val));
120 }
Here is the call graph for this function:

◆ read() [6/6]

void epee::serialization::throwable_buffer_reader::read ( void * target,
size_t count )
inline

Definition at line 96 of file portable_storage_from_bin.h.

97 {
99 CHECK_AND_ASSERT_THROW_MES(m_count >= count, " attempt to read " << count << " bytes from buffer with " << m_count << " bytes remained");
100 memcpy(target, m_ptr, count);
101 m_ptr += count;
102 m_count -= count;
103 }
void * memcpy(void *a, const void *b, size_t c)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_ae()

template<class type_name>
storage_entry epee::serialization::throwable_buffer_reader::read_ae ( )

Definition at line 133 of file portable_storage_from_bin.h.

134 {
136 //for pod types
137 array_entry_t<type_name> sa;
138 size_t size = read_varint();
139 CHECK_AND_ASSERT_THROW_MES(size <= m_count, "Size sanity check failed");
140 sa.reserve(size);
141 //TODO: add some optimization here later
142 while(size--)
143 sa.m_array.push_back(read<type_name>());
144 return storage_entry(array_entry(sa));
145 }
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
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_se() [1/3]

template<>
storage_entry epee::serialization::throwable_buffer_reader::read_se ( )
inline

Definition at line 221 of file portable_storage_from_bin.h.

222 {
224 uint8_t ent_type = 0;
225 read(ent_type);
226 CHECK_AND_ASSERT_THROW_MES(ent_type&SERIALIZE_FLAG_ARRAY, "wrong type sequenses");
227 return load_storage_array_entry(ent_type);
228 }
Here is the call graph for this function:

◆ read_se() [2/3]

template<>
storage_entry epee::serialization::throwable_buffer_reader::read_se ( )
inline

Definition at line 210 of file portable_storage_from_bin.h.

211 {
213 section s;//use extra variable due to vs bug, line "storage_entry se(section()); " can't be compiled in visual studio
214 storage_entry se(s);
215 section& section_entry = boost::get<section>(se);
216 read(section_entry);
217 return se;
218 }
Here is the call graph for this function:

◆ read_se() [3/3]

template<class t_type>
storage_entry epee::serialization::throwable_buffer_reader::read_se ( )

Definition at line 193 of file portable_storage_from_bin.h.

194 {
196 t_type v;
197 read(v);
198 return storage_entry(v);
199 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_sec_name()

void epee::serialization::throwable_buffer_reader::read_sec_name ( std::string & sce_name)
inline

Definition at line 105 of file portable_storage_from_bin.h.

106 {
108 uint8_t name_len = 0;
109 read(name_len);
110 sce_name.resize(name_len);
111 read((void*)sce_name.data(), name_len);
112 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_varint()

size_t epee::serialization::throwable_buffer_reader::read_varint ( )
inline

Definition at line 173 of file portable_storage_from_bin.h.

174 {
176 CHECK_AND_ASSERT_THROW_MES(m_count >= 1, "empty buff, expected place for varint");
177 size_t v = 0;
178 uint8_t size_mask = (*(uint8_t*)m_ptr) &PORTABLE_RAW_SIZE_MARK_MASK;
179 switch (size_mask)
180 {
185 default:
186 CHECK_AND_ASSERT_THROW_MES(false, "unknown varint size_mask = " << size_mask);
187 }
188 v >>= 2;
189 return v;
190 }
#define PORTABLE_RAW_SIZE_MARK_WORD
#define PORTABLE_RAW_SIZE_MARK_DWORD
#define PORTABLE_RAW_SIZE_MARK_MASK
#define PORTABLE_RAW_SIZE_MARK_BYTE
#define PORTABLE_RAW_SIZE_MARK_INT64
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this struct was generated from the following file: