[ndnSIM] How to add additional std::vector<std::string> type field in Interest packet

John Baugh jpbaugh at umich.edu
Fri May 25 00:00:47 PDT 2018


Mudasir,

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.

At least, I believe this is what Junxiao was saying.

Thanks!

John

On Thu, May 24, 2018 at 3:22 PM, Mudasir Qazi <mudasirqazi00 at gmail.com>
wrote:

> Hi,
> Any update on this? I have tried following way in wireDecode but still
> getting error.
>         val = m_wire.find(tlv::MyVector);
>     uint8_t* temp = reinterpret_cast<uint8_t*>(val->value(), val->size());
>     stringstream ss;
>     ss << temp;
>     boost::archive::binary_iarchive ia(ss);
>     std::vector<std::string> myTempVector;
>     ia >> myTempVector;
>     m_MyVector = myTempVector;
>
>
> Following error occurs:
> error: ‘class std::vector<std::__cxx11::basic_string<char> >’ has no
> member named ‘serialize’
>          t.serialize(ar, file_version);
>
> Can anyone suggest a better/complete solution of my problem?
>
>
> On Tue, 22 May 2018 at 23:34, Mudasir Qazi <mudasirqazi00 at gmail.com>
> wrote:
>
>> Hi,
>> 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
>> ifstream and ofstream as most of the solutions on Internet have
>> suggested. All this works.
>>
>> But in the scenario of ndnSIM, I am unable to related it. Because in
>> practice work we have ifstream to be deserialized into a vector, while
>> in wireDecode method of interest.cpp file we have
>> Block::element_const_iterator type of val initialized by statement val =
>> m_wire.find(tlv::MyVector). Now I don't understand how can I treat
>> Block::element_const_iterator as ifstream to get it deserialized.
>>
>> Please help me and suggest further what should I do to achieve this.
>>
>> On Tue, 22 May 2018 at 18:10, Mudasir Qazi <mudasirqazi00 at gmail.com>
>> wrote:
>>
>>> Great catch! Thank you so much sir. I'm doing it right now. Thanks again.
>>>
>>> On Tue, 22 May 2018 at 18:08, Junxiao Shi <shijunxiao at email.arizona.edu>
>>> wrote:
>>>
>>>> Hi Mudasir
>>>>
>>>>
>>>>> //for MyVector
>>>>> std::vector<std::string> myTempVector = this->getMyVector();
>>>>>     totalLength += encoder.prependByteArray(
>>>>>             reinterpret_cast<uint8_t*>(&myTempVector),
>>>>> sizeof(myTempVector));
>>>>>     totalLength += encoder.prependVarNumber(sizeof(myTempVector));
>>>>>     totalLength += encoder.prependVarNumber(tlv::MyVector);
>>>>>
>>>>
>>>>
>>>>> //for MyVector
>>>>> val = m_wire.find(tlv::MyVector);
>>>>> if (val == m_wire.elements_end()) {
>>>>>     BOOST_THROW_EXCEPTION(Error("MyVector element is missing"));
>>>>> }
>>>>> std::vector<std::string> myTemVector;
>>>>> if (val->value_size() != sizeof(myTemVector)) {
>>>>>     BOOST_THROW_EXCEPTION(Error("myTemVector element is malformed"));
>>>>> }
>>>>> std::memcpy(&myTemVector, val->value(), sizeof(myTemVector));
>>>>> m_MyVector = myTemVector;
>>>>>
>>>>> *Problem:* 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 *wireDecode* 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.
>>>>>
>>>>
>>>> You did not serialize <https://en.wikipedia.org/wiki/Serialization>
>>>> the std::vector<std::string>, but merely copied the header structure of
>>>> std::vector<std::string>. Thus, you triggered undefined behavior in STL
>>>> library.
>>>>
>>>> Learn to write the following two programs in C++:
>>>>
>>>>    1. Given a std::vector<std::string>, write it to a file.
>>>>    2. Read the above file into a std::vector<std::string>, and print
>>>>    it on screen.
>>>>
>>>> After you wrote these programs, you can use the same technique to write
>>>> to and read from TLV structures.
>>>>
>>>> Yours, Junxiao
>>>>
>>>
>>>
>>> --
>>> Regards,
>>> Mudasir Qazi
>>>
>>
>>
>> --
>> Regards,
>> Mudasir Qazi
>>
>
>
> --
> Regards,
> Mudasir Qazi
>
> _______________________________________________
> ndnSIM mailing list
> ndnSIM at lists.cs.ucla.edu
> http://www.lists.cs.ucla.edu/mailman/listinfo/ndnsim
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20180525/a594e06e/attachment-0001.html>


More information about the ndnSIM mailing list