copy_serializable.cpp
Go to the documentation of this file.
1 
30 
31 namespace eip {
32 namespace serialization {
33 
35 {
36  // check if this is SerializableBuffer to avoid unnecessary copy
37  const SerializableBuffer* src_sb = dynamic_cast<const SerializableBuffer*>(&src);
38  SerializableBuffer* dst_sb = dynamic_cast<SerializableBuffer*>(&dst);
39  if (src_sb)
40  {
41  if (dst_sb)
42  {
43  (*dst_sb) = (*src_sb);
44  }
45  else
46  {
47  BufferReader reader(src_sb->getData());
48  dst.deserialize(reader, src_sb->getLength());
49  }
50  return;
51  }
52  else if (dst_sb)
53  {
54  // cannot serialize to a SerializableBuffer, since it will attempt not to
55  // copy the buffer but just return to it.
56  // This should never be required in practice. Not implementing yet
57  // TODO: fix if actually ever needed
58  throw std::logic_error("Cannot get payload from Serializable to SerializableBuffer");
59  }
60  else
61  {
62  // must serialize and then deserialize again
63  size_t length = src.getLength();
64  std::vector<char> buf(length);
65  BufferWriter writer(buffer(buf));
66  src.serialize(writer);
67  BufferReader reader(buffer(buf));
68  dst.deserialize(reader, length);
69  }
70 }
71 
72 } // namespace serialization
73 } // namespace eip
virtual Reader & deserialize(Reader &reader, size_t length)=0
void copy_serializable(Serializable &dst, const Serializable &src)
Definition: connection.h:41
virtual mutable_buffer getData() const
virtual size_t getLength() const =0
virtual Writer & serialize(Writer &writer) const =0


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