sequenced_data_item.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_SEQUENCED_DATA_ITEM_H
27 #define ODVA_ETHERNETIP_SEQUENCED_DATA_ITEM_H
28 
29 #include <string>
30 
35 
36 namespace eip {
37 
38 using std::string;
39 using serialization::Serializable;
40 using serialization::Reader;
41 using serialization::Writer;
42 
48 template <class T>
49 class SequencedDataItem : public T
50 {
51 public:
53 
54  SequencedDataItem(EIP_UINT sequence = 0) : sequence_num(sequence), already_deserializing(false) { }
55 
60  virtual size_t getLength() const
61  {
62  return sizeof(sequence_num) + T::getLength();
63  }
64 
71  virtual Writer& serialize(Writer& writer) const
72  {
73  writer.write(sequence_num);
74  return T::serialize(writer);
75  }
76 
80  virtual Reader& deserialize(Reader& reader, size_t length)
81  {
82  if (already_deserializing) return T::deserialize(reader, length - sizeof(sequence_num));
83  reader.read(sequence_num);
84  already_deserializing = true;
85  T::deserialize(reader, length - sizeof(sequence_num));
86  already_deserializing = false;
87  return reader;
88  }
89 
96  virtual Reader& deserialize(Reader& reader)
97  {
98  if (already_deserializing) return T::deserialize(reader);
99  reader.read(sequence_num);
100  already_deserializing = true;
101  T::deserialize(reader);
102  already_deserializing = false;
103  return reader;
104  }
105 
106 private:
107  // TODO: this is a total hack, and probably shows that this approach isn't working
109 };
110 
111 } // namespace eip
112 
113 #endif // ODVA_ETHERNETIP_SEQUENCED_DATA_ITEM_H
SequencedDataItem(EIP_UINT sequence=0)
virtual size_t getLength() const
virtual Reader & deserialize(Reader &reader)
virtual Reader & deserialize(Reader &reader, size_t length)
Definition: connection.h:41
uint16_t EIP_UINT
Definition: eip_types.h:39
virtual Writer & serialize(Writer &writer) const


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