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
EncapHeader & getHeader()
Definition: encap_packet.h:78
Writer & serialize(Writer &writer) const
virtual size_t getLength() const
Definition: encap_header.h:68
size_t getLength() const
Definition: encap_packet.h:112
Reader & deserialize(Reader &reader, size_t length)
shared_ptr< Serializable > payload_
Definition: encap_packet.h:157
shared_ptr< Serializable > getPayload() const
Definition: encap_packet.h:87
void setPayload(shared_ptr< Serializable > payload)
Definition: encap_packet.h:96
void getPayloadAs(Serializable &result)
Definition: connection.h:41
uint16_t EIP_UINT
Definition: eip_types.h:39
uint32_t EIP_UDINT
Definition: eip_types.h:42
EncapPacket(EIP_UINT command, EIP_UDINT session_handle, shared_ptr< Serializable > payload)
Definition: encap_packet.h:66
EncapPacket(EIP_UINT command=0, EIP_UDINT session_handle=0)
Definition: encap_packet.h:57
EncapHeader header_
Definition: encap_packet.h:156


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