hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCETaskRequestDeleteData.cpp
Go to the documentation of this file.
1 #include <Poco/JSON/Object.h>
2 #include <Poco/JSON/Array.h>
3 #include <Poco/JSON/JSON.h>
4 #include <Poco/JSON/Stringifier.h>
5 #include <Poco/JSON/Parser.h>
6 #include <Poco/JSON/JSONException.h>
7 #include <Poco/Dynamic/Var.h>
8 #include <utility>
9 
10 #include "DRCEError.hpp"
12 
13 namespace HCE
14 {
15 namespace drce
16 {
17 //-----------------------------------------------------------------------------
19 : inherited(DRCETaskRequest::RequestType::rtDeleteTaskData)
20 {
21  if (!json.empty())
22  unserialize(json);
23 }
24 //-----------------------------------------------------------------------------
25 bool DRCETaskRequestDeleteData::serialize(std::string& json)
26 {
28  errorMsg.clear();
29  try
30  {
31  Poco::JSON::Object::Ptr obj = new Poco::JSON::Object();
32 
33  std::stringstream ostr;
34  Poco::JSON::Stringifier::stringify(obj, ostr);
35  json = ostr.str();
36 
37  _isError = false;
38  }
39  catch(std::exception& e)
40  {
41  _isError = true;
42  errorMsg = e.what();
44  }
45  return !_isError;}
46 //-----------------------------------------------------------------------------
47 bool DRCETaskRequestDeleteData::unserialize(const std::string& json)
48 {
50  errorMsg.clear();
51 
52  try
53  {
54  Poco::JSON::Parser parser;
55  Poco::Dynamic::Var res = parser.parse(json);
56  Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
57 
58  _isError = false;
59  }
60  catch(Poco::JSON::JSONException& e)
61  {
62  _isError = true;
63  errorMsg = e.message();
65  }
66  catch(Poco::Exception& e)
67  {
68  _isError = true;
69  errorMsg = e.message();
71  }
72  return !_isError;
73 }
74 //-----------------------------------------------------------------------------
75 std::istream& operator>>(std::istream& is, DRCETaskRequestDeleteData& rhs)
76 {
77  std::string json;
78  is.seekg(0, std::ios::end);
79  json.resize(is.tellg());
80  is.seekg(0, std::ios::beg);
81  is.read(const_cast<char*>(json.c_str()), json.size());
82  rhs.unserialize(json);
83  return is;
84 }
85 //-----------------------------------------------------------------------------
86 std::ostream& operator<<(std::ostream& os, const DRCETaskRequestDeleteData& rhs)
87 {
88  std::string json;
89  const_cast<DRCETaskRequestDeleteData&>(rhs).serialize(json);
90  return os << json;
91 }
92 //-----------------------------------------------------------------------------
93 //-----------------------------------------------------------------------------
94 } // end namespace drce
95 } // end namespace HCE