| 9209 | */ |
| 9210 | template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>> |
| 9211 | class binary_reader |
| 9212 | { |
| 9213 | using number_integer_t = typename BasicJsonType::number_integer_t; |
| 9214 | using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| 9215 | using number_float_t = typename BasicJsonType::number_float_t; |
| 9216 | using string_t = typename BasicJsonType::string_t; |
| 9217 | using binary_t = typename BasicJsonType::binary_t; |
| 9218 | using json_sax_t = SAX; |
| 9219 | using char_type = typename InputAdapterType::char_type; |
| 9220 | using char_int_type = typename char_traits<char_type>::int_type; |
| 9221 | |
| 9222 | public: |
| 9223 | /*! |
| 9224 | @brief create a binary reader |
| 9225 | |
| 9226 | @param[in] adapter input adapter to read from |
| 9227 | */ |
| 9228 | explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format) |
| 9229 | { |
| 9230 | (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {}; |
| 9231 | } |
| 9232 | |
| 9233 | // make class move-only |
| 9234 | binary_reader(const binary_reader&) = delete; |
| 9235 | binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| 9236 | binary_reader& operator=(const binary_reader&) = delete; |
| 9237 | binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) |
| 9238 | ~binary_reader() = default; |
| 9239 | |
| 9240 | /*! |
| 9241 | @param[in] format the binary format to parse |
| 9242 | @param[in] sax_ a SAX event processor |
| 9243 | @param[in] strict whether to expect the input to be consumed completed |
| 9244 | @param[in] tag_handler how to treat CBOR tags |
| 9245 | |
| 9246 | @return whether parsing was successful |
| 9247 | */ |
| 9248 | JSON_HEDLEY_NON_NULL(3) |
| 9249 | bool sax_parse(const input_format_t format, |
| 9250 | json_sax_t* sax_, |
| 9251 | const bool strict = true, |
| 9252 | const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) |
| 9253 | { |
| 9254 | sax = sax_; |
| 9255 | bool result = false; |
| 9256 | |
| 9257 | switch (format) |
| 9258 | { |
| 9259 | case input_format_t::bson: |
| 9260 | result = parse_bson_internal(); |
| 9261 | break; |
| 9262 | |
| 9263 | case input_format_t::cbor: |
| 9264 | result = parse_cbor_internal(true, tag_handler); |
| 9265 | break; |
| 9266 | |
| 9267 | case input_format_t::msgpack: |
| 9268 | result = parse_msgpack_internal(); |
nothing calls this directly
no test coverage detected