MCPcopy Create free account
hub / github.com/ElementsProject/elements / read

Method read

src/univalue/lib/univalue_read.cpp:259–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257#define clearExpect(bit) (expectMask &= ~EXP_##bit)
258
259bool UniValue::read(const char *raw, size_t size)
260{
261 clear();
262
263 uint32_t expectMask = 0;
264 std::vector<UniValue*> stack;
265
266 std::string tokenVal;
267 unsigned int consumed;
268 enum jtokentype tok = JTOK_NONE;
269 enum jtokentype last_tok = JTOK_NONE;
270 const char* end = raw + size;
271 do {
272 last_tok = tok;
273
274 tok = getJsonToken(tokenVal, consumed, raw, end);
275 if (tok == JTOK_NONE || tok == JTOK_ERR)
276 return false;
277 raw += consumed;
278
279 bool isValueOpen = jsonTokenIsValue(tok) ||
280 tok == JTOK_OBJ_OPEN || tok == JTOK_ARR_OPEN;
281
282 if (expect(VALUE)) {
283 if (!isValueOpen)
284 return false;
285 clearExpect(VALUE);
286
287 } else if (expect(ARR_VALUE)) {
288 bool isArrValue = isValueOpen || (tok == JTOK_ARR_CLOSE);
289 if (!isArrValue)
290 return false;
291
292 clearExpect(ARR_VALUE);
293
294 } else if (expect(OBJ_NAME)) {
295 bool isObjName = (tok == JTOK_OBJ_CLOSE || tok == JTOK_STRING);
296 if (!isObjName)
297 return false;
298
299 } else if (expect(COLON)) {
300 if (tok != JTOK_COLON)
301 return false;
302 clearExpect(COLON);
303
304 } else if (!expect(COLON) && (tok == JTOK_COLON)) {
305 return false;
306 }
307
308 if (expect(NOT_VALUE)) {
309 if (isValueOpen)
310 return false;
311 clearExpect(NOT_VALUE);
312 }
313
314 switch (tok) {
315
316 case JTOK_OBJ_OPEN:

Callers 7

mainFunction · 0.45
runtestFunction · 0.45
unescape_unicode_testFunction · 0.45
BOOST_AUTO_TEST_CASEFunction · 0.45
mainFunction · 0.45
ReadSettingsFunction · 0.45
RunCommandParseJSONFunction · 0.45

Calls 9

clearFunction · 0.85
getJsonTokenFunction · 0.85
jsonTokenIsValueFunction · 0.85
getTypeMethod · 0.80
setBoolMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45
pop_backMethod · 0.45
emptyMethod · 0.45

Tested by 5

mainFunction · 0.36
runtestFunction · 0.36
unescape_unicode_testFunction · 0.36
BOOST_AUTO_TEST_CASEFunction · 0.36
mainFunction · 0.36