cpf_item.cpp
Go to the documentation of this file.
1 
25 #include <boost/make_shared.hpp>
26 
30 
31 using boost::make_shared;
32 
33 namespace eip {
34 
35 using serialization::SerializableBuffer;
36 
37 Writer& CPFItem::serialize(Writer& writer) const
38 {
39  writer.write(item_type_);
40  writer.write(getDataLength());
41  if (item_data_) {
42  item_data_->serialize(writer);
43  }
44  return writer;
45 }
46 
47 Reader& CPFItem::deserialize(Reader& reader, size_t length)
48 {
49  if (length < 4)
50  {
51  throw std::length_error("Length given too small to parse CPF Item type and length");
52  }
53  EIP_UINT item_length;
54  reader.read(item_type_);
55  reader.read(item_length);
56  if (length < item_length + 4)
57  {
58  throw std::length_error("Length given too small to parse CPF Item Data");
59  }
60  deserializeData(reader, item_length);
61  return reader;
62 }
63 
64 Reader& CPFItem::deserialize(Reader& reader)
65 {
66  EIP_UINT item_length;
67  reader.read(item_type_);
68  reader.read(item_length);
69  deserializeData(reader, item_length);
70  return reader;
71 }
72 
73 void CPFItem::deserializeData(Reader& reader, EIP_UINT item_length)
74 {
75  if (item_length > 0)
76  {
77  item_data_ = make_shared<SerializableBuffer>();
78  item_data_->deserialize(reader, item_length);
79  }
80  else
81  {
82  item_data_ = shared_ptr<Serializable>();
83  }
84 }
85 
86 void CPFItem::getDataAs(Serializable& result)
87 {
89 }
90 
91 } // namespace eip
EIP_UINT item_type_
Definition: cpf_item.h:151
virtual EIP_UINT getDataLength() const
Definition: cpf_item.h:111
virtual Writer & serialize(Writer &writer) const
Definition: cpf_item.cpp:37
void copy_serializable(Serializable &dst, const Serializable &src)
Definition: connection.h:41
virtual Reader & deserialize(Reader &reader, size_t length)
Definition: cpf_item.cpp:47
uint16_t EIP_UINT
Definition: eip_types.h:39
void getDataAs(Serializable &result)
Definition: cpf_item.cpp:86
void deserializeData(Reader &reader, EIP_UINT item_length)
Definition: cpf_item.cpp:73
shared_ptr< Serializable > item_data_
Definition: cpf_item.h:152


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