Fix use of getAsI when parsing download rpc.

The value is store as a string in in the xml, so we cannot use getAsI.
We have to get the string and parse it to an int.
We cannot use strtoull because android stdc++ lib doesn't have it.

We have to implement our how parseFromString function using a
istringstream.
This commit is contained in:
Matthieu Gautier 2018-11-02 17:03:03 +01:00
parent 360c913230
commit 5f4c04e79e
2 changed files with 12 additions and 4 deletions

View File

@ -71,5 +71,13 @@ std::string to_string(T value)
oss << value; oss << value;
return oss.str(); return oss.str();
} }
template<typename T>
T extractFromString(const std::string& str) {
std::istringstream iss(str);
T ret;
iss >> ret;
return ret;
}
} //namespace kiwix } //namespace kiwix
#endif #endif

View File

@ -72,12 +72,12 @@ void Download::updateStatus(bool follow)
} catch (InvalidRPCNode& e) { } } catch (InvalidRPCNode& e) { }
} }
m_status = status; m_status = status;
m_totalLength = structNode.getMember("totalLength").getValue().getAsI(); m_totalLength = extractFromString<uint64_t>(structNode.getMember("totalLength").getValue().getAsS());
m_completedLength = structNode.getMember("completedLength").getValue().getAsI(); m_completedLength = extractFromString<uint64_t>(structNode.getMember("completedLength").getValue().getAsS());
m_downloadSpeed = structNode.getMember("downloadSpeed").getValue().getAsI(); m_downloadSpeed = extractFromString<uint64_t>(structNode.getMember("downloadSpeed").getValue().getAsS());
try { try {
auto verifiedLengthValue = structNode.getMember("verifiedLength").getValue(); auto verifiedLengthValue = structNode.getMember("verifiedLength").getValue();
m_verifiedLength = verifiedLengthValue.getAsI(); m_verifiedLength = extractFromString<uint64_t>(verifiedLengthValue.getAsS());
} catch (InvalidRPCNode& e) { m_verifiedLength = 0; } } catch (InvalidRPCNode& e) { m_verifiedLength = 0; }
auto filesMember = structNode.getMember("files"); auto filesMember = structNode.getMember("files");
auto fileStruct = filesMember.getValue().getArray().getValue(0).getStruct(); auto fileStruct = filesMember.getValue().getArray().getValue(0).getStruct();