4#include "extern/cjson/cJSON.h"
5#include "helpers/client_helper.h"
6#include "helpers/reflection_helper.h"
7#include "IoTeXResultCodes.h"
17 const reflection::CppType type;
18 const IotexString name;
20 JsonProp(reflection::CppType type, IotexString name) :
21 type(type), name(name), _initialized(
false)
28 _initialized = orig._initialized;
29 _bytesCount = orig._bytesCount;
32 _value.object = orig._value.object;
33 orig._value.object =
nullptr;
38 void setValue(
const char* value)
40 if(_initialized && type == reflection::CppType::C_STRING)
42 free(_value.c_string);
44 _value.c_string = (
char*)malloc(strlen(value));
45 memcpy(_value.c_string, value, strlen(value));
49 void setValue(
const IotexString& value)
51 if(_initialized && type == reflection::CppType::STRING)
55 _value.string =
new IotexString(value);
59 void setValue(uint64_t value)
62 _value.uint64 = value;
65 void setValue(
bool value)
68 _value.boolean = value;
72 const char* getValueCString()
74 return _initialized ? _value.c_string :
nullptr;
77 const IotexString* getValueString()
79 return _initialized ? _value.string :
nullptr;
82 uint64_t getValueUint64()
89 return _value.boolean;
92 const uint8_t* getValueBytes()
99 if(_initialized && isHeapAllocated())
105 uint32_t getBytesCount()
110 void ToString(IotexString& out,
bool enclose =
false)
116 out +=
"\"" + name +
"\":";
118 appendValueToString(out);
138 uint32_t _bytesCount;
140 bool isHeapAllocated()
142 if(type == reflection::CppType::C_STRING || type == reflection::CppType::STRING ||
143 type == reflection::CppType::OBJECT || type == reflection::CppType::BYTES)
151 virtual void appendValueToString(IotexString& out)
171 const IotexString* getValue()
173 return _value.string;
177 void appendValueToString(IotexString& out)
override
180 out += _value.string->c_str();
201 void appendValueToString(IotexString& out)
override
204 sprintf(buf,
"%u", _value.uint8);
221 return _value.uint64;
225 void appendValueToString(IotexString& out)
override
228 sprintf(buf,
"%lu", _value.uint64);
239 const uint8_t* getValue()
257 return _value.boolean;
261 void appendValueToString(IotexString& out)
263 out += _value.boolean ?
"true" :
"false";
274iotex::ResultCode SetValueFromJsonObject(
const cJSON* json, reflection::CppType type,
void* pData,
275 size_t max_size = 0);
Definition: json_helper.h:268
Definition: json_helper.h:246
Definition: json_helper.h:234
Definition: json_helper.h:16
Definition: json_helper.h:162
Definition: json_helper.h:210
Definition: json_helper.h:186