Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald\src\payload\extended\extended_data.cpp
Line
Count
Source (jump to first uncovered line)
1
//  Copyright 2020-2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#include "herald/payload/extended/extended_data.h"
6
#include "herald/datatype/data.h"
7
8
#include <string>
9
10
namespace herald {
11
namespace payload {
12
namespace extended {
13
14
ConcreteExtendedDataV1::ConcreteExtendedDataV1()
15
  : sections(),
16
    inUse(0)
17
4
{
18
4
  ;
19
4
}
20
21
ConcreteExtendedDataV1::ConcreteExtendedDataV1(const ConcreteExtendedDataV1& other)
22
  : sections(other.sections),
23
    inUse(other.inUse)
24
4
{
25
4
  ;
26
4
}
27
28
ConcreteExtendedDataV1::ConcreteExtendedDataV1(ConcreteExtendedDataV1&& other)
29
  : sections(std::move(other.sections)),
30
    inUse(other.inUse)
31
0
{
32
0
  ;
33
0
}
34
35
// ConcreteExtendedDataV1&
36
// ConcreteExtendedDataV1::operator=(const ConcreteExtendedDataV1& other)
37
// {
38
//   mHasData = other.mHasData;
39
//   sections = other.sections;
40
41
//   return *this;
42
// }
43
44
// ConcreteExtendedDataV1&
45
// ConcreteExtendedDataV1::operator=(ConcreteExtendedDataV1&& other)
46
// {
47
//   mHasData = other.mHasData;
48
//   sections = std::move(other.sections);
49
50
//   return *this;
51
// }
52
53
ConcreteExtendedDataV1::~ConcreteExtendedDataV1()
54
8
{
55
8
  ;
56
8
}
57
58
59
60
bool
61
ConcreteExtendedDataV1::hasData() const
62
0
{
63
0
  return inUse > 0;
64
0
}
65
66
void
67
ConcreteExtendedDataV1::addSection(ExtendedDataSegmentCode code, uint8_t value)
68
0
{
69
0
  if (inUse >= sections.size()) {
70
0
    return;
71
0
  }
72
0
  sections[inUse].code = code;
73
0
  sections[inUse].length = sizeof(float);
74
0
  sections[inUse].data.append(std::byte(value));
75
0
  ++inUse;
76
0
}
77
78
void
79
ConcreteExtendedDataV1::addSection(ExtendedDataSegmentCode code, uint16_t value)
80
0
{
81
0
  if (inUse >= sections.size()) {
82
0
    return;
83
0
  }
84
0
  sections[inUse].code = code;
85
0
  sections[inUse].length = sizeof(float);
86
0
  sections[inUse].data.append(std::byte(value >> 8));
87
0
  sections[inUse].data.append(std::byte(value & 0xff));
88
0
  ++inUse;
89
0
}
90
91
void
92
ConcreteExtendedDataV1::addSection(ExtendedDataSegmentCode code, float value)
93
0
{
94
0
  if (inUse >= sections.size()) {
95
0
    return;
96
0
  }
97
0
  sections[inUse].code = code;
98
0
  sections[inUse].length = sizeof(float);
99
0
  for (std::size_t i = sizeof(float);i > 0 ;--i) {
100
0
    sections[inUse].data.append(std::byte(((std::size_t)value) >> (8 * (i - 1))));
101
0
  }
102
0
  ++inUse;
103
0
}
104
105
void
106
ConcreteExtendedDataV1::addSection(ExtendedDataSegmentCode code, const std::string value)
107
3
{
108
3
  if (inUse >= sections.size()) {
109
0
    return;
110
0
  }
111
3
  sections[inUse].data.append(value);
112
3
  sections[inUse].code = code;
113
3
  sections[inUse].length = value.size();
114
3
  ++inUse;
115
3
}
116
117
void
118
ConcreteExtendedDataV1::addSection(ExtendedDataSegmentCode code, const Data& value)
119
0
{
120
0
  if (inUse >= sections.size()) {
121
0
    return;
122
0
  }
123
0
  sections[inUse].data.append(value);
124
0
  sections[inUse].code = code;
125
0
  sections[inUse].length = value.size();
126
0
  ++inUse;
127
0
}
128
129
const ConcreteExtendedDataSectionV1&
130
ConcreteExtendedDataV1::getSection(std::size_t index) const
131
0
{
132
0
  return sections[index];
133
0
}
134
135
PayloadData
136
ConcreteExtendedDataV1::payload()
137
4
{
138
4
  if (inUse > 0) {
139
3
    PayloadData result;
140
6
    for (std::size_t i = 0;i < inUse;
++i3
) {
141
3
      auto s = sections[i];
142
3
      result.append(s.code);
143
3
      result.append(s.length);
144
3
      result.append(s.data);
145
3
    }
146
3
    return result;
147
3
  }
148
1
  return PayloadData(); // empty
149
1
}
150
151
}
152
}
153
}