///The fields in the class are
uint16_t m_id;
uint8_t m_reserved;
Ipv4Address m_local;
Ipv4Address m_source;
double m_x;
double m_y;
double m_xVel;
double m_yVel;
double m_x1;
double m_y1;
double m_x2;
double m_y2;
uint16_t m_initialTime;
uint16_t m_duration;
std::string m_message;
uint32_t
DataHeader::GetSerializedSize () const
{
return 79 + m_message.length() + 1; // 79 bytes for fields and 1 for string terminal ('\0')
}
void
DataHeader::Serialize (Buffer::Iterator i) const
{
Buffer::Iterator start = i;
i.WriteU16 (m_id);
i.WriteU8 (m_reserved);
WriteTo (i, m_local);
WriteTo (i, m_source);
i.WriteHtonU64 (m_x);
i.WriteHtonU64 (m_y);
i.WriteHtonU64 (m_xVel);
i.WriteHtonU64 (m_yVel);
i.WriteHtonU64 (m_x1);
i.WriteHtonU64 (m_y1);
i.WriteHtonU64 (m_x2);
i.WriteHtonU64 (m_y2);
i.WriteU16 (m_initialTime);
i.WriteU16 (m_duration);
char tmpBuffer [m_message.length() + 1];
strcpy (tmpBuffer, m_message.c_str());
i.Write ((uint8_t *)tmpBuffer, strlen(tmpBuffer) + 1);
}
uint32_t
DataHeader::Deserialize (Buffer::Iterator start)
{
Buffer::Iterator i = start;
m_id = i.ReadU16 ();
m_reserved = i.ReadU8 ();
ReadFrom (i, m_local);
ReadFrom (i, m_source);
m_x = i.ReadNtohU64 ();
m_y = i.ReadNtohU64 ();
m_xVel = i.ReadNtohU64 ();
m_yVel = i.ReadNtohU64 ();
m_x1 = i.ReadNtohU64 ();
m_y1 = i.ReadNtohU64 ();
m_x2 = i.ReadNtohU64 ();
m_y2 = i.ReadNtohU64 ();
m_initialTime = i.ReadU16 ();
m_duration = i.ReadU16 ();
uint8_t c;
uint32_t len = 0;
Buffer::Iterator i2 = i;
do
{
c = i2.ReadU8 ();
len++;
} while (c != 0);
char tmpBuffer [len];
start.Read ((uint8_t*)tmpBuffer, len);
m_message = tmpBuffer;
uint32_t dist = i.GetDistanceFrom (start);
NS_ASSERT (dist == GetSerializedSize ());
return dist;
}
m_message
and len variables I can see that it just reads 1 until the while condition it's satisfied and m_message gets garbage like this: Âôìûÿ start.Read ((uint8_t*)tmpBuffer, len);
i.Read ((uint8_t*)tmpBuffer, len);
--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.