encap_packet.cpp
Go to the documentation of this file.
1 
26 #include <vector>
27 #include <boost/make_shared.hpp>
28 
34 
35 using std::vector;
36 using boost::make_shared;
37 
38 namespace eip {
39 
40 using serialization::SerializableBuffer;
41 using serialization::BufferReader;
42 using serialization::BufferWriter;
43 
44 void EncapPacket::getPayloadAs(Serializable& result)
45 {
47 }
48 
49 Writer& EncapPacket::serialize(Writer& writer) const
50 {
51  // fixme: need to set length before this!
52  // header_.length = (NULL == payload_) ? 0 : payload_->getLength();
53  header_.serialize(writer);
54  if (payload_)
55  {
56  payload_->serialize(writer);
57  }
58  return writer;
59 }
60 
61 Reader& EncapPacket::deserialize(Reader& reader)
62 {
63  header_.deserialize(reader);
64  if (header_.length > 0)
65  {
66  shared_ptr<SerializableBuffer> sb = make_shared<SerializableBuffer>();
67  sb->deserialize(reader, header_.length);
68  payload_ = sb;
69  }
70  else
71  {
72  payload_ = shared_ptr<Serializable>();
73  }
74  return reader;
75 }
76 
77 Reader& EncapPacket::deserialize(Reader& reader, size_t length)
78 {
79  if (length < header_.getLength())
80  {
81  throw std::length_error("Deserialization size less than header size");
82  }
83  header_.deserialize(reader);
84  if (length != header_.getLength() + header_.length)
85  {
86  throw std::length_error("Packet length different than given to deserialize");
87  }
88  if (header_.length > 0)
89  {
90  payload_ = make_shared<SerializableBuffer>();
91  payload_->deserialize(reader, header_.length);
92  }
93  else
94  {
95  payload_ = shared_ptr<Serializable>();
96  }
97  return reader;
98 }
99 
100 } // namespace eip
Writer & serialize(Writer &writer) const
virtual Writer & serialize(Writer &writer) const
virtual size_t getLength() const
Definition: encap_header.h:68
Reader & deserialize(Reader &reader, size_t length)
shared_ptr< Serializable > payload_
Definition: encap_packet.h:157
void copy_serializable(Serializable &dst, const Serializable &src)
void getPayloadAs(Serializable &result)
Definition: connection.h:41
EncapHeader header_
Definition: encap_packet.h:156
virtual Reader & deserialize(Reader &reader, size_t length)
Definition: encap_header.h:89


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