buffer_writer.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_SERIALIZATION_BUFFER_WRITER_H
27 #define ODVA_ETHERNETIP_SERIALIZATION_BUFFER_WRITER_H
28 
29 #include <stdexcept>
30 #include <boost/asio.hpp>
31 
34 
35 using boost::asio::const_buffer;
36 using boost::asio::mutable_buffer;
37 
38 namespace eip {
39 namespace serialization {
40 
44 class BufferWriter : public Writer
45 {
46 public:
47 
52  BufferWriter(mutable_buffer buf) : buf_(buf), byte_count_(0) { }
53 
61  void writeBytes(const void* p, size_t n)
62  {
63  writeBuffer(boost::asio::buffer(p, n));
64  }
65 
74  void writeBuffer(const_buffer b)
75  {
76  using boost::asio::buffer_size;
77  if (buffer_size(buf_) < buffer_size(b))
78  {
79  throw std::length_error("Buffer to small to serialize value");
80  }
81  boost::asio::buffer_copy(buf_, b);
82  byte_count_ += buffer_size(b);
83  buf_ = buf_ + buffer_size(b);
84  }
85 
90  size_t getByteCount()
91  {
92  return byte_count_;
93  }
94 
95 private:
96  mutable_buffer buf_;
97  size_t byte_count_;
98 };
99 
100 } // namespace serialization
101 } // namespace eip
102 #endif // ODVA_ETHERNETIP_SERIALIZATION_BUFFER_WRITER_H
BufferWriter(mutable_buffer buf)
Definition: buffer_writer.h:52
void writeBytes(const void *p, size_t n)
Definition: buffer_writer.h:61
void writeBuffer(const_buffer b)
Definition: buffer_writer.h:74
Definition: connection.h:41


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Mon Jun 10 2019 14:00:16