encap_packet.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_ENCAP_PACKET_H
27 #define ODVA_ETHERNETIP_ENCAP_PACKET_H
28 
29 #include <boost/shared_ptr.hpp>
30 
32 
37 
38 
39 using boost::shared_ptr;
40 
41 namespace eip {
42 
43 using serialization::Serializable;
44 using serialization::Reader;
45 using serialization::Writer;
46 
50 class EncapPacket : public Serializable
51 {
52 public:
53 
57  EncapPacket(EIP_UINT command = 0, EIP_UDINT session_handle = 0)
58  : header_(command, session_handle) { }
59 
66  EncapPacket(EIP_UINT command, EIP_UDINT session_handle,
67  shared_ptr<Serializable> payload)
68  : header_(command, session_handle), payload_(payload)
69  {
70  updateLength();
71  }
72 
73 
79  {
80  return header_;
81  }
82 
87  shared_ptr<Serializable> getPayload() const
88  {
89  return payload_;
90  }
91 
96  void setPayload(shared_ptr<Serializable> payload)
97  {
98  payload_ = payload;
99  updateLength();
100  }
101 
106  void getPayloadAs(Serializable& result);
107 
112  size_t getLength() const
113  {
114  size_t l = header_.getLength();
115  if (NULL != payload_)
116  {
117  l += payload_->getLength();
118  }
119  return l;
120  }
121 
127  {
128  header_.length = payload_ ? payload_->getLength() : 0;
129  }
130 
136  Writer& serialize(Writer& writer) const;
137 
145  Reader& deserialize(Reader& reader, size_t length);
146 
153  Reader& deserialize(Reader& reader);
154 
155 private:
157  shared_ptr<Serializable> payload_;
158 };
159 
160 } // namespace eip
161 
162 #endif // ODVA_ETHERNETIP_ENCAP_PACKET_H
encap_header.h
eip::serialization::Writer
Definition: writer.h:41
eip_types.h
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::EncapPacket::setPayload
void setPayload(shared_ptr< Serializable > payload)
Definition: encap_packet.h:96
EIP_UINT
uint16_t EIP_UINT
Definition: eip_types.h:39
eip::EncapHeader::getLength
virtual size_t getLength() const
Definition: encap_header.h:68
eip::EncapPacket::getHeader
EncapHeader & getHeader()
Definition: encap_packet.h:78
eip::EncapPacket::EncapPacket
EncapPacket(EIP_UINT command, EIP_UDINT session_handle, shared_ptr< Serializable > payload)
Definition: encap_packet.h:66
eip::EncapPacket::payload_
shared_ptr< Serializable > payload_
Definition: encap_packet.h:157
eip::EncapPacket::EncapPacket
EncapPacket(EIP_UINT command=0, EIP_UDINT session_handle=0)
Definition: encap_packet.h:57
eip::serialization::Serializable
Definition: serializable.h:38
eip::EncapPacket::getPayload
shared_ptr< Serializable > getPayload() const
Definition: encap_packet.h:87
reader.h
eip::EncapPacket::updateLength
void updateLength()
Definition: encap_packet.h:126
eip::EncapPacket::getPayloadAs
void getPayloadAs(Serializable &result)
Definition: encap_packet.cpp:44
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
Definition: encap_header.h:44
eip::EncapHeader::length
EIP_UINT length
Definition: encap_header.h:48
eip::EncapPacket::getLength
size_t getLength() const
Definition: encap_packet.h:112
eip::EncapPacket
Definition: encap_packet.h:50
EIP_UDINT
uint32_t EIP_UDINT
Definition: eip_types.h:42
serializable.h
writer.h


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