-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathCBORTestUtil.cpp
55 lines (43 loc) · 1.65 KB
/
CBORTestUtil.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
/*
Copyright (c) 2019 Arduino. All rights reserved.
*/
/**************************************************************************************
INCLUDE
**************************************************************************************/
#include <util/CBORTestUtil.h>
#include <iomanip>
#include <iostream>
#include <CBOREncoder.h>
/**************************************************************************************
NAMESPACE
**************************************************************************************/
namespace cbor
{
/**************************************************************************************
PUBLIC FUNCTIONS
**************************************************************************************/
std::vector<uint8_t> encode(PropertyContainer & property_container, bool lightPayload) {
int bytes_encoded = 0;
uint8_t buf[200] = {0};
if (CBOREncoder::encode(property_container, buf, 200, bytes_encoded, lightPayload) == CborNoError)
return std::vector<uint8_t>(buf, buf + bytes_encoded);
else
return std::vector<uint8_t>();
}
void print(std::vector<uint8_t> const & vect) {
for (auto i = vect.begin(); i != vect.end(); i++) {
std::cout << std::uppercase
<< std::hex
<< std::setw(2)
<< std::setfill('0')
<< static_cast<size_t>(*i)
<< std::dec
<< std::nouppercase
<< " ";
}
std::cout << std::endl;
}
/**************************************************************************************
NAMESPACE
**************************************************************************************/
} /* cbor */