memory_block_parser.cpp
Go to the documentation of this file.
1 #include <stdexcept>
2 
3 #include <boost/endian/conversion.hpp>
4 
6 
7 namespace ixblue_stdbin_decoder
8 {
9 
10 void MemoryBlockParser::parse(boost::asio::const_buffer& buffer, const tBitMask& mask,
11  Data::BinaryNav& outBinaryNav)
12 {
13  // If this memory block is present in the frame,
14  if(mask.test(offsetInMask))
15  {
16  // And there is enough bytes in buffer we can parse it :
17  if(boost::asio::buffer_size(buffer) >= bytesCount)
18  {
19  parse(buffer, outBinaryNav);
20  }
21  else
22  {
23  throw std::runtime_error(
24  "Not enough byes in buffer to parse this memory block");
25  }
26  }
27 }
28 
29 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, double& res)
30 {
31  uint64_t bytes = *boost::asio::buffer_cast<const uint64_t*>(buf);
32  boost::endian::big_to_native_inplace(bytes);
33  std::memcpy(&res, &bytes, sizeof(double));
34  buf = buf + sizeof(double);
35  return buf;
36 }
37 
38 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, float& res)
39 {
40  uint32_t bytes = *boost::asio::buffer_cast<const uint32_t*>(buf);
41  boost::endian::big_to_native_inplace(bytes);
42  std::memcpy(&res, &bytes, sizeof(float));
43  buf = buf + sizeof(float);
44  return buf;
45 }
46 
47 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, int32_t& res)
48 {
49  res = *boost::asio::buffer_cast<const int32_t*>(buf);
50  boost::endian::big_to_native_inplace(res);
51  buf = buf + sizeof(int32_t);
52  return buf;
53 }
54 
55 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, uint64_t& res)
56 {
57  res = *boost::asio::buffer_cast<const uint64_t*>(buf);
58  boost::endian::big_to_native_inplace(res);
59  buf = buf + sizeof(uint64_t);
60  return buf;
61 }
62 
63 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, uint32_t& res)
64 {
65  res = *boost::asio::buffer_cast<const uint32_t*>(buf);
66  boost::endian::big_to_native_inplace(res);
67  buf = buf + sizeof(uint32_t);
68  return buf;
69 }
70 
71 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, uint16_t& res)
72 {
73  res = *boost::asio::buffer_cast<const uint16_t*>(buf);
74  boost::endian::big_to_native_inplace(res);
75  buf = buf + sizeof(uint16_t);
76  return buf;
77 }
78 
79 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, uint8_t& res)
80 {
81  res = *boost::asio::buffer_cast<const uint8_t*>(buf);
82  buf = buf + sizeof(uint8_t);
83  return buf;
84 }
85 
86 } // namespace ixblue_stdbin_decoder
void parse(boost::asio::const_buffer &buffer, const tBitMask &mask, Data::BinaryNav &outBinaryNav)
boost::asio::const_buffer & operator>>(boost::asio::const_buffer &buf, std::array< uint8_t, N > &res)


ixblue_stdbin_decoder
Author(s): Adrien BARRAL , Laure LEBROTON
autogenerated on Sat Jan 9 2021 03:13:21