simdjson 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.clang-format +5 -0
- data/.gitignore +14 -0
- data/.gitmodules +3 -0
- data/.rubocop.yml +9 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +32 -0
- data/benchmark/apache_builds.json +4421 -0
- data/benchmark/demo.json +15 -0
- data/benchmark/github_events.json +1390 -0
- data/benchmark/run_benchmark.rb +30 -0
- data/ext/simdjson/extconf.rb +22 -0
- data/ext/simdjson/simdjson.cpp +76 -0
- data/ext/simdjson/simdjson.hpp +6 -0
- data/lib/simdjson/version.rb +3 -0
- data/lib/simdjson.rb +2 -0
- data/simdjson.gemspec +35 -0
- data/vendor/.gitkeep +0 -0
- data/vendor/simdjson/AUTHORS +3 -0
- data/vendor/simdjson/CMakeLists.txt +63 -0
- data/vendor/simdjson/CONTRIBUTORS +27 -0
- data/vendor/simdjson/Dockerfile +10 -0
- data/vendor/simdjson/LICENSE +201 -0
- data/vendor/simdjson/Makefile +203 -0
- data/vendor/simdjson/Notes.md +85 -0
- data/vendor/simdjson/README.md +581 -0
- data/vendor/simdjson/amalgamation.sh +158 -0
- data/vendor/simdjson/benchmark/CMakeLists.txt +8 -0
- data/vendor/simdjson/benchmark/benchmark.h +223 -0
- data/vendor/simdjson/benchmark/distinctuseridcompetition.cpp +347 -0
- data/vendor/simdjson/benchmark/linux/linux-perf-events.h +93 -0
- data/vendor/simdjson/benchmark/minifiercompetition.cpp +181 -0
- data/vendor/simdjson/benchmark/parse.cpp +393 -0
- data/vendor/simdjson/benchmark/parseandstatcompetition.cpp +305 -0
- data/vendor/simdjson/benchmark/parsingcompetition.cpp +298 -0
- data/vendor/simdjson/benchmark/statisticalmodel.cpp +208 -0
- data/vendor/simdjson/dependencies/jsoncppdist/json/json-forwards.h +344 -0
- data/vendor/simdjson/dependencies/jsoncppdist/json/json.h +2366 -0
- data/vendor/simdjson/dependencies/jsoncppdist/jsoncpp.cpp +5418 -0
- data/vendor/simdjson/doc/apache_builds.jsonparseandstat.png +0 -0
- data/vendor/simdjson/doc/gbps.png +0 -0
- data/vendor/simdjson/doc/github_events.jsonparseandstat.png +0 -0
- data/vendor/simdjson/doc/twitter.jsonparseandstat.png +0 -0
- data/vendor/simdjson/doc/update-center.jsonparseandstat.png +0 -0
- data/vendor/simdjson/images/halvarflake.png +0 -0
- data/vendor/simdjson/images/logo.png +0 -0
- data/vendor/simdjson/include/simdjson/common_defs.h +102 -0
- data/vendor/simdjson/include/simdjson/isadetection.h +152 -0
- data/vendor/simdjson/include/simdjson/jsoncharutils.h +301 -0
- data/vendor/simdjson/include/simdjson/jsonformatutils.h +202 -0
- data/vendor/simdjson/include/simdjson/jsonioutil.h +32 -0
- data/vendor/simdjson/include/simdjson/jsonminifier.h +30 -0
- data/vendor/simdjson/include/simdjson/jsonparser.h +250 -0
- data/vendor/simdjson/include/simdjson/numberparsing.h +587 -0
- data/vendor/simdjson/include/simdjson/padded_string.h +70 -0
- data/vendor/simdjson/include/simdjson/parsedjson.h +544 -0
- data/vendor/simdjson/include/simdjson/portability.h +172 -0
- data/vendor/simdjson/include/simdjson/simdjson.h +44 -0
- data/vendor/simdjson/include/simdjson/simdjson_version.h +13 -0
- data/vendor/simdjson/include/simdjson/simdprune_tables.h +35074 -0
- data/vendor/simdjson/include/simdjson/simdutf8check_arm64.h +180 -0
- data/vendor/simdjson/include/simdjson/simdutf8check_haswell.h +198 -0
- data/vendor/simdjson/include/simdjson/simdutf8check_westmere.h +169 -0
- data/vendor/simdjson/include/simdjson/stage1_find_marks.h +121 -0
- data/vendor/simdjson/include/simdjson/stage1_find_marks_arm64.h +210 -0
- data/vendor/simdjson/include/simdjson/stage1_find_marks_flatten.h +93 -0
- data/vendor/simdjson/include/simdjson/stage1_find_marks_flatten_haswell.h +95 -0
- data/vendor/simdjson/include/simdjson/stage1_find_marks_haswell.h +210 -0
- data/vendor/simdjson/include/simdjson/stage1_find_marks_macros.h +239 -0
- data/vendor/simdjson/include/simdjson/stage1_find_marks_westmere.h +194 -0
- data/vendor/simdjson/include/simdjson/stage2_build_tape.h +85 -0
- data/vendor/simdjson/include/simdjson/stringparsing.h +105 -0
- data/vendor/simdjson/include/simdjson/stringparsing_arm64.h +56 -0
- data/vendor/simdjson/include/simdjson/stringparsing_haswell.h +43 -0
- data/vendor/simdjson/include/simdjson/stringparsing_macros.h +88 -0
- data/vendor/simdjson/include/simdjson/stringparsing_westmere.h +41 -0
- data/vendor/simdjson/jsonexamples/small/jsoniter_scala/README.md +4 -0
- data/vendor/simdjson/scripts/dumpsimplestats.sh +11 -0
- data/vendor/simdjson/scripts/issue150.sh +14 -0
- data/vendor/simdjson/scripts/javascript/README.md +3 -0
- data/vendor/simdjson/scripts/javascript/generatelargejson.js +19 -0
- data/vendor/simdjson/scripts/minifier.sh +11 -0
- data/vendor/simdjson/scripts/parseandstat.sh +24 -0
- data/vendor/simdjson/scripts/parser.sh +11 -0
- data/vendor/simdjson/scripts/parsingcompdata.sh +26 -0
- data/vendor/simdjson/scripts/plotparse.sh +98 -0
- data/vendor/simdjson/scripts/selectparser.sh +11 -0
- data/vendor/simdjson/scripts/setupfortesting/disablehyperthreading.sh +15 -0
- data/vendor/simdjson/scripts/setupfortesting/powerpolicy.sh +32 -0
- data/vendor/simdjson/scripts/setupfortesting/setupfortesting.sh +6 -0
- data/vendor/simdjson/scripts/setupfortesting/turboboost.sh +51 -0
- data/vendor/simdjson/scripts/testjson2json.sh +99 -0
- data/vendor/simdjson/scripts/transitions/Makefile +10 -0
- data/vendor/simdjson/scripts/transitions/generatetransitions.cpp +20 -0
- data/vendor/simdjson/singleheader/README.md +1 -0
- data/vendor/simdjson/singleheader/amalgamation_demo.cpp +20 -0
- data/vendor/simdjson/singleheader/simdjson.cpp +1652 -0
- data/vendor/simdjson/singleheader/simdjson.h +39692 -0
- data/vendor/simdjson/src/CMakeLists.txt +67 -0
- data/vendor/simdjson/src/jsonioutil.cpp +35 -0
- data/vendor/simdjson/src/jsonminifier.cpp +285 -0
- data/vendor/simdjson/src/jsonparser.cpp +91 -0
- data/vendor/simdjson/src/parsedjson.cpp +323 -0
- data/vendor/simdjson/src/parsedjsoniterator.cpp +272 -0
- data/vendor/simdjson/src/simdjson.cpp +30 -0
- data/vendor/simdjson/src/stage1_find_marks.cpp +41 -0
- data/vendor/simdjson/src/stage2_build_tape.cpp +567 -0
- data/vendor/simdjson/style/clang-format-check.sh +25 -0
- data/vendor/simdjson/style/clang-format.sh +25 -0
- data/vendor/simdjson/style/run-clang-format.py +326 -0
- data/vendor/simdjson/tape.md +134 -0
- data/vendor/simdjson/tests/CMakeLists.txt +25 -0
- data/vendor/simdjson/tests/allparserscheckfile.cpp +192 -0
- data/vendor/simdjson/tests/basictests.cpp +75 -0
- data/vendor/simdjson/tests/jsoncheck.cpp +136 -0
- data/vendor/simdjson/tests/numberparsingcheck.cpp +224 -0
- data/vendor/simdjson/tests/pointercheck.cpp +38 -0
- data/vendor/simdjson/tests/singleheadertest.cpp +22 -0
- data/vendor/simdjson/tests/stringparsingcheck.cpp +408 -0
- data/vendor/simdjson/tools/CMakeLists.txt +3 -0
- data/vendor/simdjson/tools/cmake/FindCTargets.cmake +15 -0
- data/vendor/simdjson/tools/cmake/FindOptions.cmake +52 -0
- data/vendor/simdjson/tools/json2json.cpp +112 -0
- data/vendor/simdjson/tools/jsonpointer.cpp +93 -0
- data/vendor/simdjson/tools/jsonstats.cpp +143 -0
- data/vendor/simdjson/tools/minify.cpp +21 -0
- data/vendor/simdjson/tools/release.py +125 -0
- data/vendor/simdjson/windows/dirent_portable.h +1043 -0
- metadata +273 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
#ifndef SIMDJSON_JSONFORMATUTILS_H
|
2
|
+
#define SIMDJSON_JSONFORMATUTILS_H
|
3
|
+
|
4
|
+
#include <cstdio>
|
5
|
+
#include <iomanip>
|
6
|
+
#include <iostream>
|
7
|
+
|
8
|
+
namespace simdjson {
|
9
|
+
// ends with zero char
|
10
|
+
static inline void print_with_escapes(const unsigned char *src) {
|
11
|
+
while (*src) {
|
12
|
+
switch (*src) {
|
13
|
+
case '\b':
|
14
|
+
putchar('\\');
|
15
|
+
putchar('b');
|
16
|
+
break;
|
17
|
+
case '\f':
|
18
|
+
putchar('\\');
|
19
|
+
putchar('f');
|
20
|
+
break;
|
21
|
+
case '\n':
|
22
|
+
putchar('\\');
|
23
|
+
putchar('n');
|
24
|
+
break;
|
25
|
+
case '\r':
|
26
|
+
putchar('\\');
|
27
|
+
putchar('r');
|
28
|
+
break;
|
29
|
+
case '\"':
|
30
|
+
putchar('\\');
|
31
|
+
putchar('"');
|
32
|
+
break;
|
33
|
+
case '\t':
|
34
|
+
putchar('\\');
|
35
|
+
putchar('t');
|
36
|
+
break;
|
37
|
+
case '\\':
|
38
|
+
putchar('\\');
|
39
|
+
putchar('\\');
|
40
|
+
break;
|
41
|
+
default:
|
42
|
+
if (*src <= 0x1F) {
|
43
|
+
printf("\\u%04x", *src);
|
44
|
+
} else {
|
45
|
+
putchar(*src);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
src++;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
// ends with zero char
|
53
|
+
static inline void print_with_escapes(const unsigned char *src,
|
54
|
+
std::ostream &os) {
|
55
|
+
while (*src) {
|
56
|
+
switch (*src) {
|
57
|
+
case '\b':
|
58
|
+
os << '\\';
|
59
|
+
os << 'b';
|
60
|
+
break;
|
61
|
+
case '\f':
|
62
|
+
os << '\\';
|
63
|
+
os << 'f';
|
64
|
+
break;
|
65
|
+
case '\n':
|
66
|
+
os << '\\';
|
67
|
+
os << 'n';
|
68
|
+
break;
|
69
|
+
case '\r':
|
70
|
+
os << '\\';
|
71
|
+
os << 'r';
|
72
|
+
break;
|
73
|
+
case '\"':
|
74
|
+
os << '\\';
|
75
|
+
os << '"';
|
76
|
+
break;
|
77
|
+
case '\t':
|
78
|
+
os << '\\';
|
79
|
+
os << 't';
|
80
|
+
break;
|
81
|
+
case '\\':
|
82
|
+
os << '\\';
|
83
|
+
os << '\\';
|
84
|
+
break;
|
85
|
+
default:
|
86
|
+
if (*src <= 0x1F) {
|
87
|
+
std::ios::fmtflags f(os.flags());
|
88
|
+
os << std::hex << std::setw(4) << std::setfill('0')
|
89
|
+
<< static_cast<int>(*src);
|
90
|
+
os.flags(f);
|
91
|
+
} else {
|
92
|
+
os << *src;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
src++;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
// print len chars
|
100
|
+
static inline void print_with_escapes(const unsigned char *src, size_t len) {
|
101
|
+
const unsigned char *finalsrc = src + len;
|
102
|
+
while (src < finalsrc) {
|
103
|
+
switch (*src) {
|
104
|
+
case '\b':
|
105
|
+
putchar('\\');
|
106
|
+
putchar('b');
|
107
|
+
break;
|
108
|
+
case '\f':
|
109
|
+
putchar('\\');
|
110
|
+
putchar('f');
|
111
|
+
break;
|
112
|
+
case '\n':
|
113
|
+
putchar('\\');
|
114
|
+
putchar('n');
|
115
|
+
break;
|
116
|
+
case '\r':
|
117
|
+
putchar('\\');
|
118
|
+
putchar('r');
|
119
|
+
break;
|
120
|
+
case '\"':
|
121
|
+
putchar('\\');
|
122
|
+
putchar('"');
|
123
|
+
break;
|
124
|
+
case '\t':
|
125
|
+
putchar('\\');
|
126
|
+
putchar('t');
|
127
|
+
break;
|
128
|
+
case '\\':
|
129
|
+
putchar('\\');
|
130
|
+
putchar('\\');
|
131
|
+
break;
|
132
|
+
default:
|
133
|
+
if (*src <= 0x1F) {
|
134
|
+
printf("\\u%04x", *src);
|
135
|
+
} else {
|
136
|
+
putchar(*src);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
src++;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
// print len chars
|
144
|
+
static inline void print_with_escapes(const unsigned char *src,
|
145
|
+
std::ostream &os, size_t len) {
|
146
|
+
const unsigned char *finalsrc = src + len;
|
147
|
+
while (src < finalsrc) {
|
148
|
+
switch (*src) {
|
149
|
+
case '\b':
|
150
|
+
os << '\\';
|
151
|
+
os << 'b';
|
152
|
+
break;
|
153
|
+
case '\f':
|
154
|
+
os << '\\';
|
155
|
+
os << 'f';
|
156
|
+
break;
|
157
|
+
case '\n':
|
158
|
+
os << '\\';
|
159
|
+
os << 'n';
|
160
|
+
break;
|
161
|
+
case '\r':
|
162
|
+
os << '\\';
|
163
|
+
os << 'r';
|
164
|
+
break;
|
165
|
+
case '\"':
|
166
|
+
os << '\\';
|
167
|
+
os << '"';
|
168
|
+
break;
|
169
|
+
case '\t':
|
170
|
+
os << '\\';
|
171
|
+
os << 't';
|
172
|
+
break;
|
173
|
+
case '\\':
|
174
|
+
os << '\\';
|
175
|
+
os << '\\';
|
176
|
+
break;
|
177
|
+
default:
|
178
|
+
if (*src <= 0x1F) {
|
179
|
+
std::ios::fmtflags f(os.flags());
|
180
|
+
os << std::hex << std::setw(4) << std::setfill('0')
|
181
|
+
<< static_cast<int>(*src);
|
182
|
+
os.flags(f);
|
183
|
+
} else {
|
184
|
+
os << *src;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
src++;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
static inline void print_with_escapes(const char *src, std::ostream &os) {
|
192
|
+
print_with_escapes(reinterpret_cast<const unsigned char *>(src), os);
|
193
|
+
}
|
194
|
+
|
195
|
+
static inline void print_with_escapes(const char *src, std::ostream &os,
|
196
|
+
size_t len) {
|
197
|
+
print_with_escapes(reinterpret_cast<const unsigned char *>(src), os, len);
|
198
|
+
}
|
199
|
+
} // namespace simdjson
|
200
|
+
|
201
|
+
#
|
202
|
+
#endif
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef SIMDJSON_JSONIOUTIL_H
|
2
|
+
#define SIMDJSON_JSONIOUTIL_H
|
3
|
+
|
4
|
+
#include "simdjson/common_defs.h"
|
5
|
+
#include <exception>
|
6
|
+
#include <fstream>
|
7
|
+
#include <iostream>
|
8
|
+
#include <sstream>
|
9
|
+
#include <string>
|
10
|
+
|
11
|
+
#include "simdjson/padded_string.h"
|
12
|
+
|
13
|
+
namespace simdjson {
|
14
|
+
|
15
|
+
// load a file in memory...
|
16
|
+
// get a corpus; pad out to cache line so we can always use SIMD
|
17
|
+
// throws exceptions in case of failure
|
18
|
+
// first element of the pair is a string (null terminated)
|
19
|
+
// whereas the second element is the length.
|
20
|
+
// caller is responsible to free (aligned_free((void*)result.data())))
|
21
|
+
//
|
22
|
+
// throws an exception if the file cannot be opened, use try/catch
|
23
|
+
// try {
|
24
|
+
// p = get_corpus(filename);
|
25
|
+
// } catch (const std::exception& e) {
|
26
|
+
// aligned_free((void*)p.data());
|
27
|
+
// std::cout << "Could not load the file " << filename << std::endl;
|
28
|
+
// }
|
29
|
+
padded_string get_corpus(const std::string &filename);
|
30
|
+
} // namespace simdjson
|
31
|
+
|
32
|
+
#endif
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#ifndef SIMDJSON_JSONMINIFIER_H
|
2
|
+
#define SIMDJSON_JSONMINIFIER_H
|
3
|
+
|
4
|
+
#include "simdjson/padded_string.h"
|
5
|
+
#include <cstddef>
|
6
|
+
#include <cstdint>
|
7
|
+
#include <string_view>
|
8
|
+
|
9
|
+
namespace simdjson {
|
10
|
+
|
11
|
+
// Take input from buf and remove useless whitespace, write it to out; buf and
|
12
|
+
// out can be the same pointer. Result is null terminated,
|
13
|
+
// return the string length (minus the null termination).
|
14
|
+
// The accelerated version of this function only runs on AVX2 hardware.
|
15
|
+
size_t json_minify(const uint8_t *buf, size_t len, uint8_t *out);
|
16
|
+
|
17
|
+
static inline size_t json_minify(const char *buf, size_t len, char *out) {
|
18
|
+
return json_minify(reinterpret_cast<const uint8_t *>(buf), len,
|
19
|
+
reinterpret_cast<uint8_t *>(out));
|
20
|
+
}
|
21
|
+
|
22
|
+
static inline size_t json_minify(const std::string_view &p, char *out) {
|
23
|
+
return json_minify(p.data(), p.size(), out);
|
24
|
+
}
|
25
|
+
|
26
|
+
static inline size_t json_minify(const padded_string &p, char *out) {
|
27
|
+
return json_minify(p.data(), p.size(), out);
|
28
|
+
}
|
29
|
+
} // namespace simdjson
|
30
|
+
#endif
|
@@ -0,0 +1,250 @@
|
|
1
|
+
#ifndef SIMDJSON_JSONPARSER_H
|
2
|
+
#define SIMDJSON_JSONPARSER_H
|
3
|
+
#include "simdjson/common_defs.h"
|
4
|
+
#include "simdjson/jsonioutil.h"
|
5
|
+
#include "simdjson/padded_string.h"
|
6
|
+
#include "simdjson/parsedjson.h"
|
7
|
+
#include "simdjson/simdjson.h"
|
8
|
+
#include "simdjson/stage1_find_marks.h"
|
9
|
+
#include "simdjson/stage2_build_tape.h"
|
10
|
+
#include <string>
|
11
|
+
#ifdef _MSC_VER
|
12
|
+
#include <windows.h>
|
13
|
+
// must be included after windows.h
|
14
|
+
#include <sysinfoapi.h>
|
15
|
+
#else
|
16
|
+
#include <unistd.h>
|
17
|
+
#endif
|
18
|
+
|
19
|
+
namespace simdjson {
|
20
|
+
// json_parse_implementation is the generic function, it is specialized for
|
21
|
+
// various architectures, e.g., as
|
22
|
+
// json_parse_implementation<Architecture::HASWELL> or
|
23
|
+
// json_parse_implementation<Architecture::ARM64>
|
24
|
+
template <Architecture T>
|
25
|
+
int json_parse_implementation(const uint8_t *buf, size_t len, ParsedJson &pj,
|
26
|
+
bool realloc_if_needed = true) {
|
27
|
+
if (pj.byte_capacity < len) {
|
28
|
+
return simdjson::CAPACITY;
|
29
|
+
}
|
30
|
+
bool reallocated = false;
|
31
|
+
if (realloc_if_needed) {
|
32
|
+
#if ALLOW_SAME_PAGE_BUFFER_OVERRUN
|
33
|
+
// realloc is needed if the end of the memory crosses a page
|
34
|
+
#ifdef _MSC_VER
|
35
|
+
SYSTEM_INFO sysInfo;
|
36
|
+
GetSystemInfo(&sysInfo);
|
37
|
+
long page_size = sysInfo.dwPageSize;
|
38
|
+
#else
|
39
|
+
long page_size = sysconf(_SC_PAGESIZE);
|
40
|
+
#endif
|
41
|
+
//////////////
|
42
|
+
// We want to check that buf + len - 1 and buf + len - 1 + SIMDJSON_PADDING
|
43
|
+
// are in the same page.
|
44
|
+
// That is, we want to check that
|
45
|
+
// (buf + len - 1) / page_size == (buf + len - 1 + SIMDJSON_PADDING) /
|
46
|
+
// page_size That's true if (buf + len - 1) % page_size + SIMDJSON_PADDING <
|
47
|
+
// page_size.
|
48
|
+
///////////
|
49
|
+
if ((reinterpret_cast<uintptr_t>(buf + len - 1) % page_size) +
|
50
|
+
SIMDJSON_PADDING <
|
51
|
+
static_cast<uintptr_t>(page_size)) {
|
52
|
+
#else // SIMDJSON_SAFE_SAME_PAGE_READ_OVERRUN
|
53
|
+
if (true) { // if not SIMDJSON_SAFE_SAME_PAGE_READ_OVERRUN, we always
|
54
|
+
// reallocate
|
55
|
+
#endif
|
56
|
+
const uint8_t *tmp_buf = buf;
|
57
|
+
buf = (uint8_t *)allocate_padded_buffer(len);
|
58
|
+
if (buf == NULL)
|
59
|
+
return simdjson::MEMALLOC;
|
60
|
+
memcpy((void *)buf, tmp_buf, len);
|
61
|
+
reallocated = true;
|
62
|
+
} // if (true) OR if ( (reinterpret_cast<uintptr_t>(buf + len - 1) %
|
63
|
+
// page_size ) + SIMDJSON_PADDING < static_cast<uintptr_t>(page_size) ) {
|
64
|
+
} // if(realloc_if_needed) {
|
65
|
+
int stage1_is_ok = simdjson::find_structural_bits<T>(buf, len, pj);
|
66
|
+
if (stage1_is_ok != simdjson::SUCCESS) {
|
67
|
+
pj.error_code = stage1_is_ok;
|
68
|
+
return pj.error_code;
|
69
|
+
}
|
70
|
+
int res = unified_machine<T>(buf, len, pj);
|
71
|
+
if (reallocated) {
|
72
|
+
aligned_free((void *)buf);
|
73
|
+
}
|
74
|
+
return res;
|
75
|
+
}
|
76
|
+
|
77
|
+
// Parse a document found in buf.
|
78
|
+
//
|
79
|
+
// The content should be a valid JSON document encoded as UTF-8. If there is a
|
80
|
+
// UTF-8 BOM, the caller is responsible for omitting it, UTF-8 BOM are
|
81
|
+
// discouraged.
|
82
|
+
//
|
83
|
+
// You need to preallocate ParsedJson with a capacity of len (e.g.,
|
84
|
+
// pj.allocate_capacity(len)).
|
85
|
+
//
|
86
|
+
// The function returns simdjson::SUCCESS (an integer = 0) in case of a success
|
87
|
+
// or an error code from simdjson/simdjson.h in case of failure such as
|
88
|
+
// simdjson::CAPACITY, simdjson::MEMALLOC, simdjson::DEPTH_ERROR and so forth;
|
89
|
+
// the simdjson::error_message function converts these error codes into a
|
90
|
+
// string).
|
91
|
+
//
|
92
|
+
// You can also check validity by calling pj.is_valid(). The same ParsedJson can
|
93
|
+
// be reused for other documents.
|
94
|
+
//
|
95
|
+
// If realloc_if_needed is true (default) then a temporary buffer is created
|
96
|
+
// when needed during processing (a copy of the input string is made). The input
|
97
|
+
// buf should be readable up to buf + len + SIMDJSON_PADDING if
|
98
|
+
// realloc_if_needed is false, all bytes at and after buf + len are ignored
|
99
|
+
// (can be garbage). The ParsedJson object can be reused.
|
100
|
+
|
101
|
+
int json_parse(const uint8_t *buf, size_t len, ParsedJson &pj,
|
102
|
+
bool realloc_if_needed = true);
|
103
|
+
|
104
|
+
// Parse a document found in buf.
|
105
|
+
//
|
106
|
+
// The content should be a valid JSON document encoded as UTF-8. If there is a
|
107
|
+
// UTF-8 BOM, the caller is responsible for omitting it, UTF-8 BOM are
|
108
|
+
// discouraged.
|
109
|
+
//
|
110
|
+
// You need to preallocate ParsedJson with a capacity of len (e.g.,
|
111
|
+
// pj.allocate_capacity(len)).
|
112
|
+
//
|
113
|
+
// The function returns simdjson::SUCCESS (an integer = 0) in case of a success
|
114
|
+
// or an error code from simdjson/simdjson.h in case of failure such as
|
115
|
+
// simdjson::CAPACITY, simdjson::MEMALLOC, simdjson::DEPTH_ERROR and so forth;
|
116
|
+
// the simdjson::error_message function converts these error codes into a
|
117
|
+
// string).
|
118
|
+
//
|
119
|
+
// You can also check validity
|
120
|
+
// by calling pj.is_valid(). The same ParsedJson can be reused for other
|
121
|
+
// documents.
|
122
|
+
//
|
123
|
+
// If realloc_if_needed is true (default) then a temporary buffer is created
|
124
|
+
// when needed during processing (a copy of the input string is made). The input
|
125
|
+
// buf should be readable up to buf + len + SIMDJSON_PADDING if
|
126
|
+
// realloc_if_needed is false, all bytes at and after buf + len are ignored
|
127
|
+
// (can be garbage). The ParsedJson object can be reused.
|
128
|
+
int json_parse(const char *buf, size_t len, ParsedJson &pj,
|
129
|
+
bool realloc_if_needed = true);
|
130
|
+
|
131
|
+
// We do not want to allow implicit conversion from C string to std::string.
|
132
|
+
int json_parse(const char *buf, ParsedJson &pj) = delete;
|
133
|
+
|
134
|
+
// Parse a document found in in string s.
|
135
|
+
// You need to preallocate ParsedJson with a capacity of len (e.g.,
|
136
|
+
// pj.allocate_capacity(len)).
|
137
|
+
//
|
138
|
+
// The function returns simdjson::SUCCESS (an integer = 0) in case of a success
|
139
|
+
// or an error code from simdjson/simdjson.h in case of failure such as
|
140
|
+
// simdjson::CAPACITY, simdjson::MEMALLOC, simdjson::DEPTH_ERROR and so forth;
|
141
|
+
// the simdjson::error_message function converts these error codes into a
|
142
|
+
// string).
|
143
|
+
//
|
144
|
+
// A temporary buffer is created when needed during processing
|
145
|
+
// (a copy of the input string is made).
|
146
|
+
inline int json_parse(const std::string &s, ParsedJson &pj) {
|
147
|
+
return json_parse(s.data(), s.length(), pj, true);
|
148
|
+
}
|
149
|
+
|
150
|
+
// Parse a document found in in string s.
|
151
|
+
//
|
152
|
+
// The content should be a valid JSON document encoded as UTF-8. If there is a
|
153
|
+
// UTF-8 BOM, the caller is responsible for omitting it, UTF-8 BOM are
|
154
|
+
// discouraged.
|
155
|
+
//
|
156
|
+
// You need to preallocate ParsedJson with a capacity of len (e.g.,
|
157
|
+
// pj.allocate_capacity(len)).
|
158
|
+
//
|
159
|
+
// The function returns simdjson::SUCCESS (an integer = 0) in case of a success
|
160
|
+
// or an error code from simdjson/simdjson.h in case of failure such as
|
161
|
+
// simdjson::CAPACITY, simdjson::MEMALLOC, simdjson::DEPTH_ERROR and so forth;
|
162
|
+
// the simdjson::error_message function converts these error codes into a
|
163
|
+
// string).
|
164
|
+
//
|
165
|
+
// You can also check validity
|
166
|
+
// by calling pj.is_valid(). The same ParsedJson can be reused for other
|
167
|
+
// documents.
|
168
|
+
inline int json_parse(const padded_string &s, ParsedJson &pj) {
|
169
|
+
return json_parse(s.data(), s.length(), pj, false);
|
170
|
+
}
|
171
|
+
|
172
|
+
// Build a ParsedJson object. You can check validity
|
173
|
+
// by calling pj.is_valid(). This does the memory allocation needed for
|
174
|
+
// ParsedJson. If realloc_if_needed is true (default) then a temporary buffer is
|
175
|
+
// created when needed during processing (a copy of the input string is made).
|
176
|
+
//
|
177
|
+
// The input buf should be readable up to buf + len + SIMDJSON_PADDING if
|
178
|
+
// realloc_if_needed is false, all bytes at and after buf + len are ignored
|
179
|
+
// (can be garbage).
|
180
|
+
//
|
181
|
+
// The content should be a valid JSON document encoded as UTF-8. If there is a
|
182
|
+
// UTF-8 BOM, the caller is responsible for omitting it, UTF-8 BOM are
|
183
|
+
// discouraged.
|
184
|
+
//
|
185
|
+
// This is a convenience function which calls json_parse.
|
186
|
+
WARN_UNUSED
|
187
|
+
ParsedJson build_parsed_json(const uint8_t *buf, size_t len,
|
188
|
+
bool realloc_if_needed = true);
|
189
|
+
|
190
|
+
WARN_UNUSED
|
191
|
+
// Build a ParsedJson object. You can check validity
|
192
|
+
// by calling pj.is_valid(). This does the memory allocation needed for
|
193
|
+
// ParsedJson. If realloc_if_needed is true (default) then a temporary buffer is
|
194
|
+
// created when needed during processing (a copy of the input string is made).
|
195
|
+
//
|
196
|
+
// The input buf should be readable up to buf + len + SIMDJSON_PADDING if
|
197
|
+
// realloc_if_needed is false, all bytes at and after buf + len are ignored
|
198
|
+
// (can be garbage).
|
199
|
+
//
|
200
|
+
//
|
201
|
+
// The content should be a valid JSON document encoded as UTF-8. If there is a
|
202
|
+
// UTF-8 BOM, the caller is responsible for omitting it, UTF-8 BOM are
|
203
|
+
// discouraged.
|
204
|
+
//
|
205
|
+
// This is a convenience function which calls json_parse.
|
206
|
+
inline ParsedJson build_parsed_json(const char *buf, size_t len,
|
207
|
+
bool realloc_if_needed = true) {
|
208
|
+
return build_parsed_json(reinterpret_cast<const uint8_t *>(buf), len,
|
209
|
+
realloc_if_needed);
|
210
|
+
}
|
211
|
+
|
212
|
+
// We do not want to allow implicit conversion from C string to std::string.
|
213
|
+
ParsedJson build_parsed_json(const char *buf) = delete;
|
214
|
+
|
215
|
+
// Parse a document found in in string s.
|
216
|
+
// You need to preallocate ParsedJson with a capacity of len (e.g.,
|
217
|
+
// pj.allocate_capacity(len)). Return SUCCESS (an integer = 0) in case of a
|
218
|
+
// success. You can also check validity by calling pj.is_valid(). The same
|
219
|
+
// ParsedJson can be reused for other documents.
|
220
|
+
//
|
221
|
+
// A temporary buffer is created when needed during processing
|
222
|
+
// (a copy of the input string is made).
|
223
|
+
//
|
224
|
+
// The content should be a valid JSON document encoded as UTF-8. If there is a
|
225
|
+
// UTF-8 BOM, the caller is responsible for omitting it, UTF-8 BOM are
|
226
|
+
// discouraged.
|
227
|
+
//
|
228
|
+
// This is a convenience function which calls json_parse.
|
229
|
+
WARN_UNUSED
|
230
|
+
inline ParsedJson build_parsed_json(const std::string &s) {
|
231
|
+
return build_parsed_json(s.data(), s.length(), true);
|
232
|
+
}
|
233
|
+
|
234
|
+
// Parse a document found in in string s.
|
235
|
+
// You need to preallocate ParsedJson with a capacity of len (e.g.,
|
236
|
+
// pj.allocate_capacity(len)). Return SUCCESS (an integer = 0) in case of a
|
237
|
+
// success. You can also check validity by calling pj.is_valid(). The same
|
238
|
+
// ParsedJson can be reused for other documents.
|
239
|
+
//
|
240
|
+
// The content should be a valid JSON document encoded as UTF-8. If there is a
|
241
|
+
// UTF-8 BOM, the caller is responsible for omitting it, UTF-8 BOM are
|
242
|
+
// discouraged.
|
243
|
+
//
|
244
|
+
// This is a convenience function which calls json_parse.
|
245
|
+
WARN_UNUSED
|
246
|
+
inline ParsedJson build_parsed_json(const padded_string &s) {
|
247
|
+
return build_parsed_json(s.data(), s.length(), false);
|
248
|
+
}
|
249
|
+
} // namespace simdjson
|
250
|
+
#endif
|