All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ndnd-status-response.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
7 #ifndef NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP
8 #define NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP
9 
10 #include "../encoding/block.hpp"
11 #include "../encoding/tlv-ndnd.hpp"
12 
13 namespace ndn {
14 namespace ndnd {
15 
17 {
18 public:
20  : code_(0)
21  {
22  }
23 
24  StatusResponse(uint32_t code, const std::string& info)
25  : code_(code)
26  , info_(info)
27  {
28  }
29 
33  explicit
34  StatusResponse(const Block& wire)
35  {
36  wireDecode(wire);
37  }
38 
39  inline uint32_t
40  getCode() const;
41 
42  inline void
43  setCode(uint32_t code);
44 
45  inline const std::string&
46  getInfo() const;
47 
48  inline void
49  setInfo(const std::string& info);
50 
51  inline const Block&
52  wireEncode() const;
53 
54  inline void
55  wireDecode(const Block& block);
56 
57 private:
58  uint32_t code_;
59  std::string info_;
60 
61  mutable Block wire_;
62 };
63 
64 inline uint32_t
66 {
67  return code_;
68 }
69 
70 inline void
72 {
73  code_ = code;
74  wire_.reset();
75 }
76 
77 inline const std::string&
79 {
80  return info_;
81 }
82 
83 inline void
84 StatusResponse::setInfo(const std::string& info)
85 {
86  info_ = info;
87  wire_.reset();
88 }
89 
90 
91 inline const Block&
93 {
94  if (wire_.hasWire())
95  return wire_;
96 
98  wire_.push_back
100 
101  if (!info_.empty())
102  {
103  wire_.push_back
104  (dataBlock(tlv::ndnd::StatusText, info_.c_str(), info_.size()));
105  }
106 
107  wire_.encode();
108  return wire_;
109 }
110 
111 inline void
113 {
114  wire_ = wire;
115  wire_.parse();
116 
118 
120  if (val != wire_.elements_end())
121  {
122  info_.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
123  }
124 }
125 
126 inline std::ostream&
127 operator << (std::ostream& os, const StatusResponse& status)
128 {
129  os << status.getCode() << " " << status.getInfo();
130  return os;
131 }
132 
133 } // namespace ndnd
134 } // namespace ndn
135 
136 #endif // NDN_MANAGEMENT_NDND_STATUS_RESPONSE_HPP
Block nonNegativeIntegerBlock(uint32_t type, uint64_t value)
element_const_iterator find(uint32_t type) const
Definition: block.hpp:343
void setInfo(const std::string &info)
Class representing wire element of the NDN packet.
Definition: block.hpp:26
uint64_t readNonNegativeInteger(const Block &block)
element_const_iterator elements_end() const
Definition: block.hpp:476
StatusResponse(uint32_t code, const std::string &info)
const std::string & getInfo() const
void wireDecode(const Block &block)
StatusResponse(const Block &wire)
Create from wire encoding.
const Block & get(uint32_t type) const
Get the first subelement of the requested type.
Definition: block.hpp:326
element_container::const_iterator element_const_iterator
Definition: block.hpp:31
void reset()
Reset wire buffer of the element.
Definition: block.hpp:300
void push_back(const Block &element)
Definition: block.hpp:390
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:265
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:298
const Block & wireEncode() const
Block dataBlock(uint32_t type, const char *data, size_t dataSize)
std::ostream & operator<<(std::ostream &os, const FaceInstance &entry)
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.hpp:288