| 12824 | */ |
| 12825 | template<typename BasicJsonType, typename CharType> |
| 12826 | class binary_writer |
| 12827 | { |
| 12828 | using string_t = typename BasicJsonType::string_t; |
| 12829 | using binary_t = typename BasicJsonType::binary_t; |
| 12830 | using number_float_t = typename BasicJsonType::number_float_t; |
| 12831 | |
| 12832 | public: |
| 12833 | /*! |
| 12834 | @brief create a binary writer |
| 12835 | |
| 12836 | @param[in] adapter output adapter to write to |
| 12837 | */ |
| 12838 | explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter) |
| 12839 | { |
| 12840 | JSON_ASSERT(oa); |
| 12841 | } |
| 12842 | |
| 12843 | /*! |
| 12844 | @param[in] j JSON value to serialize |
| 12845 | @pre j.type() == value_t::object |
| 12846 | */ |
| 12847 | void write_bson(const BasicJsonType& j) |
| 12848 | { |
| 12849 | switch (j.type()) |
| 12850 | { |
| 12851 | case value_t::object: |
| 12852 | { |
| 12853 | write_bson_object(*j.m_value.object); |
| 12854 | break; |
| 12855 | } |
| 12856 | |
| 12857 | default: |
| 12858 | { |
| 12859 | JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()))); |
| 12860 | } |
| 12861 | } |
| 12862 | } |
| 12863 | |
| 12864 | /*! |
| 12865 | @param[in] j JSON value to serialize |
| 12866 | */ |
| 12867 | void write_cbor(const BasicJsonType& j) |
| 12868 | { |
| 12869 | switch (j.type()) |
| 12870 | { |
| 12871 | case value_t::null: |
| 12872 | { |
| 12873 | oa->write_character(to_char_type(0xF6)); |
| 12874 | break; |
| 12875 | } |
| 12876 | |
| 12877 | case value_t::boolean: |
| 12878 | { |
| 12879 | oa->write_character(j.m_value.boolean |
| 12880 | ? to_char_type(0xF5) |
| 12881 | : to_char_type(0xF4)); |
| 12882 | break; |
| 12883 | } |
nothing calls this directly
no test coverage detected