MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / binary_writer

Class binary_writer

Source/Utils/json.hpp:12751–14317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12749 */
12750 template<typename BasicJsonType, typename CharType>
12751 class binary_writer
12752 {
12753 using string_t = typename BasicJsonType::string_t;
12754 using binary_t = typename BasicJsonType::binary_t;
12755 using number_float_t = typename BasicJsonType::number_float_t;
12756
12757 public:
12758 /*!
12759 @brief create a binary writer
12760
12761 @param[in] adapter output adapter to write to
12762 */
12763 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter)
12764 {
12765 JSON_ASSERT(oa);
12766 }
12767
12768 /*!
12769 @param[in] j JSON value to serialize
12770 @pre j.type() == value_t::object
12771 */
12772 void write_bson(const BasicJsonType& j)
12773 {
12774 switch (j.type())
12775 {
12776 case value_t::object:
12777 {
12778 write_bson_object(*j.m_value.object);
12779 break;
12780 }
12781
12782 default:
12783 {
12784 JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name())));
12785 }
12786 }
12787 }
12788
12789 /*!
12790 @param[in] j JSON value to serialize
12791 */
12792 void write_cbor(const BasicJsonType& j)
12793 {
12794 switch (j.type())
12795 {
12796 case value_t::null:
12797 {
12798 oa->write_character(to_char_type(0xF6));
12799 break;
12800 }
12801
12802 case value_t::boolean:
12803 {
12804 oa->write_character(j.m_value.boolean
12805 ? to_char_type(0xF5)
12806 : to_char_type(0xF4));
12807 break;
12808 }

Callers

nothing calls this directly

Calls 1

little_endianessFunction · 0.85

Tested by

no test coverage detected