fix build: Address trivial werrors after upgrading to C++ 20

This commit is contained in:
John Colvin committed 2023-06-26 14:56:55 +00:00
1 parent 2635308a05
commit b27dc4bc67
4 files changed
+87 -76

No files matched your search

@@ -199,45 +199,6 @@ class MarketDataServiceDeribit : public MarketDataService {
template <class T>
static std::pair<T, bool> readJson(rapidjson::Document &doc, const std::string &key);
template <>
std::pair<std::string, bool> readJson<std::string>(rapidjson::Document &doc, const std::string &key) {
auto member = doc.FindMember(key.c_str());
if (member == doc.MemberEnd() || !member->value.IsString()) {
return {{}, false};
}
return {member->value.GetString(), true};
}
template <>
std::pair<std::int64_t, bool> readJson<std::int64_t>(rapidjson::Document &doc, const std::string &key) {
auto member = doc.FindMember(key.c_str());
if (member == doc.MemberEnd()) {
return {0, false};
}
const auto &v = member->value;
if (v.IsInt64()) {
return {v.GetInt64(), true};
}
if (v.IsInt()) {
return {v.GetInt(), true};
}
if (v.IsUint64()) {
return {static_cast<std::int64_t>(v.GetUint64()), true};
}
if (v.IsUint()) {
return {static_cast<std::int64_t>(v.GetUint()), true};
}
if (v.IsString()) {
const char *cstr = v.GetString();
char* endPtr;
const std::int64_t result = std::strtol(cstr, &endPtr, 10);
if (*endPtr == '\0') {
return {result, true};
}
}
return {0, false};
}
static bool isHeartbeatRequest(const std::string &textMessage) {
rj::Document doc;
doc.Parse<rj::kParseNumbersAsStringsFlag>(textMessage.c_str());
@@ -289,30 +250,7 @@ class MarketDataServiceDeribit : public MarketDataService {
}
}
void onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) override {
if (isHeartbeatRequest(textMessage)) {
sendHeartbeat(hdl);
return;
}
rj::Document doc;
doc.Parse<rj::kParseNumbersAsStringsFlag>(textMessage.c_str());
const auto [rpcId, hasRpcId] = readJson<std::int64_t>(doc, "id");
if (hasRpcId) {
if (activeHeartbeatReqs.erase(rpcId) != 0) {
return;
}
const auto [resStr, hasResStr] = readJson<std::string>(doc, "result");
if (hasResStr && resStr == "ok") {
if (activeReqs.erase(rpcId) == 0) {
CCAPI_LOGGER_ERROR("MarketDataServiceDeribit::onTextMessage. Received rpc response with unknown id:\n{}" + textMessage);
} else {
CCAPI_LOGGER_DEBUG("MarketDataServiceDeribit::onTextMessage. Received rpc response:\n{}" + textMessage);
}
return;
}
}
MarketDataService::onTextMessage(hdl, textMessage, timeReceived);
}
void onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) override;
//////////////////////////////////////////////////
// END - BTS Custom Code
@@ -662,6 +600,79 @@ class MarketDataServiceDeribit : public MarketDataService {
std::map<std::string, std::set<int64_t>> subscriptionJsonrpcIdSetByConnectionIdMap;
std::string restTarget;
};
//////////////////////////////////////////////////
// BEGIN - BTS Custom Code
//////////////////////////////////////////////////
template <>
inline std::pair<std::string, bool> MarketDataServiceDeribit::readJson<std::string>(rapidjson::Document &doc, const std::string &key) {
auto member = doc.FindMember(key.c_str());
if (member == doc.MemberEnd() || !member->value.IsString()) {
return {{}, false};
}
return {member->value.GetString(), true};
}
template <>
inline std::pair<std::int64_t, bool> MarketDataServiceDeribit::readJson<std::int64_t>(rapidjson::Document &doc, const std::string &key) {
auto member = doc.FindMember(key.c_str());
if (member == doc.MemberEnd()) {
return {0, false};
}
const auto &v = member->value;
if (v.IsInt64()) {
return {v.GetInt64(), true};
}
if (v.IsInt()) {
return {v.GetInt(), true};
}
if (v.IsUint64()) {
return {static_cast<std::int64_t>(v.GetUint64()), true};
}
if (v.IsUint()) {
return {static_cast<std::int64_t>(v.GetUint()), true};
}
if (v.IsString()) {
const char *cstr = v.GetString();
char* endPtr;
const std::int64_t result = std::strtol(cstr, &endPtr, 10);
if (*endPtr == '\0') {
return {result, true};
}
}
return {0, false};
}
inline void MarketDataServiceDeribit::onTextMessage(wspp::connection_hdl hdl, const std::string& textMessage, const TimePoint& timeReceived) {
if (isHeartbeatRequest(textMessage)) {
sendHeartbeat(hdl);
return;
}
rj::Document doc;
doc.Parse<rj::kParseNumbersAsStringsFlag>(textMessage.c_str());
const auto [rpcId, hasRpcId] = readJson<std::int64_t>(doc, "id");
if (hasRpcId) {
if (activeHeartbeatReqs.erase(rpcId) != 0) {
return;
}
const auto [resStr, hasResStr] = readJson<std::string>(doc, "result");
if (hasResStr && resStr == "ok") {
if (activeReqs.erase(rpcId) == 0) {
CCAPI_LOGGER_ERROR("MarketDataServiceDeribit::onTextMessage. Received rpc response with unknown id:\n{}" + textMessage);
} else {
CCAPI_LOGGER_DEBUG("MarketDataServiceDeribit::onTextMessage. Received rpc response:\n{}" + textMessage);
}
return;
}
}
MarketDataService::onTextMessage(hdl, textMessage, timeReceived);
}
//////////////////////////////////////////////////
// END - BTS Custom Code
//////////////////////////////////////////////////
} /* namespace ccapi */
#endif
#endif