<div dir="ltr"><div>Hi,</div><div>Any update on this? I have tried following way in wireDecode but still getting error.</div><div>        <span style="font-family:monospace,monospace">val = m_wire.find(tlv::MyVector);<br>    uint8_t* temp = reinterpret_cast<uint8_t*>(val->value(), val->size());<br>    stringstream ss;<br>    ss << temp;<br>    boost::archive::binary_iarchive ia(ss);<br>    std::vector<std::string> myTempVector;<br>    ia >> <span style="font-family:monospace,monospace">myTempVector</span>;<br>    <span style="font-family:monospace,monospace">m_MyVector</span> = <span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace">myTempVector</span></span>;</span></div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">Following error occurs:</span></div><div><span style="font-family:monospace,monospace">error: ‘class std::vector<std::__cxx11::basic_string<char> >’ has no member named ‘serialize’<br>         t.serialize(ar, file_version);</span><br></div><div><br></div><div>Can anyone suggest a better/complete solution of my problem?<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 22 May 2018 at 23:34, Mudasir Qazi <<a href="mailto:mudasirqazi00@gmail.com">mudasirqazi00@gmail.com</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"><div>Hi,</div><div>I have tried the solution you suggested. The serialization/deserialization of a vector to .txt file is not much difficult. I have practiced it in separate file and it works fine. I have created a vector and serialized it into a .txt file, than I read same .txt file and saved the data in a separate vector. I have done this using <span style="font-family:monospace,monospace">ifstream</span> and <span style="font-family:monospace,monospace">ofstream</span> as most of the solutions on Internet have suggested. All this works.</div><div><br></div><div>But in the scenario of ndnSIM, I am unable to related it. Because in practice work we have <span style="font-family:monospace,monospace">ifstream</span> to be deserialized into a vector<span style="font-family:monospace,monospace"></span>, while in <span style="font-family:monospace,monospace">wireDecode</span> method of <span style="font-family:monospace,monospace">interest.cpp</span> file we have <span style="font-family:monospace,monospace">Block::element_const_iterator</span> type of <span style="font-family:monospace,monospace">val</span> initialized by statement <span style="font-family:monospace,monospace">val = m_wire.find(tlv::MyVector)</span>. Now I don't understand how can I treat <span style="font-family:monospace,monospace">Block::element_const_iterator</span> as <span style="font-family:monospace,monospace">ifstream</span> to get it deserialized.</div><div><br></div><div>Please help me and suggest further what should I do to achieve this. <br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 22 May 2018 at 18:10, Mudasir Qazi <<a href="mailto:mudasirqazi00@gmail.com" target="_blank">mudasirqazi00@gmail.com</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">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" target="_blank">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="m_2079307609389373927m_-3595387526649982000gmail_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></blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="m_2079307609389373927gmail_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></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>