! @brief Writes a BSON element with key @a name and unsigned @a value */
| 13742 | @brief Writes a BSON element with key @a name and unsigned @a value |
| 13743 | */ |
| 13744 | void write_bson_unsigned(const string_t& name, |
| 13745 | const std::uint64_t value) |
| 13746 | { |
| 13747 | if (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) |
| 13748 | { |
| 13749 | write_bson_entry_header(name, 0x10 /* int32 */); |
| 13750 | write_number<std::int32_t, true>(static_cast<std::int32_t>(value)); |
| 13751 | } |
| 13752 | else if (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)())) |
| 13753 | { |
| 13754 | write_bson_entry_header(name, 0x12 /* int64 */); |
| 13755 | write_number<std::int64_t, true>(static_cast<std::int64_t>(value)); |
| 13756 | } |
| 13757 | else |
| 13758 | { |
| 13759 | JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(value) + " cannot be represented by BSON as it does not fit int64")); |
| 13760 | } |
| 13761 | } |
| 13762 | |
| 13763 | /*! |
| 13764 | @brief Writes a BSON element with key @a name and object @a value |