<div dir="ltr">Mudasir,<div><br></div><div>I think Junxiao is saying that you can't just prepend the vector directly.  You have to prepare the vector for transport just like you'd prepare it for file I/O.  In other words, it needs serialized.  So if you can prepend the size of the vector, and then prepend all the items in the vector individually, you can reconstruct the vector later on with that information, just like you would with a file.</div><div><br></div><div>At least, I believe this is what Junxiao was saying.</div><div><br></div><div>Thanks!</div><div><br></div><div>John</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 24, 2018 at 3:22 PM, Mudasir Qazi <span dir="ltr"><<a href="mailto:mudasirqazi00@gmail.com" target="_blank">mudasirqazi00@gmail.com</a>></span> wrote:<br><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>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*>(<wbr>val->value(), val->size());<br>    stringstream ss;<br>    ss << temp;<br>    boost::archive::binary_<wbr>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::<wbr>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><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Tue, 22 May 2018 at 23:34, 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"><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_<wbr>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*>(&<wbr>myTempVector), sizeof(myTempVector));<br>    totalLength += encoder.prependVarNumber(<wbr>sizeof(myTempVector));<br>    totalLength += encoder.prependVarNumber(tlv::<wbr>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("<wbr>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">m<wbr>yTemVector</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_-7839682614618572032m_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_-7839682614618572032m_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></div></div><span class="HOEnZb"><font color="#888888">-- <br><div dir="ltr" class="m_-7839682614618572032gmail_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>
</font></span><br>______________________________<wbr>_________________<br>
ndnSIM mailing list<br>
<a href="mailto:ndnSIM@lists.cs.ucla.edu">ndnSIM@lists.cs.ucla.edu</a><br>
<a href="http://www.lists.cs.ucla.edu/mailman/listinfo/ndnsim" rel="noreferrer" target="_blank">http://www.lists.cs.ucla.edu/<wbr>mailman/listinfo/ndnsim</a><br>
<br></blockquote></div><br></div>