15#include "nlohmann/json.hpp"
18#include <boost/endian/conversion.hpp>
37 void Read(
unsigned char*& source, uint8_t& value)
39 memcpy(&value, source, 1);
42 void Write(
unsigned char*& destination, uint8_t& value)
44 memcpy(destination, &value, 1);
48 void Read(
unsigned char*& source, int32_t& value)
50 memcpy(&value, source, 4);
51 boost::endian::little_to_native_inplace(value);
54 void Write(
unsigned char*& destination, int32_t& value)
56 boost::endian::native_to_little_inplace(value);
57 memcpy(destination, &value, 4);
61 void Read(
unsigned char*& source, uint32_t& value)
63 memcpy(&value, source, 4);
64 boost::endian::little_to_native_inplace(value);
67 void Write(
unsigned char*& destination, uint32_t& value)
69 boost::endian::native_to_little_inplace(value);
70 memcpy(destination, &value, 4);
74 void Read(
unsigned char*& source,
double& value)
76 memcpy(&value, source, 8);
79 void Write(
unsigned char*& destination,
double& value)
81 memcpy(destination, &value, 8);
85 void Read(
unsigned char*& source,
string& value)
87 value.assign((
char*)source);
88 source += value.length() + 1;
90 void Write(
unsigned char*& destination,
string& value)
92 memcpy(destination, value.c_str(), value.length() + 1);
93 destination += value.length() + 1;
96 void Read(
unsigned char*& source,
unsigned char*& value, uint64_t& size)
98 memcpy(&size, source, 8);
99 boost::endian::little_to_native_inplace(size);
101 value =
new unsigned char[size];
102 memcpy(value, source, size);
105 void Write(
unsigned char*& destination,
unsigned char* value, uint64_t size)
108 uint64_t size_little = boost::endian::native_to_little(size);
109 memcpy(destination, &size_little, 8);
111 memcpy(destination, value, size);
114 cout <<
"ERROR: count of bytes for the value should be greater than zero. The value was not written to the "
119 void Read(
unsigned char*& source,
double* value,
const uint64_t count)
121 memcpy(value, source, count * 8);
124 void Write(
unsigned char*& destination,
double* value,
const uint64_t count)
126 memcpy(destination, value, count * 8);
127 destination += count * 8;
130 template<
size_t rows,
size_t cols>
131 void Read(
unsigned char*& source,
double (&value)[rows][cols])
133 memcpy(value, source, rows * cols * 8);
134 source += rows * cols * 8;
136 template<
size_t rows,
size_t cols>
137 void Write(
unsigned char*& destination,
double (&value)[rows][cols])
139 memcpy(destination, value, rows * cols * 8);
140 destination += rows * cols * 8;
143 void Read(
unsigned char*& source,
double*** value, uint8_t& size1, uint8_t& size2, uint8_t& size3)
145 memcpy(&size1, source, 1);
146 boost::endian::little_to_native_inplace(size1);
148 memcpy(&size2, source, 1);
149 boost::endian::little_to_native_inplace(size2);
151 memcpy(&size3, source, 1);
152 boost::endian::little_to_native_inplace(size3);
155 value =
new double**[size1];
156 for (
int i = 0;
i < size1;
i++) {
157 value[
i] =
new double*[size2];
158 for (
int j = 0; j < size2; j++)
159 value[
i][j] =
new double[size3];
161 uint32_t full_size = size1 * size2 * size3 * 8;
162 memcpy(value, source, full_size);
165 void Write(
unsigned char*& destination,
double*** value, uint8_t size1, uint8_t size2, uint8_t size3)
167 uint32_t full_size = size1 * size2 * size3 * 8;
169 uint8_t size1_little = boost::endian::native_to_little(size1);
170 memcpy(destination, &size1_little, 1);
172 uint8_t size2_little = boost::endian::native_to_little(size2);
173 memcpy(destination, &size2_little, 1);
175 uint8_t size3_little = boost::endian::native_to_little(size3);
176 memcpy(destination, &size3_little, 1);
179 memcpy(destination, value, full_size);
180 destination += full_size;
182 cout <<
"ERROR: count of bytes for the value should be greater than zero. The value was not written to the "
187 void Read(
unsigned char*& source, vector<double>& value)
190 memcpy(&size, source, 8);
191 boost::endian::little_to_native_inplace(size);
193 value.assign((
double*)source, (
double*)(source + size));
196 void Write(
unsigned char*& destination, vector<double>& value)
198 uint64_t size = value.size() * 8;
200 uint64_t size_little = boost::endian::native_to_little(size);
201 memcpy(destination, &size_little, 8);
203 memcpy(destination, value.data(), size);
206 cout <<
"ERROR: vector size of the value should be greater than zero. The value was not written to the "
214 memcpy(&size, source, 8);
215 boost::endian::little_to_native_inplace(size);
218 vector<uint8_t> uint8_vec((uint8_t*)source, (uint8_t*)(source + size));
225 uint64_t size = uint8_vec.size();
227 uint64_t size_little = boost::endian::native_to_little(size);
228 memcpy(destination, &size_little, 8);
230 memcpy(destination, uint8_vec.data(), size);
233 cout <<
"ERROR: json size should be greater than zero. The value was not written to the database!" << endl;
a class to store JSON values
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
basic_json<> json
default specialization
void Write(unsigned char *&destination, vector< double > &value)
void Write(unsigned char *&destination, uint8_t &value)
void Read(unsigned char *&source, uint8_t &value)
virtual enumValueType GetType()=0
void Read(unsigned char *&source, json &value)
virtual void ReadValue(unsigned char *source)=0
void Read(unsigned char *&source, double &value)
void Read(unsigned char *&source, unsigned char *&value, uint64_t &size)
void Write(unsigned char *&destination, uint32_t &value)
void Read(unsigned char *&source, string &value)
void Read(unsigned char *&source, vector< double > &value)
void Read(unsigned char *&source, double *value, const uint64_t count)
void Write(unsigned char *&destination, double ***value, uint8_t size1, uint8_t size2, uint8_t size3)
void Write(unsigned char *&destination, double *value, const uint64_t count)
virtual void WriteValue(unsigned char *destination)=0
void Read(unsigned char *&source, double(&value)[rows][cols])
void Write(unsigned char *&destination, double &value)
void Write(unsigned char *&destination, json &value)
void Write(unsigned char *&destination, unsigned char *value, uint64_t size)
virtual size_t GetStorageSize()=0
void Read(unsigned char *&source, uint32_t &value)
void Write(unsigned char *&destination, double(&value)[rows][cols])
void Read(unsigned char *&source, int32_t &value)
void Write(unsigned char *&destination, int32_t &value)
void Read(unsigned char *&source, double ***value, uint8_t &size1, uint8_t &size2, uint8_t &size3)
void Write(unsigned char *&destination, string &value)