simdjson  3.1.1
Ridiculously Fast JSON
parser.h
1 #include "simdjson/error.h"
2 
3 namespace simdjson {
4 namespace SIMDJSON_IMPLEMENTATION {
5 namespace ondemand {
6 
7 class array;
8 class object;
9 class value;
10 class raw_json_string;
11 class document_stream;
12 
18 static constexpr size_t DEFAULT_BATCH_SIZE = 1000000;
27 static constexpr size_t MINIMAL_BATCH_SIZE = 32;
28 
34 class parser {
35 public:
41  inline explicit parser(size_t max_capacity = SIMDJSON_MAXSIZE_BYTES) noexcept;
42 
43  inline parser(parser &&other) noexcept = default;
44  simdjson_inline parser(const parser &other) = delete;
45  simdjson_inline parser &operator=(const parser &other) = delete;
46  simdjson_inline parser &operator=(parser &&other) noexcept = default;
47 
49  inline ~parser() noexcept = default;
50 
96  simdjson_warn_unused simdjson_result<document> iterate(padded_string_view json) & noexcept;
98  simdjson_warn_unused simdjson_result<document> iterate(const char *json, size_t len, size_t capacity) & noexcept;
100  simdjson_warn_unused simdjson_result<document> iterate(const uint8_t *json, size_t len, size_t capacity) & noexcept;
102  simdjson_warn_unused simdjson_result<document> iterate(std::string_view json, size_t capacity) & noexcept;
104  simdjson_warn_unused simdjson_result<document> iterate(const std::string &json) & noexcept;
106  simdjson_warn_unused simdjson_result<document> iterate(const simdjson_result<padded_string> &json) & noexcept;
108  simdjson_warn_unused simdjson_result<document> iterate(const simdjson_result<padded_string_view> &json) & noexcept;
110  simdjson_warn_unused simdjson_result<document> iterate(padded_string &&json) & noexcept = delete;
111 
150  simdjson_warn_unused simdjson_result<json_iterator> iterate_raw(padded_string_view json) & noexcept;
151 
152 
215  inline simdjson_result<document_stream> iterate_many(const uint8_t *buf, size_t len, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
217  inline simdjson_result<document_stream> iterate_many(const char *buf, size_t len, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
219  inline simdjson_result<document_stream> iterate_many(const std::string &s, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
220  inline simdjson_result<document_stream> iterate_many(const std::string &&s, size_t batch_size) = delete;// unsafe
222  inline simdjson_result<document_stream> iterate_many(const padded_string &s, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
223  inline simdjson_result<document_stream> iterate_many(const padded_string &&s, size_t batch_size) = delete;// unsafe
224 
226  simdjson_result<document_stream> iterate_many(const char *buf, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept = delete;
227 
229  simdjson_inline size_t capacity() const noexcept;
231  simdjson_inline size_t max_capacity() const noexcept;
232  simdjson_inline void set_max_capacity(size_t max_capacity) noexcept;
239  simdjson_inline size_t max_depth() const noexcept;
240 
253  simdjson_warn_unused error_code allocate(size_t capacity, size_t max_depth=DEFAULT_MAX_DEPTH) noexcept;
254 
255  #ifdef SIMDJSON_THREADS_ENABLED
261  bool threaded{true};
262  #endif
263 
284  simdjson_inline simdjson_result<std::string_view> unescape(raw_json_string in, uint8_t *&dst) const noexcept;
285 private:
287  std::unique_ptr<internal::dom_parser_implementation> implementation{};
288  size_t _capacity{0};
289  size_t _max_capacity;
290  size_t _max_depth{DEFAULT_MAX_DEPTH};
291  std::unique_ptr<uint8_t[]> string_buf{};
292 #if SIMDJSON_DEVELOPMENT_CHECKS
293  std::unique_ptr<token_position[]> start_positions{};
294 #endif
295 
296  friend class json_iterator;
297  friend class document_stream;
298 };
299 
300 } // namespace ondemand
301 } // namespace SIMDJSON_IMPLEMENTATION
302 } // namespace simdjson
303 
304 namespace simdjson {
305 
306 template<>
307 struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::parser> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::parser> {
308 public:
310  simdjson_inline simdjson_result(error_code error) noexcept;
311  simdjson_inline simdjson_result() noexcept = default;
312 };
313 
314 } // namespace simdjson
simdjson_inline size_t max_capacity() const noexcept
The maximum capacity of this parser (the largest document it is allowed to process).
Definition: parser-inl.h:104
simdjson_warn_unused simdjson_result< document > iterate(padded_string_view json) &noexcept
Start iterating an on-demand JSON document.
Definition: parser-inl.h:31
~parser() noexcept=default
Deallocate the JSON parser.
parser(size_t max_capacity=SIMDJSON_MAXSIZE_BYTES) noexcept
Create a JSON parser.
Definition: parser-inl.h:5
simdjson_result< document_stream > iterate_many(const uint8_t *buf, size_t len, size_t batch_size=DEFAULT_BATCH_SIZE) noexcept
Parse a buffer containing many JSON documents.
Definition: parser-inl.h:87
simdjson_inline size_t max_depth() const noexcept
The maximum depth of this parser (the most deeply nested objects and arrays it can process).
Definition: parser-inl.h:107
simdjson_warn_unused error_code allocate(size_t capacity, size_t max_depth=DEFAULT_MAX_DEPTH) noexcept
Ensure this parser has enough memory to process JSON documents up to capacity bytes in length and max...
Definition: parser-inl.h:9
simdjson_inline simdjson_result< std::string_view > unescape(raw_json_string in, uint8_t *&dst) const noexcept
Unescape this JSON string, replacing \ with \, with newline, etc.
Definition: parser-inl.h:119
simdjson_inline size_t capacity() const noexcept
The capacity of this parser (the largest document it can process).
Definition: parser-inl.h:101
A string escaped per JSON rules, terminated with quote (").
An implementation of simdjson for a particular CPU architecture.
User-provided string that promises it has extra padded bytes at the end for use with parser::parse().
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
We want to support argument-dependent lookup (ADL).
constexpr size_t DEFAULT_MAX_DEPTH
By default, simdjson supports this many nested objects and arrays.
Definition: common_defs.h:52
error_code
All possible errors returned by simdjson.
Definition: error.h:17
constexpr size_t SIMDJSON_MAXSIZE_BYTES
The maximum document size supported by simdjson.
Definition: common_defs.h:35
String with extra allocation for ease of use with parser::parse()
Definition: padded_string.h:21
The result of a simdjson operation that could fail.
Definition: error.h:205
simdjson_inline error_code error() const noexcept
The error.
Definition: error-inl.h:132
simdjson_inline T & value() &noexcept(false)
Get the result value.