MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / main

Function main

example/parse_ondemand.cpp:16–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14)";
15
16int main() {
17 // The target is exsited in JSON
18 {
19 sonic_json::Document doc;
20 doc.ParseOnDemand(json, {"a", "a0", 8});
21 if (doc.HasParseError()) {
22 return -1;
23 }
24 uint64_t val = doc.GetUint64();
25 std::cout << "Parse ondemand result is " << val << std::endl;
26 // output: Parse ondemand result is 8
27 }
28
29 // The target is not exsited in JSON
30 {
31 sonic_json::Document doc;
32 doc.ParseOnDemand(json, {"a", "a1", "unknown"});
33 if (doc.HasParseError()) {
34 sonic_json::SonicError err = doc.GetParseError();
35 size_t error_position = doc.GetErrorOffset();
36 std::cout << "Parse Error: " << sonic_json::ErrorMsg(err)
37 << ". Error Position At " << error_position << std::endl;
38 // output: Parse Error: ParseOnDemand: the target type is not matched..
39 // Error Position At 55
40 }
41 }
42 return 0;
43}
44// g++ -I../include/ -march=haswell --std=c++11 parseondemand.cpp -o
45// parseondemand

Callers

nothing calls this directly

Calls 4

ErrorMsgFunction · 0.85
HasParseErrorMethod · 0.80
GetParseErrorMethod · 0.80
GetErrorOffsetMethod · 0.80

Tested by

no test coverage detected