1 #ifndef SIMDJSON_DOM_PARSER_H
2 #define SIMDJSON_DOM_PARSER_H
4 #include "simdjson/common_defs.h"
5 #include "simdjson/dom/document.h"
6 #include "simdjson/error.h"
7 #include "simdjson/internal/dom_parser_implementation.h"
8 #include "simdjson/internal/tape_ref.h"
9 #include "simdjson/padded_string.h"
10 #include "simdjson/portability.h"
19 class document_stream;
23 static constexpr
size_t DEFAULT_BATCH_SIZE = 1000000;
32 static constexpr
size_t MINIMAL_BATCH_SIZE = 32;
37 static constexpr
size_t MINIMAL_DOCUMENT_CAPACITY = 32;
462 #ifndef SIMDJSON_DISABLE_DEPRECATED_API
474 [[deprecated(
"Use allocate() instead.")]]
482 simdjson_inline size_t capacity() const noexcept;
498 simdjson_inline
size_t max_depth() const noexcept;
516 #ifdef SIMDJSON_THREADS_ENABLED
527 using InvalidJSON [[deprecated(
"Use simdjson_error instead")]] =
simdjson_error;
530 std::unique_ptr<internal::dom_parser_implementation>
implementation{};
541 [[deprecated(
"Use the result of parser.parse() instead")]]
542 inline bool is_valid() const noexcept;
548 [[deprecated("Use the result of
parser.
parse() instead")]]
549 inline
int get_error_code() const noexcept;
553 inline std::
string get_error_message() const noexcept;
556 [[deprecated("Use cout << on the result of
parser.
parse() instead")]]
557 inline
bool print_json(std::ostream &os) const noexcept;
560 inline
bool dump_raw_tape(std::ostream &os) const noexcept;
569 size_t _max_capacity;
574 std::unique_ptr<
char[]> loaded_bytes;
577 size_t _loaded_bytes_capacity{0};
598 inline error_code ensure_capacity(
size_t desired_capacity) noexcept;
604 inline error_code ensure_capacity(document& doc,
size_t desired_capacity) noexcept;
607 inline simdjson_result<size_t> read_file(
const std::string &path) noexcept;
609 friend class parser::Iterator;
610 friend class document_stream;
A persistent document parser.
simdjson_inline parser(size_t max_capacity=SIMDJSON_MAXSIZE_BYTES) noexcept
Create a JSON parser.
simdjson_result< element > parse(const uint8_t *buf, size_t len, bool realloc_if_needed=true) &noexcept
Parse a JSON document and return a temporary reference to it.
simdjson_result< element > parse_into_document(document &doc, const uint8_t *buf, size_t len, bool realloc_if_needed=true) &noexcept
Parse a JSON document into a provide document instance and return a temporary reference to it.
simdjson_inline size_t max_depth() const noexcept
The maximum level of nested object and arrays supported by this parser.
simdjson_inline parser(parser &&other) noexcept
Take another parser's buffers and state.
simdjson_result< document_stream > load_many(const std::string &path, size_t batch_size=dom::DEFAULT_BATCH_SIZE) noexcept
Load a file containing many JSON documents.
simdjson_inline void set_max_capacity(size_t max_capacity) noexcept
Set max_capacity.
simdjson_inline size_t max_capacity() const noexcept
The largest document this parser can automatically support.
simdjson_result< element > load(const std::string &path) &noexcept
Load a JSON document from a file and return a reference to it.
~parser()=default
Deallocate the JSON parser.
simdjson_inline size_t capacity() const noexcept
The largest document this parser can support without reallocating.
simdjson_inline parser & operator=(parser &&other) noexcept
Take another parser's buffers and state.
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...
simdjson_result< document_stream > parse_many(const uint8_t *buf, size_t len, size_t batch_size=dom::DEFAULT_BATCH_SIZE) noexcept
Parse a buffer containing many JSON documents.
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().
We want to support argument-dependent lookup (ADL).
const char * error_message(error_code error) noexcept
Get the error message for the given error code.
constexpr size_t DEFAULT_MAX_DEPTH
By default, simdjson supports this many nested objects and arrays.
error_code
All possible errors returned by simdjson.
@ UNINITIALIZED
unknown error, or uninitialized document
constexpr size_t SIMDJSON_MAXSIZE_BYTES
The maximum document size supported by simdjson.
String with extra allocation for ease of use with parser::parse()
Exception thrown when an exception-supporting simdjson method is called.
The result of a simdjson operation that could fail.