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
eip::serialization::Writer
Definition: writer.h:41
eip_types.h
eip
Definition: connection.h:41
eip::serialization::BufferWriter
Definition: buffer_writer.h:44
eip::serialization::BufferWriter::BufferWriter
BufferWriter(mutable_buffer buf)
Definition: buffer_writer.h:52
eip::serialization::BufferWriter::byte_count_
size_t byte_count_
Definition: buffer_writer.h:97
eip::serialization::BufferWriter::writeBuffer
void writeBuffer(const_buffer b)
Definition: buffer_writer.h:74
eip::serialization::BufferWriter::buf_
mutable_buffer buf_
Definition: buffer_writer.h:96
eip::serialization::BufferWriter::getByteCount
size_t getByteCount()
Definition: buffer_writer.h:90
eip::serialization::BufferWriter::writeBytes
void writeBytes(const void *p, size_t n)
Definition: buffer_writer.h:61
writer.h


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Wed Mar 2 2022 00:38:55