include
odva_ethernetip
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
31
#include "
odva_ethernetip/eip_types.h
"
32
#include "
odva_ethernetip/serialization/reader.h
"
33
#include "
odva_ethernetip/serialization/writer.h
"
34
#include "
odva_ethernetip/serialization/serializable.h
"
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
:
52
EIP_UINT
sequence_num
;
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
108
bool
already_deserializing
;
109
};
110
111
}
// namespace eip
112
113
#endif // ODVA_ETHERNETIP_SEQUENCED_DATA_ITEM_H
eip::serialization::Writer
Definition:
writer.h:41
eip_types.h
eip::serialization::Reader
Definition:
reader.h:42
eip
Definition:
connection.h:41
eip::SequencedDataItem::deserialize
virtual Reader & deserialize(Reader &reader)
Definition:
sequenced_data_item.h:96
eip::serialization::Writer::write
void write(const T &v)
Definition:
writer.h:50
EIP_UINT
uint16_t EIP_UINT
Definition:
eip_types.h:39
eip::SequencedDataItem::getLength
virtual size_t getLength() const
Definition:
sequenced_data_item.h:60
eip::SequencedDataItem::deserialize
virtual Reader & deserialize(Reader &reader, size_t length)
Definition:
sequenced_data_item.h:80
eip::SequencedDataItem
Definition:
sequenced_data_item.h:49
eip::serialization::Reader::read
void read(T &v)
Definition:
reader.h:51
eip::SequencedDataItem::already_deserializing
bool already_deserializing
Definition:
sequenced_data_item.h:108
reader.h
eip::SequencedDataItem::sequence_num
EIP_UINT sequence_num
Definition:
sequenced_data_item.h:52
eip::SequencedDataItem::SequencedDataItem
SequencedDataItem(EIP_UINT sequence=0)
Definition:
sequenced_data_item.h:54
eip::SequencedDataItem::serialize
virtual Writer & serialize(Writer &writer) const
Definition:
sequenced_data_item.h:71
serializable.h
writer.h
odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Wed Mar 2 2022 00:38:56