hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCEOutputJsonMessage.cpp
Go to the documentation of this file.
2 
3 namespace HCE
4 {
5 namespace drce
6 {
7 //-----------------------------------------------------------------------------
9 : inherited(), resultData()
10 {
11  if (!json.empty())
12  unserialize(json);
13 }
14 //-----------------------------------------------------------------------------
16 {
17  resetError();
18  resultData.clear();
19 }
20 //-----------------------------------------------------------------------------
22 {
23  resultData = rhs;
24 }
25 //-----------------------------------------------------------------------------
27 {
28  resultData = std::forward<DRCEResultData>(rhs);
29 }
30 //-----------------------------------------------------------------------------
31 bool DRCEOutputJsonMessage::serialize(std::string& json)
32 {
33  resetError();
34  DRCEResultDataSerializator resultDataSerializator(resultData);
35  if (!resultDataSerializator.serialize(json))
36  {
37  _isError = resultDataSerializator.isError();
38  errorMsg = resultDataSerializator.getErrorMsg();
39  errorCode = resultDataSerializator.getErrorCode();
40  }
41  return !_isError;
42 }
43 //-----------------------------------------------------------------------------
44 bool DRCEOutputJsonMessage::unserialize(const std::string& json)
45 {
46  clear();
47  DRCEResultDataSerializator resultDataSerializator(resultData);
48  if (!resultDataSerializator.unserialize(json))
49  {
50  _isError = resultDataSerializator.isError();
51  errorMsg = resultDataSerializator.getErrorMsg();
52  errorCode = resultDataSerializator.getErrorCode();
53  }
54  return !_isError;
55 }
56 //-----------------------------------------------------------------------------
57 std::istream& operator>>(std::istream& is, DRCEOutputJsonMessage& outputJsonMessage)
58 {
59  std::string json;
60  is.seekg(0, std::ios::end);
61  json.resize(is.tellg());
62  is.seekg(0, std::ios::beg);
63  is.read(const_cast<char*>(json.c_str()), json.size());
64  outputJsonMessage.unserialize(json);
65  return is;
66 }
67 //-----------------------------------------------------------------------------
68 std::ostream& operator<<(std::ostream& os, const DRCEOutputJsonMessage& outputJsonMessage)
69 {
70  std::string json;
71  const_cast<DRCEOutputJsonMessage&>(outputJsonMessage).serialize(json);
72  return os << json;
73 }
74 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
76 } // namespace drce
77 } // namespace HCE