<div dir="ltr">Great catch! Thank you so much sir. I'm doing it right now. Thanks again.<br></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 22 May 2018 at 18:08, Junxiao Shi <<a href="mailto:shijunxiao@email.arizona.edu">shijunxiao@email.arizona.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Mudasir<br><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>//for MyVector<br></div><div><span style="font-family:monospace,monospace">std::vector<std::string> myTempVector = this->getMyVector();<br>    totalLength += encoder.prependByteArray(<br>            reinterpret_cast<uint8_t*>(&myTempVector), sizeof(myTempVector));<br>    totalLength += encoder.prependVarNumber(sizeof(myTempVector));<br>    totalLength += encoder.prependVarNumber(tlv::MyVector);</span></div></div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>//for MyVector</div><div><span style="font-family:monospace,monospace">val = m_wire.find(tlv::MyVector);<br>if (val == m_wire.elements_end()) {<br>    BOOST_THROW_EXCEPTION(Error("MyVector element is missing"));<br>}<br>std::vector<std::string> myTemVector;<br>if (val->value_size() != sizeof(myTemVector)) {<br>    BOOST_THROW_EXCEPTION(Error("<span style="font-family:monospace,monospace">myTemVector</span> element is malformed"));<br>}<br>std::memcpy(&myTemVector, val->value(), sizeof(myTemVector));<br>m_MyVector = myTemVector;</span></div><div><br></div><div><b>Problem:</b> I'm following these 1-to-5 steps in order to add an Integer and a std::vector<std::string> fields in Interest packet but it gives an error on <b><span style="font-family:monospace,monospace">wireDecode</span></b> while decoding MyVector field and simulation stops and terminates. But it does not give error on MyInteger field. Am I doing it right? Am I missing something? Please help me solving this I'm stuck on this point from many days.</div></div></blockquote><div><br></div><div>You did not <a href="https://en.wikipedia.org/wiki/Serialization" target="_blank">serialize</a> the std::vector<std::string>, but merely copied the header structure of std::vector<std::string>. Thus, you triggered undefined behavior in STL library.</div><div><br></div><div>Learn to write the following two programs in C++:</div><div><ol><li>Given a std::vector<std::string>, write it to a file.</li><li>Read the above file into a std::vector<std::string>, and print it on screen.</li></ol></div><div>After you wrote these programs, you can use the same technique to write to and read from TLV structures.</div><div><br></div><div>Yours, Junxiao</div></div></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:georgia,serif">Regards,<br></span></div><div><span style="font-family:georgia,serif">Mudasir Qazi<br></span></div></div></div></div></div></div></div></div></div>