Add tag serialize methods; add serialize routines to Address
This commit is contained in:
@@ -107,6 +107,30 @@ Address::Register (void)
|
||||
return type;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Address::GetSerializedSize (void) const
|
||||
{
|
||||
return 1 + 1 + m_len;
|
||||
}
|
||||
|
||||
void
|
||||
Address::Serialize (uint8_t* buf, uint32_t len) const
|
||||
{
|
||||
NS_ASSERT (len >= static_cast<uint32_t> (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];
|
||||
}
|
||||
}
|
||||
|
||||
Address
|
||||
Address::Deserialize (const uint8_t* buf)
|
||||
{
|
||||
return Address (buf[0], buf + 2, buf[1]);
|
||||
}
|
||||
|
||||
ATTRIBUTE_HELPER_CPP (Address);
|
||||
|
||||
|
||||
|
||||
@@ -153,6 +153,27 @@ public:
|
||||
* \returns a new type id.
|
||||
*/
|
||||
static uint8_t Register (void);
|
||||
/**
|
||||
* Get the number of bytes needed to serialize the underlying Address
|
||||
* Typically, this is GetLength () + 2
|
||||
*
|
||||
* \returns the number of bytes required for an Address in serialized form
|
||||
*/
|
||||
uint32_t GetSerializedSize (void) const;
|
||||
/**
|
||||
* Serialize this address in host byte order to a byte buffer
|
||||
*
|
||||
* \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;
|
||||
/**
|
||||
* \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);
|
||||
|
||||
ATTRIBUTE_HELPER_HEADER_1 (Address);
|
||||
private:
|
||||
|
||||
@@ -288,20 +288,35 @@ SocketRxAddressTag::GetInstanceTypeId (void) const
|
||||
{
|
||||
return GetTypeId ();
|
||||
}
|
||||
uint32_t
|
||||
uint32_t
|
||||
SocketRxAddressTag::GetSerializedSize (void) const
|
||||
{
|
||||
return 0;
|
||||
{
|
||||
return m_address.GetSerializedSize ();
|
||||
}
|
||||
void
|
||||
void
|
||||
SocketRxAddressTag::Serialize (TagBuffer i) const
|
||||
{
|
||||
// for local use in stack only
|
||||
{
|
||||
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;
|
||||
}
|
||||
void
|
||||
void
|
||||
SocketRxAddressTag::Deserialize (TagBuffer i)
|
||||
{
|
||||
// for local use in stack only
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
SocketIpTtlTag::SocketIpTtlTag ()
|
||||
@@ -335,20 +350,21 @@ SocketIpTtlTag::GetInstanceTypeId (void) const
|
||||
{
|
||||
return GetTypeId ();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
SocketIpTtlTag::GetSerializedSize (void) const
|
||||
{
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
void
|
||||
SocketIpTtlTag::Serialize (TagBuffer i) const
|
||||
{
|
||||
// for local use in stack only
|
||||
i.WriteU8 (m_ttl);
|
||||
}
|
||||
void
|
||||
SocketIpTtlTag::Deserialize (TagBuffer i)
|
||||
{
|
||||
// for local use in stack only
|
||||
m_ttl = i.ReadU8 ();
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
Reference in New Issue
Block a user