MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / working_with_cbor1

Function working_with_cbor1

examples/src/cbor_examples.cpp:385–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383};
384
385void working_with_cbor1()
386{
387 // Parse the CBOR data into a json value
388 json j = cbor::decode_cbor<json>(data);
389
390 // Pretty print
391 std::cout << "(1)\n" << pretty_print(j) << "\n\n";
392
393 // Iterate over rows
394 std::cout << "(2)\n";
395 for (const auto& row : j.array_range())
396 {
397 std::cout << row[1].as<jsoncons::byte_string>() << " (" << row[1].tag() << ")\n";
398 }
399 std::cout << "\n";
400
401 // Select the third column with JSONPath
402 std::cout << "(3)\n";
403 json result = jsonpath::json_query(j,"$[*][2]");
404 std::cout << pretty_print(result) << "\n\n";
405
406 // Serialize back to CBOR
407 std::vector<uint8_t> buffer;
408 cbor::encode_cbor(j, buffer);
409 std::cout << "(4)\n" << byte_string_view(buffer) << "\n\n";
410}
411
412void working_with_cbor2()
413{

Callers 1

mainFunction · 0.85

Calls 5

pretty_printFunction · 0.85
json_queryFunction · 0.85
encode_cborFunction · 0.85
byte_string_viewClass · 0.85
tagMethod · 0.45

Tested by

no test coverage detected