-
Notifications
You must be signed in to change notification settings - Fork 0
/
paramsudp.cpp
67 lines (51 loc) · 1.29 KB
/
paramsudp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "paramsudp.h"
ParamsUDP::ParamsUDP(std::string dev): IParams(dev)
{
}
bool ParamsUDP::fromJSON(const rapidjson::Value &doc)
{
bool result = false;
const char* members[] = { "IP", "Port" };
if(doc.IsObject())
{
bool isOK = true;
for(size_t i = 0; i < sizeof(members)/sizeof(members[0]); ++i)
{
if(!doc.HasMember(members[i]))
{
isOK = false;
break;
}
}
if(isOK)
{
setDevPath(doc[members[0]].GetString());
setPortUDP(doc[members[1]].GetString());
result = true;
}
}
return result;
}
void ParamsUDP::toJSON(rapidjson::Document& doc)
{
auto& allocator = doc.GetAllocator();
rapidjson::Value val;
rapidjson::Value obj(rapidjson::kObjectType);
val.SetString(getDevPath().c_str(), allocator);
obj.AddMember("IP", val, allocator);
val.SetString(std::to_string(portUDP).c_str(), allocator);
obj.AddMember("Port", val, allocator);
doc.AddMember("Params", obj, allocator);
}
uint16_t ParamsUDP::getPortUDP() const
{
return portUDP;
}
void ParamsUDP::setPortUDP(const uint16_t&value)
{
portUDP = value;
}
void ParamsUDP::setPortUDP(const char* value)
{
portUDP = std::atoi(value);
}