simdjson  0.3.1
Ridiculously Fast JSON
document_stream.h
1 #ifndef SIMDJSON_DOCUMENT_STREAM_H
2 #define SIMDJSON_DOCUMENT_STREAM_H
3 
4 #include <thread>
5 #include "simdjson/document.h"
6 
7 namespace simdjson::dom {
8 
16 public:
17  really_inline ~document_stream() noexcept;
18 
22  class iterator {
23  public:
27  really_inline simdjson_result<element> operator*() noexcept;
31  inline iterator& operator++() noexcept;
36  really_inline bool operator!=(const iterator &other) const noexcept;
37 
38  private:
39  iterator(document_stream& stream, bool finished) noexcept;
41  document_stream& stream;
43  bool finished;
44  friend class document_stream;
45  };
46 
50  really_inline iterator begin() noexcept;
54  really_inline iterator end() noexcept;
55 
56 private:
57 
58  document_stream &operator=(const document_stream &) = delete; // Disallow copying
59 
60  document_stream(document_stream &other) = delete; // Disallow copying
61 
62  really_inline document_stream(dom::parser &parser, const uint8_t *buf, size_t len, size_t batch_size, error_code error = SUCCESS) noexcept;
63 
90  inline error_code json_parse() noexcept;
91 
99  inline size_t get_current_buffer_loc() const { return current_buffer_loc; }
100 
105  inline size_t get_n_parsed_docs() const { return n_parsed_docs; }
106 
111  inline size_t get_n_bytes_parsed() const { return n_bytes_parsed; }
112 
113  inline const uint8_t *buf() const { return _buf + buf_start; }
114 
115  inline void advance(size_t offset) { buf_start += offset; }
116 
117  inline size_t remaining() const { return _len - buf_start; }
118 
119  dom::parser &parser;
120  const uint8_t *_buf;
121  const size_t _len;
122  size_t _batch_size; // this is actually variable!
123  size_t buf_start{0};
124  size_t next_json{0};
125  bool load_next_batch{true};
126  size_t current_buffer_loc{0};
127 #ifdef SIMDJSON_THREADS_ENABLED
128  size_t last_json_buffer_loc{0};
129 #endif
130  size_t n_parsed_docs{0};
131  size_t n_bytes_parsed{0};
132  error_code error{SUCCESS_AND_HAS_MORE};
133 #ifdef SIMDJSON_THREADS_ENABLED
134  error_code stage1_is_ok_thread{SUCCESS};
135  std::thread stage_1_thread;
136  dom::parser parser_thread;
137 #endif
138  friend class dom::parser;
139 }; // class document_stream
140 
141 } // end of namespace simdjson::dom
142 
143 #endif // SIMDJSON_DOCUMENT_STREAM_H
simdjson::dom::document_stream::iterator
An iterator through a forward-only stream of documents.
Definition: document_stream.h:22
simdjson::dom::document_stream::iterator::operator*
really_inline simdjson_result< element > operator*() noexcept
Get the current document (or error).
Definition: document_stream.h:130
simdjson::dom::document_stream::begin
really_inline iterator begin() noexcept
Start iterating the documents in the stream.
Definition: document_stream.h:118
simdjson::simdjson_result
The result of a simdjson operation that could fail.
Definition: error.h:166
simdjson::dom::document_stream::iterator::operator++
iterator & operator++() noexcept
Advance to the next document.
Definition: document_stream.h:136
simdjson::dom::parser
A persistent document parser.
Definition: document.h:620
simdjson::dom::document_stream::iterator::operator!=
really_inline bool operator!=(const iterator &other) const noexcept
Check if we're at the end yet.
Definition: document_stream.h:145
simdjson::dom::document_stream
A forward-only stream of documents.
Definition: document_stream.h:15
simdjson::dom::document_stream::end
really_inline iterator end() noexcept
The end of the stream, for iterator comparison purposes.
Definition: document_stream.h:122