37 #include <arpa/inet.h> 40 serializations_(msgs.size(),
std::string()),
41 vectorIO_(msgs.size() * 2 + 1,iovec()),
45 ControlMessages::const_iterator iter = msgs.begin();
47 controlMessageSerializerHeader_.
u16Count_ = htons(msgs.size());
49 vectorIO_[0].iov_base = &controlMessageSerializerHeader_;
50 length_ += vectorIO_[0].iov_len;
52 for(
int i = 0; iter != msgs.end(); ++iter,++i)
54 (*iter)->serialize().swap(serializations_[i]);
55 controlMessageHeaders_[i].u16Id_ = htons((*iter)->getId());
56 controlMessageHeaders_[i].u16Length_ = htons(serializations_[i].length());
59 vectorIO_[i*2+1].iov_base = &controlMessageHeaders_[i];
60 length_ += vectorIO_[i*2+1].iov_len;
62 vectorIO_[i*2 + 2].iov_len = serializations_[i].length();
63 vectorIO_[i*2 + 2].iov_base =
const_cast<char *
>(serializations_[i].c_str());
64 length_ += vectorIO_[i*2+2].iov_len;
90 std::uint16_t u16ControlMessageCount =
91 ntohs(pControlMessageSerializerHeader->
u16Count_);
98 for(
int i = 0; i < u16ControlMessageCount; ++i)
104 std::uint16_t u16ControlMessageId = ntohs(pControlMessageHeader->
u16Id_);
105 std::uint16_t u16ControlMessageLength = ntohs(pControlMessageHeader->
u16Length_);
107 if(length >= u16ControlMessageLength)
110 pControlMessageHeader->
data_,
111 u16ControlMessageLength));
113 length -= u16ControlMessageLength;
121 pControlMessageHeader =
123 u16ControlMessageLength);
138 return controlMessages;
146 if(!vectorIO.empty())
153 std::uint16_t u16ControlMessageCount =
154 ntohs(pControlMessageSerializerHeader->
u16Count_);
157 if(u16ControlMessageCount <= (vectorIO.size() - 1) / 2)
159 for(
int i = 0; i < u16ControlMessageCount; ++i)
166 std::uint16_t u16ControlMessageId = ntohs(pControlMessageHeader->
u16Id_);
167 std::uint16_t u16ControlMessageLength = ntohs(pControlMessageHeader->
u16Length_);
170 if(vectorIO[i*2 + 2].iov_len == u16ControlMessageLength)
173 vectorIO[i*2 + 2].iov_base,
174 u16ControlMessageLength));
198 return controlMessages;
ControlMessageSerializer(const ControlMessages &msgs)
std::list< const ControlMessage * > ControlMessages
std::vector< iovec > VectorIO
static ControlMessages create(const void *pData, size_t length)
~ControlMessageSerializer()
static SerializedControlMessage * create(ControlMessageId id, const void *pData, size_t length)
const Utils::VectorIO & getVectorIO() const
Exception thrown to indicate a serialization or deserialization error.