! @brief Calculates the size necessary to serialize the JSON value @a j with its @a name @return The calculated size for the BSON document entry for @a j with the given @a name. */
| 13830 | @return The calculated size for the BSON document entry for @a j with the given @a name. |
| 13831 | */ |
| 13832 | static std::size_t calc_bson_element_size(const string_t& name, |
| 13833 | const BasicJsonType& j) |
| 13834 | { |
| 13835 | const auto header_size = calc_bson_entry_header_size(name); |
| 13836 | switch (j.type()) |
| 13837 | { |
| 13838 | case value_t::object: |
| 13839 | return header_size + calc_bson_object_size(*j.m_value.object); |
| 13840 | |
| 13841 | case value_t::array: |
| 13842 | return header_size + calc_bson_array_size(*j.m_value.array); |
| 13843 | |
| 13844 | case value_t::binary: |
| 13845 | return header_size + calc_bson_binary_size(*j.m_value.binary); |
| 13846 | |
| 13847 | case value_t::boolean: |
| 13848 | return header_size + 1ul; |
| 13849 | |
| 13850 | case value_t::number_float: |
| 13851 | return header_size + 8ul; |
| 13852 | |
| 13853 | case value_t::number_integer: |
| 13854 | return header_size + calc_bson_integer_size(j.m_value.number_integer); |
| 13855 | |
| 13856 | case value_t::number_unsigned: |
| 13857 | return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned); |
| 13858 | |
| 13859 | case value_t::string: |
| 13860 | return header_size + calc_bson_string_size(*j.m_value.string); |
| 13861 | |
| 13862 | case value_t::null: |
| 13863 | return header_size + 0ul; |
| 13864 | |
| 13865 | // LCOV_EXCL_START |
| 13866 | default: |
| 13867 | JSON_ASSERT(false); |
| 13868 | return 0ul; |
| 13869 | // LCOV_EXCL_STOP |
| 13870 | } |
| 13871 | } |
| 13872 | |
| 13873 | /*! |
| 13874 | @brief Serializes the JSON value @a j to BSON and associates it with the |