Aktualizr
C++ SOTA Client
image.h
1 #ifndef OPCUABRIDGE_IMAGE_H_
2 #define OPCUABRIDGE_IMAGE_H_
3 
4 #include "hash.h"
5 
6 #include "common.h"
7 
8 namespace opcuabridge {
9 class Image {
10  public:
11  Image() = default;
12  virtual ~Image() = default;
13 
14  const std::string& getFilename() const { return filename_; }
15  void setFilename(const std::string& filename) { filename_ = filename; }
16  const std::size_t& getLength() const { return length_; }
17  void setLength(const std::size_t& length) { length_ = length; }
18  const std::vector<Hash>& getHashes() const { return hashes_; }
19  void setHashes(const std::vector<Hash>& hashes) { hashes_ = hashes; }
20 
21  Json::Value wrapMessage() const {
22  Json::Value v;
23  v["filepath"] = getFilename();
24  v["fileinfo"]["length"] = static_cast<Json::Value::UInt>(getLength());
25  v["fileinfo"]["hashes"] = convert_to::jsonArray(getHashes());
26  return v;
27  }
28  void unwrapMessage(Json::Value v) {
29  setFilename(v["filepath"].asString());
30  setLength(v["fileinfo"]["length"].asUInt());
31  setHashes(convert_to::stdVector<Hash>(v["fileinfo"]["hashes"]));
32  }
33 
34  protected:
35  std::string filename_;
36  std::size_t length_{};
37  std::vector<Hash> hashes_;
38 
39  private:
40 #ifdef OPCUABRIDGE_ENABLE_SERIALIZATION
41  SERIALIZE_FUNCTION_FRIEND_DECLARATION
42 
43  DEFINE_SERIALIZE_METHOD() {
44  SERIALIZE_FIELD(ar, "filename_", filename_);
45  SERIALIZE_FIELD(ar, "length_", length_);
46  SERIALIZE_FIELD(ar, "hashes_", hashes_);
47  }
48 #endif // OPCUABRIDGE_ENABLE_SERIALIZATION
49 };
50 } // namespace opcuabridge
51 
52 #endif // OPCUABRIDGE_IMAGE_H_