NodeListMimeSerialization.hpp
1 #pragma once
2 #include <Device/Node/DeviceNode.hpp>
3 
4 #include <score/model/tree/TreeNodeSerialization.hpp>
5 #include <score/serialization/JSONVisitor.hpp>
6 #include <score/serialization/MimeVisitor.hpp>
7 
8 namespace score::mime
9 {
10 inline constexpr const char* nodelist() noexcept
11 {
12  return "application/x-score-nodelist";
13 }
14 }
15 template <>
16 struct MimeReader<Device::NodeList> : public MimeDataReader
17 {
18  using MimeDataReader::MimeDataReader;
19  void serialize(const Device::NodeList& lst) const
20  {
21  JSONReader r;
22 
23  r.stream.StartArray();
24  for(const auto& elt : lst)
25  {
26  r.stream.StartObject();
27  r.obj["Node"] = *elt;
28  r.obj["Address"] = Device::address(*elt).address;
29  r.stream.EndObject();
30  }
31  r.stream.EndArray();
32 
33  m_mime.setData(score::mime::nodelist(), r.toByteArray());
34  }
35 };
36 
37 template <>
38 struct MimeWriter<Device::FreeNodeList> : public MimeDataWriter
39 {
40  using MimeDataWriter::MimeDataWriter;
41  auto deserialize()
42  {
43  Device::FreeNodeList ml;
44  auto json = readJson(m_mime.data(score::mime::nodelist()));
45  const auto& arr = json.GetArray();
46 
47  auto& strings = score::StringConstant();
48  for(const rapidjson::Value& elt : arr)
49  {
50  JSONObject::Deserializer des{elt};
51  Device::FreeNode n;
52  n.first <<= des.obj[strings.Address];
53  n.second <<= des.obj["Node"];
54  ml.push_back(n);
55  }
56 
57  return ml;
58  }
59 };
Definition: JSONVisitor.hpp:52
Definition: JSONVisitor.hpp:423
Manipulation of Devices from Qt.
Definition: AddressSettings.cpp:14
Definition: MimeVisitor.hpp:22
Definition: MimeVisitor.hpp:32
Definition: MimeVisitor.hpp:7
Definition: MimeVisitor.hpp:9