memory_block_parser.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <bitset>
5 #include <boost/asio/buffer.hpp>
6 #include <boost/core/noncopyable.hpp>
7 #include <boost/optional.hpp>
8 #include <memory>
9 
10 namespace ixblue_stdbin_decoder
11 {
12 
13 template<size_t N>
14 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf,
15  std::array<uint8_t, N>& res)
16 {
17  for(auto& b : res)
18  {
19  const auto byte = boost::asio::buffer(buf, 1);
20  b = *boost::asio::buffer_cast<const uint8_t*>(byte);
21  buf = buf + sizeof(uint8_t);
22  }
23  return buf;
24 }
25 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, double& res);
26 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, float& res);
27 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, int32_t& res);
28 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, uint64_t& res);
29 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, uint32_t& res);
30 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, uint16_t& res);
31 boost::asio::const_buffer& operator>>(boost::asio::const_buffer& buf, uint8_t& res);
32 
33 class MemoryBlockParser : private boost::noncopyable
34 {
35  MemoryBlockParser() = delete; // ensure that offsetInMask will always be set.
36 public:
37  typedef std::bitset<32> tBitMask;
39  : offsetInMask(offsetInMask), bytesCount(bytesCount)
40  {}
41 
42  virtual ~MemoryBlockParser() = default;
43 
44  void parse(boost::asio::const_buffer& buffer, const tBitMask& mask,
45  Data::BinaryNav& outBinaryNav);
46 
47  virtual void parse(boost::asio::const_buffer& buffer,
48  Data::BinaryNav& outBinaryNav) = 0;
49  size_t getOffsetInMask(void) const { return offsetInMask; }
50  size_t getBytesCount(void) const { return bytesCount; }
51 
52 protected:
53  const size_t offsetInMask;
54  const size_t bytesCount;
55 };
56 
57 typedef std::shared_ptr<MemoryBlockParser> MemoryBlockParserPtr;
58 } // namespace ixblue_stdbin_decoder
std::shared_ptr< MemoryBlockParser > MemoryBlockParserPtr
MemoryBlockParser(size_t offsetInMask, size_t bytesCount)
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