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 
45 {
47 }
48 
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 
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
eip::serialization::Writer
Definition: writer.h:41
eip::EncapPacket::serialize
Writer & serialize(Writer &writer) const
Definition: encap_packet.cpp:49
eip::serialization::Reader
Definition: reader.h:42
eip
Definition: connection.h:41
eip::EncapHeader::getLength
virtual size_t getLength() const
Definition: encap_header.h:68
eip::EncapPacket::payload_
shared_ptr< Serializable > payload_
Definition: encap_packet.h:157
buffer_writer.h
eip::serialization::Serializable
Definition: serializable.h:38
eip::serialization::copy_serializable
void copy_serializable(Serializable &dst, const Serializable &src)
Definition: copy_serializable.cpp:34
eip::EncapPacket::getPayloadAs
void getPayloadAs(Serializable &result)
Definition: encap_packet.cpp:44
eip::EncapHeader::deserialize
virtual Reader & deserialize(Reader &reader, size_t length)
Definition: encap_header.h:89
buffer_reader.h
encap_packet.h
serializable_buffer.h
eip::EncapPacket::deserialize
Reader & deserialize(Reader &reader, size_t length)
Definition: encap_packet.cpp:77
eip::EncapPacket::header_
EncapHeader header_
Definition: encap_packet.h:156
eip::EncapHeader::length
EIP_UINT length
Definition: encap_header.h:48
copy_serializable.h
eip::EncapHeader::serialize
virtual Writer & serialize(Writer &writer) const
Definition: encap_header.cpp:35


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