libkazv
client_device.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
3  */
4 
5 #pragma once
6 
7 #include "types.hpp"
8 
9 
10 namespace Kazv::Api {
12 struct Device
13 {
14 
16  std::string deviceId;
17 
20  std::optional<std::string> displayName;
21 
24  std::optional<std::string> lastSeenIp;
25 
29  std::optional<std::int_fast64_t> lastSeenTs;
30 };
31 
32 }
33 namespace nlohmann
34 {
35 using namespace Kazv;
36 using namespace Kazv::Api;
37 template<>
38 struct adl_serializer<Device> {
39  static void to_json(json& jo, const Device &pod)
40  {
41  if (! jo.is_object()) { jo = json::object(); }
42 
43 
44  jo["device_id"s] = pod.deviceId;
45 
46 
47  addToJsonIfNeeded(jo, "display_name"s, pod.displayName);
48 
49  addToJsonIfNeeded(jo, "last_seen_ip"s, pod.lastSeenIp);
50 
51  addToJsonIfNeeded(jo, "last_seen_ts"s, pod.lastSeenTs);
52  }
53  static void from_json(const json &jo, Device& result)
54  {
55 
56  if (jo.contains("device_id"s)) {
57  result.deviceId = jo.at("device_id"s);
58  }
59  if (jo.contains("display_name"s)) {
60  result.displayName = jo.at("display_name"s);
61  }
62  if (jo.contains("last_seen_ip"s)) {
63  result.lastSeenIp = jo.at("last_seen_ip"s);
64  }
65  if (jo.contains("last_seen_ts"s)) {
66  result.lastSeenTs = jo.at("last_seen_ts"s);
67  }
68 
69  }
70 };
71  }
72 
73  namespace Kazv::Api
74  {
75 } // namespace Kazv::Api
Definition: location.hpp:10
Definition: location.hpp:10
void addToJsonIfNeeded(json &j, std::string name, T &&arg)
Definition: types.hpp:80
nlohmann::json json
Definition: jsonwrap.hpp:20
Definition: location.hpp:27
A client device.
Definition: client_device.hpp:13
std::string deviceId
Identifier of this device.
Definition: client_device.hpp:16
std::optional< std::string > lastSeenIp
The IP address where this device was last seen.
Definition: client_device.hpp:24
std::optional< std::int_fast64_t > lastSeenTs
The timestamp (in milliseconds since the unix epoch) when this devices was last seen.
Definition: client_device.hpp:29
std::optional< std::string > displayName
Display name set by the user for this device.
Definition: client_device.hpp:20
static void to_json(json &jo, const Device &pod)
Definition: client_device.hpp:39
static void from_json(const json &jo, Device &result)
Definition: client_device.hpp:53