simdjson 4.1.0
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
64public:
65 simdjson_inline json_iterator() noexcept = default;
66 simdjson_inline json_iterator(json_iterator &&other) noexcept;
67 simdjson_inline json_iterator &operator=(json_iterator &&other) noexcept;
68 simdjson_inline explicit json_iterator(const json_iterator &other) noexcept = default;
69 simdjson_inline json_iterator &operator=(const json_iterator &other) noexcept = default;
73 simdjson_warn_unused simdjson_inline error_code skip_child(depth_t parent_depth) noexcept;
74
78 simdjson_inline bool at_root() const noexcept;
79
86 simdjson_inline bool streaming() const noexcept;
87
91 simdjson_inline token_position root_position() const noexcept;
95 simdjson_inline void assert_at_document_depth() const noexcept;
99 simdjson_inline void assert_at_root() const noexcept;
100
104 simdjson_inline bool at_end() const noexcept;
105
109 simdjson_inline bool is_alive() const noexcept;
110
114 simdjson_inline void abandon() noexcept;
115
119 simdjson_inline const uint8_t *return_current_and_advance() noexcept;
120
127 simdjson_inline bool is_single_token() const noexcept;
128
134 simdjson_inline void assert_more_tokens(uint32_t required_tokens=1) const noexcept;
140 simdjson_inline void assert_valid_position(token_position position) const noexcept;
151 simdjson_inline const uint8_t *peek(int32_t delta=0) const noexcept;
159 simdjson_inline uint32_t peek_length(int32_t delta=0) const noexcept;
168 simdjson_inline const uint8_t *unsafe_pointer() const noexcept;
179 simdjson_inline const uint8_t *peek(token_position position) const noexcept;
187 simdjson_inline uint32_t peek_length(token_position position) const noexcept;
195 simdjson_inline uint32_t peek_root_length(token_position position) const noexcept;
204 simdjson_inline const uint8_t *peek_last() const noexcept;
205
213 simdjson_inline void ascend_to(depth_t parent_depth) noexcept;
214
222 simdjson_inline void descend_to(depth_t child_depth) noexcept;
223 simdjson_inline void descend_to(depth_t child_depth, int32_t delta) noexcept;
224
228 simdjson_inline depth_t depth() const noexcept;
229
233 simdjson_inline uint8_t *&string_buf_loc() noexcept;
234
241 simdjson_warn_unused simdjson_inline error_code report_error(error_code error, const char *message) noexcept;
242
248 simdjson_warn_unused simdjson_inline error_code optional_error(error_code error, const char *message) noexcept;
249
255 simdjson_warn_unused simdjson_inline bool copy_to_buffer(const uint8_t *json, uint32_t max_len, uint8_t *tmpbuf, size_t N) noexcept;
256
257 simdjson_inline token_position position() const noexcept;
263 simdjson_inline simdjson_result<std::string_view> unescape(raw_json_string in, bool allow_replacement) noexcept;
264 simdjson_inline simdjson_result<std::string_view> unescape_wobbly(raw_json_string in) noexcept;
265
266 simdjson_inline void reenter_child(token_position position, depth_t child_depth) noexcept;
267
268 simdjson_warn_unused simdjson_inline error_code consume_character(char c) noexcept;
269#if SIMDJSON_DEVELOPMENT_CHECKS
270 simdjson_inline token_position start_position(depth_t depth) const noexcept;
271 simdjson_inline void set_start_position(depth_t depth, token_position position) noexcept;
272#endif
273
274 /* Useful for debugging and logging purposes. */
275 inline std::string to_string() const noexcept;
276
280 inline simdjson_result<const char *> current_location() const noexcept;
281
286 inline void rewind() noexcept;
293 inline bool balanced() const noexcept;
294protected:
295 simdjson_inline json_iterator(const uint8_t *buf, ondemand::parser *parser) noexcept;
296#ifdef SIMDJSON_EXPERIMENTAL_ALLOW_INCOMPLETE_JSON
297 simdjson_inline json_iterator(const uint8_t *buf, ondemand::parser *parser, bool streaming) noexcept;
298#endif // SIMDJSON_EXPERIMENTAL_ALLOW_INCOMPLETE_JSON
300 simdjson_inline token_position last_position() const noexcept;
302 simdjson_inline token_position end_position() const noexcept;
304 simdjson_inline token_position end() const noexcept;
305
306 friend class document;
307 friend class document_stream;
308 friend class object;
309 friend class array;
310 friend class value;
311 friend class raw_json_string;
312 friend class parser;
313 friend class value_iterator;
314 friend class field;
315 template <typename... Args>
316 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;
317 template <typename... Args>
318 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;
319}; // json_iterator
320
321} // namespace ondemand
322} // namespace SIMDJSON_IMPLEMENTATION
323} // namespace simdjson
324
325namespace simdjson {
326
327template<>
328struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::json_iterator> {
329public:
330 simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::json_iterator &&value) noexcept;
331 simdjson_inline simdjson_result(error_code error) noexcept;
332
333 simdjson_inline simdjson_result() noexcept = default;
334};
335
336} // namespace simdjson
337
338#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:278