simdjson 5.0.2
Ridiculously Fast JSON
Loading...
Searching...
No Matches
json_iterator.h
1#ifndef SIMDJSON_GENERIC_ONDEMAND_JSON_ITERATOR_H
2
3#ifndef SIMDJSON_CONDITIONAL_INCLUDE
4#define SIMDJSON_GENERIC_ONDEMAND_JSON_ITERATOR_H
5#include "simdjson/generic/ondemand/base.h"
6#include "simdjson/generic/implementation_simdjson_result_base.h"
7#include "simdjson/generic/ondemand/token_iterator.h"
8#endif // SIMDJSON_CONDITIONAL_INCLUDE
9
10namespace simdjson {
11namespace SIMDJSON_IMPLEMENTATION {
12namespace ondemand {
13
19class json_iterator {
20protected:
21 token_iterator token{};
22 ondemand::parser *parser{};
28 uint8_t *_string_buf_loc{};
39 error_code error{SUCCESS};
48 depth_t _depth{};
55 token_position _root{};
62 bool _streaming{false};
63#ifdef SIMDJSON_EXPERIMENTAL_ALLOW_INCOMPLETE_JSON
64 bool _allow_incomplete_json{false};
65#endif
66
67public:
68 simdjson_inline json_iterator() noexcept = default;
69 simdjson_inline json_iterator(json_iterator &&other) noexcept;
70 simdjson_inline json_iterator &operator=(json_iterator &&other) noexcept;
71 simdjson_inline explicit json_iterator(const json_iterator &other) noexcept = default;
72 simdjson_inline json_iterator &operator=(const json_iterator &other) noexcept = default;
76 simdjson_warn_unused simdjson_inline error_code skip_child(depth_t parent_depth) noexcept;
77
81 simdjson_inline bool at_root() const noexcept;
82
89 simdjson_inline bool streaming() const noexcept;
90#ifdef SIMDJSON_EXPERIMENTAL_ALLOW_INCOMPLETE_JSON
91 simdjson_inline bool allow_incomplete_json() const noexcept;
92 simdjson_inline size_t remaining_input_length(const uint8_t *json) const noexcept;
93#endif // SIMDJSON_EXPERIMENTAL_ALLOW_INCOMPLETE_JSON
94
98 simdjson_inline token_position root_position() const noexcept;
102 simdjson_inline void assert_at_document_depth() const noexcept;
106 simdjson_inline void assert_at_root() const noexcept;
107
111 simdjson_inline bool at_end() const noexcept;
112
116 simdjson_inline bool is_alive() const noexcept;
117
121 simdjson_inline void abandon() noexcept;
122
126 simdjson_inline const uint8_t *return_current_and_advance() noexcept;
127
134 simdjson_inline bool is_single_token() const noexcept;
135
141 simdjson_inline void assert_more_tokens(uint32_t required_tokens=1) const noexcept;
147 simdjson_inline void assert_valid_position(token_position position) const noexcept;
158 simdjson_inline const uint8_t *peek(int32_t delta=0) const noexcept;
166 simdjson_inline uint32_t peek_length(int32_t delta=0) const noexcept;
175 simdjson_inline const uint8_t *unsafe_pointer() const noexcept;
186 simdjson_inline const uint8_t *peek(token_position position) const noexcept;
194 simdjson_inline uint32_t peek_length(token_position position) const noexcept;
202 simdjson_inline uint32_t peek_root_length(token_position position) const noexcept;
211 simdjson_inline const uint8_t *peek_last() const noexcept;
212
220 simdjson_inline void ascend_to(depth_t parent_depth) noexcept;
221
229 simdjson_inline void descend_to(depth_t child_depth) noexcept;
230 simdjson_inline void descend_to(depth_t child_depth, int32_t delta) noexcept;
231
235 simdjson_inline depth_t depth() const noexcept;
236
240 simdjson_inline uint8_t *&string_buf_loc() noexcept;
241
248 simdjson_warn_unused simdjson_inline error_code report_error(error_code error, const char *message) noexcept;
249
255 simdjson_warn_unused simdjson_inline error_code optional_error(error_code error, const char *message) noexcept;
256
262 simdjson_warn_unused simdjson_inline bool copy_to_buffer(const uint8_t *json, uint32_t max_len, uint8_t *tmpbuf, size_t N) noexcept;
263
264 simdjson_inline token_position position() const noexcept;
270 simdjson_inline simdjson_result<std::string_view> unescape(raw_json_string in, bool allow_replacement) noexcept;
271 simdjson_inline simdjson_result<std::string_view> unescape_wobbly(raw_json_string in) noexcept;
272
273 simdjson_inline void reenter_child(token_position position, depth_t child_depth) noexcept;
274
275 simdjson_warn_unused simdjson_inline error_code consume_character(char c) noexcept;
276#if SIMDJSON_DEVELOPMENT_CHECKS
277 simdjson_inline token_position start_position(depth_t depth) const noexcept;
278 simdjson_inline void set_start_position(depth_t depth, token_position position) noexcept;
279#endif
280
281 /* Useful for debugging and logging purposes. */
282 inline std::string to_string() const noexcept;
283
287 inline simdjson_result<const char *> current_location() const noexcept;
288
293 inline void rewind() noexcept;
300 inline bool balanced() const noexcept;
301protected:
302 simdjson_inline json_iterator(const uint8_t *buf, ondemand::parser *parser) noexcept;
303#ifdef SIMDJSON_EXPERIMENTAL_ALLOW_INCOMPLETE_JSON
304 simdjson_inline json_iterator(const uint8_t *buf, ondemand::parser *parser, bool streaming) noexcept;
305#endif // SIMDJSON_EXPERIMENTAL_ALLOW_INCOMPLETE_JSON
307 simdjson_inline token_position last_position() const noexcept;
309 simdjson_inline token_position end_position() const noexcept;
311 simdjson_inline token_position end() const noexcept;
312
313 friend class document;
314 friend class document_stream;
315 friend class object;
316 friend class array;
317 friend class value;
318 friend class raw_json_string;
319 friend class parser;
320 friend class value_iterator;
321 friend class field;
322 template <typename... Args>
323 friend simdjson_inline void logger::log_line(const json_iterator &iter, const char *title_prefix, const char *title, std::string_view detail, int delta, int depth_delta, logger::log_level level, Args&&... args) noexcept;
324 template <typename... Args>
325 friend simdjson_inline void logger::log_line(const json_iterator &iter, token_position index, depth_t depth, const char *title_prefix, const char *title, std::string_view detail, logger::log_level level, Args&&... args) noexcept;
326}; // json_iterator
327
328} // namespace ondemand
329} // namespace SIMDJSON_IMPLEMENTATION
330} // namespace simdjson
331
332namespace simdjson {
333
334template<>
335struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::json_iterator> {
336public:
337 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::json_iterator &&value) noexcept;
338 simdjson_inline simdjson_result(error_code error) noexcept;
339
340 simdjson_inline simdjson_result() noexcept = default;
341};
342
343} // namespace simdjson
344
345#endif // SIMDJSON_GENERIC_ONDEMAND_JSON_ITERATOR_H
int32_t depth_t
Represents the depth of a JSON value (number of nested arrays/objects).
Definition base.h:18
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8
error_code
All possible errors returned by simdjson.
Definition error.h:19
@ SUCCESS
No error.
Definition error.h:20
std::string to_string(T x)
Converts JSON to a string.
The result of a simdjson operation that could fail.
Definition error.h:281