-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.cpp
More file actions
94 lines (79 loc) · 2.53 KB
/
example.cpp
File metadata and controls
94 lines (79 loc) · 2.53 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <coapi.hpp>
int main(int argc, char **argv)
{
coapi::message msg;
msg.type(coapi::coap_type::confirmable);
auto a = msg.type();
std::vector<uint8_t> v{0b01110011, //version - type - token length
0b11111111, //code
0b11111111, // -message id
0b11111111, // -
0b00000001, // -token
0b00000010, // -
0b00000100, // -
0b11000010, // option header
0b00000001, // -option value
0b00011111, // -
0b10000011, // option header
0b00000010, // -option value
0b00000100, // -
0b00001000, // -
0b11010001, // option header
0b00000001, // -option optional delta
0b11111111, // option value
0b11111111, // payload marker
0b00001000, // -payload
0b00010000, // -
0b00100000, // -
0b01000000, // -
0b10000000, // -
};
coapi::message mi;
auto p = decode(v.begin(),v.end(),mi);
auto m = mi.raw();
if(!p)
{
std::cout << "Parsing FAIL" << std::endl;
}
std::cout << "Version=" << (int)m.version << " Type=" << (int)m.type << " "<< " Class=" << (int)m.code << " ID=" << (int)m.message_id<< std::endl;
for(auto &el:m.token)
{
std::cout << "Token val=" << (int)el << std::endl;
}
for(auto &pel:m.options)
{
std::cout << "Option number=" << pel.number << std::endl;
for(auto &it:pel.values)
{
std::cout << "Val=" << (int)it << std::endl;
}
}
for(auto &l:m.payload)
{
std::cout << "Payload=" << (int)l << std::endl;
}
std::cout << "-------" << std::endl;
std::cout << "Input vector" << std::endl;
for(auto &el:v)
{
std::cout << std::bitset<8>(el) << std::endl;
}
std::cout << std::endl << std::endl;
std::cout << "Output vector" << std::endl;
std::vector<uint8_t> vv{};
std::back_insert_iterator<std::vector<uint8_t>> it(vv);
auto pp = encode(m,it);
for(auto &m:vv)
{
std::cout << std::bitset<8>(m) << std::endl;
}
if(std::equal(v.begin(),v.end(),vv.begin()))
{
std::cout << "IN=OUT" << std::endl;
}else
{
std::cout << "IN DIFFERENT FROM OUT" << std::endl;
}
return 0;
}