File: rapidjson_sax.h

package info (click to toggle)
simdjson 4.3.1-5
  • 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 (69 lines) | stat: -rw-r--r-- 2,199 bytes parent folder | download | duplicates (8)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once

#ifdef SIMDJSON_COMPETITION_RAPIDJSON

#include "large_random.h"

namespace large_random {

using namespace rapidjson;

struct rapidjson_sax {
    static constexpr diff_flags DiffFlags = diff_flags::NONE;

    struct Handler {
        size_t k{0};
        double buffer[3];
        std::vector<point>& result;

        Handler(std::vector<point> &r) : result(r) { }

        bool Key(const char* key, SizeType length, bool copy) {
            switch(key[0]) {
            case 'x':
                k = 0;
                break;
            case 'y':
                k = 1;
                break;
            case 'z':
                k = 2;
                break;
            }
            return true;
        }
        bool Double(double d) {
            buffer[k] = d;
            if (k == 2) {
                result.emplace_back(json_benchmark::point{buffer[0],buffer[1],buffer[2]});
                k = 0;
            }
            return true;
        }
        bool Uint(unsigned i) { return Double(i); }   // Need this event because coordinate value can be equal to 1
        // Irrelevant events
        bool Null() { return true; }
        bool Bool(bool b) { return true; }
        bool Int(int i) { return true; }
        bool Int64(int64_t i) { return true; }
        bool Uint64(uint64_t i) { return true; }
        bool RawNumber(const char* str, SizeType length, bool copy) { return true; }
        bool String(const char* str, SizeType length, bool copy) { return true; }
        bool StartObject() { return true; }
        bool EndObject(SizeType memberCount) { return true; }
        bool StartArray() { return true; }
        bool EndArray(SizeType elementCount) { return true; }
    }; // handler

    bool run(simdjson::padded_string &json, std::vector<point> &result) {
        Reader reader;
        Handler handler(result);
        InsituStringStream ss(json.data());
        reader.Parse<kParseInsituFlag | kParseValidateEncodingFlag | kParseFullPrecisionFlag>(ss,handler);
        return true;
    }
}; // rapid_jason_sax
BENCHMARK_TEMPLATE(large_random, rapidjson_sax)->UseManualTime();
} // namespace large_random

#endif // SIMDJSON_COMPETITION_RAPIDJSON