| 14 | )"; |
| 15 | |
| 16 | int 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 |
nothing calls this directly
no test coverage detected