message_router_response.cpp
Go to the documentation of this file.
00001 
00026 #include <boost/make_shared.hpp>
00027 
00028 #include "odva_ethernetip/message_router_response.h"
00029 #include "odva_ethernetip/serialization/serializable_buffer.h"
00030 
00031 using boost::make_shared;
00032 
00033 namespace eip {
00034 
00035 using serialization::SerializableBuffer;
00036 
00037 size_t MessageRouterResponse::getLength() const
00038 {
00039   size_t result = sizeof(service) + sizeof(EIP_USINT) + sizeof(general_status)
00040     + sizeof(EIP_USINT);
00041   if (additional_status_)
00042   {
00043     result += additional_status_->getLength();
00044   }
00045   if (response_data_)
00046   {
00047     result += response_data_->getLength();
00048   }
00049   return result;
00050 }
00051 
00052 Reader& MessageRouterResponse::deserialize(Reader& reader, size_t length)
00053 {
00054   reader.read(service);
00055   // read the general status twice to skip the reserved data
00056   reader.read(general_status);
00057   reader.read(general_status);
00058   EIP_USINT additional_status_length;
00059   reader.read(additional_status_length);
00060   additional_status_ = readData(reader, (size_t)2*additional_status_length);
00061   response_data_ = readData(reader, length - reader.getByteCount());
00062   return reader;
00063 }
00064 
00065 shared_ptr<Serializable> MessageRouterResponse::readData(Reader& reader, int length)
00066 {
00067   shared_ptr<SerializableBuffer> sb;
00068   if (length > 0)
00069   {
00070     sb = make_shared<SerializableBuffer>();
00071     sb->deserialize(reader, length);
00072   }
00073   return sb;
00074 }
00075 
00076 } // namespace eip


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