diff --git a/src/node/address.cc b/src/node/address.cc index fb49bf8ce..1902324d9 100644 --- a/src/node/address.cc +++ b/src/node/address.cc @@ -114,21 +114,20 @@ Address::GetSerializedSize (void) const } void -Address::Serialize (uint8_t* buf, uint32_t len) const +Address::Serialize (TagBuffer buffer) const { - NS_ASSERT (len >= static_cast (m_len + 2)); - buf[0] = m_type; - buf[1] = m_len; - for (uint8_t i = 0; i < m_len; i++) - { - buf[i+2] = m_data[i]; - } + buffer.WriteU8 (m_type); + buffer.WriteU8 (m_len); + buffer.Write (m_data, m_len); } -Address -Address::Deserialize (const uint8_t* buf) +void +Address::Deserialize (TagBuffer buffer) { - return Address (buf[0], buf + 2, buf[1]); + m_type = buffer.ReadU8 (); + m_len = buffer.ReadU8 (); + NS_ASSERT (m_len <= MAX_SIZE); + buffer.Read (m_data, m_len); } ATTRIBUTE_HELPER_CPP (Address); diff --git a/src/node/address.h b/src/node/address.h index 16a8dc555..d88d5643d 100644 --- a/src/node/address.h +++ b/src/node/address.h @@ -5,6 +5,7 @@ #include #include "ns3/attribute.h" #include "ns3/attribute-helper.h" +#include "ns3/tag-buffer.h" namespace ns3 { @@ -166,14 +167,14 @@ public: * \param buf output buffer that gets written with this Address * \param len length of output buffer */ - void Serialize (uint8_t* buf, uint32_t len) const; + void Serialize (TagBuffer buffer) const; /** * \param buf buffer to read address from * \returns an Address * * The input address buffer is expected to be in host byte order format. */ - static Address Deserialize (const uint8_t* buf); + void Deserialize (TagBuffer buffer); private: friend bool operator == (const Address &a, const Address &b); diff --git a/src/node/socket.cc b/src/node/socket.cc index 18a15b0e9..0a9aabc42 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -304,27 +304,12 @@ SocketRxAddressTag::GetSerializedSize (void) const void SocketRxAddressTag::Serialize (TagBuffer i) const { - uint8_t len = m_address.GetSerializedSize (); - uint8_t* buffer = new uint8_t[len]; - memset (buffer, 0, len); - m_address.Serialize (buffer, len); - i.Write (buffer, len); - delete [] buffer; + m_address.Serialize (i); } void SocketRxAddressTag::Deserialize (TagBuffer i) { - uint8_t type = i.ReadU8 (); - uint8_t len = i.ReadU8 (); - // Len is the length of the address starting from buffer[2] - NS_ASSERT (len >= 2); - uint8_t* buffer = new uint8_t[len]; - memset (buffer, 0, len); - buffer[0] = type; - buffer[1] = len; - i.Read (buffer+2, len); // ReadU8 consumes a byte - m_address = Address::Deserialize (buffer); - delete [] buffer; + m_address.Deserialize (i); } SocketIpTtlTag::SocketIpTtlTag ()