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

Mudasir Qazi mudasirqazi00 at gmail.com
Tue May 22 06:10:38 PDT 2018


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndnsim/attachments/20180522/8bc02f5a/attachment.html>


More information about the ndnSIM mailing list