00001 00026 #include <boost/make_shared.hpp> 00027 #include <boost/foreach.hpp> 00028 00029 #include "odva_ethernetip/cpf_packet.h" 00030 00031 using boost::make_shared; 00032 00033 namespace eip { 00034 00035 size_t CPFPacket::getLength() const 00036 { 00037 // 2 bytes just for the number of items 00038 size_t l = 2; 00039 BOOST_FOREACH(CPFItem i, items_) 00040 { 00041 l += i.getLength(); 00042 } 00043 return l; 00044 } 00045 00046 Writer& CPFPacket::serialize(Writer& writer) const 00047 { 00048 writer.write(getItemCount()); 00049 BOOST_FOREACH(CPFItem i, items_) 00050 { 00051 i.serialize(writer); 00052 } 00053 return writer; 00054 } 00055 00056 Reader& CPFPacket::deserialize(Reader& reader) 00057 { 00058 items_.clear(); 00059 EIP_UINT num_items; 00060 reader.read(num_items); 00061 for (int i = 0; i < num_items; ++i) 00062 { 00063 CPFItem item; 00064 item.deserialize(reader); 00065 items_.push_back(item); 00066 } 00067 return reader; 00068 } 00069 00070 } // namespace eip