cpf_item.cpp
Go to the documentation of this file.
00001 
00025 #include <boost/make_shared.hpp>
00026 
00027 #include "odva_ethernetip/cpf_item.h"
00028 #include "odva_ethernetip/serialization/serializable_buffer.h"
00029 #include "odva_ethernetip/serialization/copy_serializable.h"
00030 
00031 using boost::make_shared;
00032 
00033 namespace eip {
00034 
00035 using serialization::SerializableBuffer;
00036 
00037 Writer& CPFItem::serialize(Writer& writer) const
00038 {
00039   writer.write(item_type_);
00040   writer.write(getDataLength());
00041   if (item_data_) {
00042     item_data_->serialize(writer);
00043   }
00044   return writer;
00045 }
00046 
00047 Reader& CPFItem::deserialize(Reader& reader, size_t length)
00048 {
00049   if (length < 4)
00050   {
00051     throw std::length_error("Length given too small to parse CPF Item type and length");
00052   }
00053   EIP_UINT item_length;
00054   reader.read(item_type_);
00055   reader.read(item_length);
00056   if (length < item_length + 4)
00057   {
00058     throw std::length_error("Length given too small to parse CPF Item Data");
00059   }
00060   deserializeData(reader, item_length);
00061   return reader;
00062 }
00063 
00064 Reader& CPFItem::deserialize(Reader& reader)
00065 {
00066   EIP_UINT item_length;
00067   reader.read(item_type_);
00068   reader.read(item_length);
00069   deserializeData(reader, item_length);
00070   return reader;
00071 }
00072 
00073 void CPFItem::deserializeData(Reader& reader, EIP_UINT item_length)
00074 {
00075   if (item_length > 0)
00076   {
00077     item_data_ = make_shared<SerializableBuffer>();
00078     item_data_->deserialize(reader, item_length);
00079   }
00080   else
00081   {
00082     item_data_ = shared_ptr<Serializable>();
00083   }
00084 }
00085 
00086 void CPFItem::getDataAs(Serializable& result)
00087 {
00088   serialization::copy_serializable(result, *item_data_);
00089 }
00090 
00091 } // namespace eip


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Sat Jun 8 2019 20:21:23