| 9139 | */ |
| 9140 | template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>> |
| 9141 | class binary_reader |
| 9142 | { |
| 9143 | using number_integer_t = typename BasicJsonType::number_integer_t; |
| 9144 | using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| 9145 | using number_float_t = typename BasicJsonType::number_float_t; |
| 9146 | using string_t = typename BasicJsonType::string_t; |
| 9147 | using binary_t = typename BasicJsonType::binary_t; |
| 9148 | using json_sax_t = SAX; |
| 9149 | using char_type = typename InputAdapterType::char_type; |
| 9150 | using char_int_type = typename std::char_traits<char_type>::int_type; |
| 9151 | |
| 9152 | public: |
| 9153 | /*! |
| 9154 | @brief create a binary reader |
| 9155 | |
| 9156 | @param[in] adapter input adapter to read from |
| 9157 | */ |
| 9158 | explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format) |
| 9159 | { |
| 9160 | (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {}; |
| 9161 | } |
| 9162 | |
| 9163 | // make class move-only |
| 9164 | binary_reader(const binary_reader&) = delete; |
| 9165 | binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| 9166 | binary_reader& operator=(const binary_reader&) = delete; |
| 9167 | binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| 9168 | ~binary_reader() = default; |
| 9169 | |
| 9170 | /*! |
| 9171 | @param[in] format the binary format to parse |
| 9172 | @param[in] sax_ a SAX event processor |
| 9173 | @param[in] strict whether to expect the input to be consumed completed |
| 9174 | @param[in] tag_handler how to treat CBOR tags |
| 9175 | |
| 9176 | @return whether parsing was successful |
| 9177 | */ |
| 9178 | JSON_HEDLEY_NON_NULL(3) |
| 9179 | bool sax_parse(const input_format_t format, |
| 9180 | json_sax_t* sax_, |
| 9181 | const bool strict = true, |
| 9182 | const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) |
| 9183 | { |
| 9184 | sax = sax_; |
| 9185 | bool result = false; |
| 9186 | |
| 9187 | switch (format) |
| 9188 | { |
| 9189 | case input_format_t::bson: |
| 9190 | result = parse_bson_internal(); |
| 9191 | break; |
| 9192 | |
| 9193 | case input_format_t::cbor: |
| 9194 | result = parse_cbor_internal(true, tag_handler); |
| 9195 | break; |
| 9196 | |
| 9197 | case input_format_t::msgpack: |
| 9198 | result = parse_msgpack_internal(); |
nothing calls this directly
no test coverage detected