File: iterate_object.cpp

package info (click to toggle)
simdjson 4.3.1-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 31,396 kB
  • sloc: cpp: 195,760; ansic: 20,954; sh: 1,126; python: 885; makefile: 47; ruby: 25; javascript: 13
file content (34 lines) | stat: -rw-r--r-- 934 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#include <iostream>
#include "simdjson.h"

using namespace simdjson;

int main() {
    auto json = "{\"a\":1}"_padded;
    ondemand::parser parser;
    auto f = [](ondemand::parser& p, simdjson::padded_string& jsons) -> ondemand::document {
        ondemand::document doc;
        auto error = p.iterate(jsons).get(doc);
        if(error) { std::abort(); }
        return doc;
    };
    ondemand::object objv;
#if COMPILATION_TEST_USE_FAILING_CODE
    // Not allowed as this would be unsafe, the document must remain alive.
    auto error = f(parser).get_object().get(objv);
#else
    ondemand::document doc = f(parser, json);
    auto error = doc.get_object().get(objv);
#endif
    if(error) {
        std::cout << "Failure" << std::endl;
    }
    int64_t a = 0;
    error = objv["a"].get_int64().get(a);
    if(error) {
        std::cout << "failure" << std::endl;
    }
    printf("a = %d\n", (int)a);
    return EXIT_SUCCESS;
}