18 : m_dataHandler(
std::
move(dataHandler))
31 std::unique_ptr<TcpSocket> pTransport(
new TcpSocket());
33 if (pTransport->connect(hostname, port, timeoutMs) != 0)
60 std::size_t elements = 0;
69 if (0x02 == buffer[0])
89 std::vector<std::uint8_t> buffer;
94 std::cout <<
"Received less than the required 4 package length bytes." << std::endl;
98 const auto packageLength = readUnalignBigEndian<std::uint32_t>(buffer.data());
100 if (packageLength < 3u)
102 std::cout <<
"Invalid package length " << packageLength <<
". Should be at least 3" << std::endl;
107 std::size_t remainingBytesToReceive = packageLength;
111 std::cout <<
"Received less than the required " << remainingBytesToReceive <<
" bytes." << std::endl;
116 const auto protocolVersion = readUnalignBigEndian<std::uint16_t>(buffer.data());
117 const auto packetType = readUnalignBigEndian<std::uint8_t>(buffer.data() + 2);
118 if (protocolVersion != 0x001)
120 std::cout <<
"Received unknown protocol version " << protocolVersion <<
"." << std::endl;
123 if (packetType != 0x62)
125 std::cout <<
"Received unknown packet type " << packetType <<
"." << std::endl;
135 std::cout <<
"No datahandler is set -> cant parse blob data" << std::endl;
139 using ItBufDifferenceType = std::vector<std::uint8_t>::iterator::difference_type;
140 auto itBufSegment = itBuf;
141 auto remainingSize = bufferSize;
143 if (remainingSize < 4)
145 std::cout <<
"Received not enough data to parse segment description. Connection issues?" << std::endl;
152 itBufSegment +=
sizeof(std::uint16_t);
153 const auto numSegments = readUnalignBigEndian<std::uint16_t>(&*itBufSegment);
154 itBufSegment +=
sizeof(std::uint16_t);
158 std::vector<std::uint32_t> offset(numSegments);
159 std::vector<std::uint32_t> changeCounter(numSegments);
160 const std::uint16_t segmentDescriptionSize = 4u + 4u;
161 const std::size_t totalSegmentDescriptionSize =
static_cast<std::size_t
>(numSegments * segmentDescriptionSize);
162 if (remainingSize < totalSegmentDescriptionSize)
164 std::cout <<
"Received not enough data to parse segment description. Connection issues?" << std::endl;
169 std::cout <<
"Invalid number of segments. Connection issues?" << std::endl;
172 for (std::uint16_t
i = 0;
i < numSegments;
i++)
174 offset[
i] = readUnalignBigEndian<std::uint32_t>(&*itBufSegment);
175 itBufSegment +=
sizeof(std::uint32_t);
176 changeCounter[
i] = readUnalignBigEndian<std::uint32_t>(&*itBufSegment);
177 itBufSegment +=
sizeof(std::uint32_t);
179 remainingSize -= totalSegmentDescriptionSize;
183 const std::size_t xmlSize = offset[1] - offset[0];
184 if (remainingSize < xmlSize)
186 std::cout <<
"Received not enough data to parse xml Description. Connection issues?" << std::endl;
189 remainingSize -= xmlSize;
190 const std::string xmlSegment((itBuf +
static_cast<ItBufDifferenceType
>(offset[0])),
191 (itBuf +
static_cast<ItBufDifferenceType
>(offset[1])));
196 std::size_t binarySegmentSize = offset[2] - offset[1];
197 if (remainingSize < binarySegmentSize)
199 std::cout <<
"Received not enough data to parse binary Segment. Connection issues?" << std::endl;
202 result =
m_dataHandler->parseBinaryData((itBuf +
static_cast<ItBufDifferenceType
>(offset[1])), binarySegmentSize);
203 remainingSize -= binarySegmentSize;
220 const std::vector<char>
data{
'B',
'l',
'b',
'R',
'q',
's',
't'};