simdjson  3.1.8
Ridiculously Fast JSON
json_iterator.h
1 namespace simdjson {
2 namespace SIMDJSON_IMPLEMENTATION {
3 namespace ondemand {
4 
5 class document;
6 class document_stream;
7 class object;
8 class array;
9 class value;
10 class raw_json_string;
11 class parser;
12 
18 class json_iterator {
19 protected:
20  token_iterator token{};
21  ondemand::parser *parser{};
27  uint8_t *_string_buf_loc{};
38  error_code error{SUCCESS};
47  depth_t _depth{};
54  token_position _root{};
61  bool _streaming{false};
62 
63 public:
64  simdjson_inline json_iterator() noexcept = default;
65  simdjson_inline json_iterator(json_iterator &&other) noexcept;
66  simdjson_inline json_iterator &operator=(json_iterator &&other) noexcept;
67  simdjson_inline explicit json_iterator(const json_iterator &other) noexcept = default;
68  simdjson_inline json_iterator &operator=(const json_iterator &other) noexcept = default;
72  simdjson_warn_unused simdjson_inline error_code skip_child(depth_t parent_depth) noexcept;
73 
77  simdjson_inline bool at_root() const noexcept;
78 
85  simdjson_inline bool streaming() const noexcept;
86 
90  simdjson_inline token_position root_position() const noexcept;
94  simdjson_inline void assert_at_document_depth() const noexcept;
98  simdjson_inline void assert_at_root() const noexcept;
99 
103  simdjson_inline bool at_end() const noexcept;
104 
108  simdjson_inline bool is_alive() const noexcept;
109 
113  simdjson_inline void abandon() noexcept;
114 
118  simdjson_inline const uint8_t *return_current_and_advance() noexcept;
119 
126  simdjson_inline bool is_single_token() const noexcept;
127 
133  simdjson_inline void assert_more_tokens(uint32_t required_tokens=1) const noexcept;
139  simdjson_inline void assert_valid_position(token_position position) const noexcept;
150  simdjson_inline const uint8_t *peek(int32_t delta=0) const noexcept;
158  simdjson_inline uint32_t peek_length(int32_t delta=0) const noexcept;
167  simdjson_inline const uint8_t *unsafe_pointer() const noexcept;
178  simdjson_inline const uint8_t *peek(token_position position) const noexcept;
186  simdjson_inline uint32_t peek_length(token_position position) const noexcept;
195  simdjson_inline const uint8_t *peek_last() const noexcept;
196 
204  simdjson_inline void ascend_to(depth_t parent_depth) noexcept;
205 
213  simdjson_inline void descend_to(depth_t child_depth) noexcept;
214  simdjson_inline void descend_to(depth_t child_depth, int32_t delta) noexcept;
215 
219  simdjson_inline depth_t depth() const noexcept;
220 
224  simdjson_inline uint8_t *&string_buf_loc() noexcept;
225 
232  simdjson_inline error_code report_error(error_code error, const char *message) noexcept;
233 
239  simdjson_inline error_code optional_error(error_code error, const char *message) noexcept;
240 
246  simdjson_warn_unused simdjson_inline bool copy_to_buffer(const uint8_t *json, uint32_t max_len, uint8_t *tmpbuf, size_t N) noexcept;
247 
248  simdjson_inline token_position position() const noexcept;
254  simdjson_inline simdjson_result<std::string_view> unescape(raw_json_string in, bool allow_replacement) noexcept;
255  simdjson_inline simdjson_result<std::string_view> unescape_wobbly(raw_json_string in) noexcept;
256  simdjson_inline void reenter_child(token_position position, depth_t child_depth) noexcept;
257 
258 #if SIMDJSON_DEVELOPMENT_CHECKS
259  simdjson_inline token_position start_position(depth_t depth) const noexcept;
260  simdjson_inline void set_start_position(depth_t depth, token_position position) noexcept;
261 #endif
262 
263  /* Useful for debugging and logging purposes. */
264  inline std::string to_string() const noexcept;
265 
269  inline simdjson_result<const char *> current_location() const noexcept;
270 
275  inline void rewind() noexcept;
282  inline bool balanced() const noexcept;
283 protected:
284  simdjson_inline json_iterator(const uint8_t *buf, ondemand::parser *parser) noexcept;
286  simdjson_inline token_position last_position() const noexcept;
288  simdjson_inline token_position end_position() const noexcept;
290  simdjson_inline token_position end() const noexcept;
291 
292  friend class document;
293  friend class document_stream;
294  friend class object;
295  friend class array;
296  friend class value;
297  friend class raw_json_string;
298  friend class parser;
299  friend class value_iterator;
300  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) noexcept;
301  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) noexcept;
302 }; // json_iterator
303 
304 } // namespace ondemand
305 } // namespace SIMDJSON_IMPLEMENTATION
306 } // namespace simdjson
307 
308 namespace simdjson {
309 
310 template<>
311 struct simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_iterator> : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::json_iterator> {
312 public:
313  simdjson_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::json_iterator &&value) noexcept;
314  simdjson_inline simdjson_result(error_code error) noexcept;
315 
316  simdjson_inline simdjson_result() noexcept = default;
317 };
318 
319 } // namespace simdjson
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
int32_t depth_t
Represents the depth of a JSON value (number of nested arrays/objects).
Definition: ondemand.h:11
We want to support argument-dependent lookup (ADL).
error_code
All possible errors returned by simdjson.
Definition: error.h:17
@ SUCCESS
No error.
Definition: error.h:18
std::string to_string(T x)
Converts JSON to a string.
The result of a simdjson operation that could fail.
Definition: error.h:205