MCPcopy Create free account
hub / github.com/arun11299/cpp-jwt / get_number

Method get_number

include/jwt/json/json.hpp:9924–9950  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9922 */
9923 template<typename NumberType, bool InputIsLittleEndian = false>
9924 bool get_number(const input_format_t format, NumberType& result)
9925 {
9926 // step 1: read input into array with system's byte order
9927 std::array<std::uint8_t, sizeof(NumberType)> vec;
9928 for (std::size_t i = 0; i < sizeof(NumberType); ++i)
9929 {
9930 get();
9931 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number")))
9932 {
9933 return false;
9934 }
9935
9936 // reverse byte order prior to conversion if necessary
9937 if (is_little_endian != InputIsLittleEndian)
9938 {
9939 vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);
9940 }
9941 else
9942 {
9943 vec[i] = static_cast<std::uint8_t>(current); // LCOV_EXCL_LINE
9944 }
9945 }
9946
9947 // step 2: convert array into number of type T and return
9948 std::memcpy(&result, vec.data(), sizeof(NumberType));
9949 return true;
9950 }
9951
9952 /*!
9953 @brief create a string by reading characters from the input

Callers

nothing calls this directly

Calls 2

getFunction · 0.85
dataMethod · 0.80

Tested by

no test coverage detected