OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RequestInfo.cpp
Go to the documentation of this file.
1 #include "RequestInfo.h"
2 
3 #include <boost/property_tree/json_parser.hpp>
4 
5 #include <sstream>
6 
7 namespace heavyai {
8 
9 RequestInfo::RequestInfo(std::string const& session_id_or_json) {
10  if (!session_id_or_json.empty() && session_id_or_json[0] == '{') {
11  std::istringstream iss(session_id_or_json);
12  boost::property_tree::ptree ptree;
13  boost::property_tree::read_json(iss, ptree);
14  session_id_ = ptree.get<std::string>("session_id");
15  request_id_ = ptree.get<logger::RequestId>("request_id");
16  } else {
17  session_id_ = session_id_or_json;
18  request_id_ = 0; // Valid request_ids are always positive.
19  }
20 }
21 
22 std::string RequestInfo::json() const {
23  boost::property_tree::ptree ptree;
24  std::ostringstream oss;
25  ptree.put("session_id", session_id_);
26  ptree.put("request_id", request_id_);
27  constexpr bool pretty_print = false;
28  boost::property_tree::write_json(oss, ptree, pretty_print);
29  return oss.str();
30 }
31 
32 } // namespace heavyai
logger::RequestId request_id_
Definition: RequestInfo.h:30
RequestInfo(std::string const &session_id_or_json)
Definition: RequestInfo.cpp:9
std::string session_id_
Definition: RequestInfo.h:29
std::string json() const
Definition: RequestInfo.cpp:22
uint64_t RequestId
Definition: Logger.h:131