! @brief determine the type prefix of container values */
| 14126 | @brief determine the type prefix of container values |
| 14127 | */ |
| 14128 | CharType ubjson_prefix(const BasicJsonType& j) const noexcept |
| 14129 | { |
| 14130 | switch (j.type()) |
| 14131 | { |
| 14132 | case value_t::null: |
| 14133 | return 'Z'; |
| 14134 | |
| 14135 | case value_t::boolean: |
| 14136 | return j.m_value.boolean ? 'T' : 'F'; |
| 14137 | |
| 14138 | case value_t::number_integer: |
| 14139 | { |
| 14140 | if ((std::numeric_limits<std::int8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)()) |
| 14141 | { |
| 14142 | return 'i'; |
| 14143 | } |
| 14144 | if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)()) |
| 14145 | { |
| 14146 | return 'U'; |
| 14147 | } |
| 14148 | if ((std::numeric_limits<std::int16_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)()) |
| 14149 | { |
| 14150 | return 'I'; |
| 14151 | } |
| 14152 | if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)()) |
| 14153 | { |
| 14154 | return 'l'; |
| 14155 | } |
| 14156 | if ((std::numeric_limits<std::int64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)()) |
| 14157 | { |
| 14158 | return 'L'; |
| 14159 | } |
| 14160 | // anything else is treated as high-precision number |
| 14161 | return 'H'; // LCOV_EXCL_LINE |
| 14162 | } |
| 14163 | |
| 14164 | case value_t::number_unsigned: |
| 14165 | { |
| 14166 | if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)())) |
| 14167 | { |
| 14168 | return 'i'; |
| 14169 | } |
| 14170 | if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint8_t>::max)())) |
| 14171 | { |
| 14172 | return 'U'; |
| 14173 | } |
| 14174 | if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)())) |
| 14175 | { |
| 14176 | return 'I'; |
| 14177 | } |
| 14178 | if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)())) |
| 14179 | { |
| 14180 | return 'l'; |
| 14181 | } |
| 14182 | if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)())) |
| 14183 | { |
| 14184 | return 'L'; |
| 14185 | } |