MCPcopy Create free account
hub / github.com/apache/thrift / readJSONDouble

Method readJSONDouble

lib/cpp/src/thrift/protocol/TJSONProtocol.cpp:887–926  ·  view source on GitHub ↗

Reads a JSON number or string and interprets it as a double.

Source from the content-addressed store, hash-verified

885
886// Reads a JSON number or string and interprets it as a double.
887uint32_t TJSONProtocol::readJSONDouble(double& num) {
888 uint32_t result = context_->read(reader_);
889 std::string str;
890 if (reader_.peek() == kJSONStringDelimiter) {
891 result += readJSONString(str, true);
892 // Check for NaN, Infinity and -Infinity
893 if (str == kThriftNan) {
894 num = HUGE_VAL / HUGE_VAL; // generates NaN
895 } else if (str == kThriftInfinity) {
896 num = HUGE_VAL;
897 } else if (str == kThriftNegativeInfinity) {
898 num = -HUGE_VAL;
899 } else {
900 if (!context_->escapeNum()) {
901 // Throw exception -- we should not be in a string in this case
902 throw TProtocolException(TProtocolException::INVALID_DATA,
903 "Numeric data unexpectedly quoted");
904 }
905 try {
906 num = fromString<double>(str);
907 } catch (const std::runtime_error&) {
908 throw TProtocolException(TProtocolException::INVALID_DATA,
909 "Expected numeric value; got \"" + str + "\"");
910 }
911 }
912 } else {
913 if (context_->escapeNum()) {
914 // This will throw - we should have had a quote if escapeNum == true
915 readJSONSyntaxChar(kJSONStringDelimiter);
916 }
917 result += readJSONNumericChars(str);
918 try {
919 num = fromString<double>(str);
920 } catch (const std::runtime_error&) {
921 throw TProtocolException(TProtocolException::INVALID_DATA,
922 "Expected numeric value; got \"" + str + "\"");
923 }
924 }
925 return result;
926}
927
928uint32_t TJSONProtocol::readJSONObjectStart() {
929 uint32_t result = context_->read(reader_);

Callers

nothing calls this directly

Calls 4

TProtocolExceptionClass · 0.70
readMethod · 0.65
peekMethod · 0.45
escapeNumMethod · 0.45

Tested by

no test coverage detected