add Htolsb and Lsbtoh write/read methods
This commit is contained in:
@@ -761,6 +761,33 @@ Buffer::Iterator::WriteU64 (uint64_t data)
|
||||
data >>= 8;
|
||||
WriteU8 (data & 0xff);
|
||||
}
|
||||
void
|
||||
Buffer::Iterator::WriteHtolsbU16 (uint16_t data)
|
||||
{
|
||||
WriteU8 ((data >> 0) & 0xff);
|
||||
WriteU8 ((data >> 8) & 0xff);
|
||||
}
|
||||
void
|
||||
Buffer::Iterator::WriteHtolsbU32 (uint32_t data)
|
||||
{
|
||||
WriteU8 ((data >> 0) & 0xff);
|
||||
WriteU8 ((data >> 8) & 0xff);
|
||||
WriteU8 ((data >> 16) & 0xff);
|
||||
WriteU8 ((data >> 24) & 0xff);
|
||||
}
|
||||
void
|
||||
Buffer::Iterator::WriteHtolsbU64 (uint64_t data)
|
||||
{
|
||||
WriteU8 ((data >> 0) & 0xff);
|
||||
WriteU8 ((data >> 8) & 0xff);
|
||||
WriteU8 ((data >> 16) & 0xff);
|
||||
WriteU8 ((data >> 24) & 0xff);
|
||||
WriteU8 ((data >> 32) & 0xff);
|
||||
WriteU8 ((data >> 40) & 0xff);
|
||||
WriteU8 ((data >> 48) & 0xff);
|
||||
WriteU8 ((data >> 54) & 0xff);
|
||||
}
|
||||
|
||||
void
|
||||
Buffer::Iterator::WriteHtonU16 (uint16_t data)
|
||||
{
|
||||
@@ -895,6 +922,61 @@ Buffer::Iterator::ReadNtohU64 (void)
|
||||
retval |= ReadU8 ();
|
||||
return retval;
|
||||
}
|
||||
uint16_t
|
||||
Buffer::Iterator::ReadLsbtohU16 (void)
|
||||
{
|
||||
uint8_t byte0 = ReadU8 ();
|
||||
uint8_t byte1 = ReadU8 ();
|
||||
uint16_t data = byte1;
|
||||
data <<= 8;
|
||||
data |= byte0;
|
||||
return data;
|
||||
}
|
||||
uint32_t
|
||||
Buffer::Iterator::ReadLsbtohU32 (void)
|
||||
{
|
||||
uint8_t byte0 = ReadU8 ();
|
||||
uint8_t byte1 = ReadU8 ();
|
||||
uint8_t byte2 = ReadU8 ();
|
||||
uint8_t byte3 = ReadU8 ();
|
||||
uint32_t data = byte3;
|
||||
data <<= 8;
|
||||
data |= byte2;
|
||||
data <<= 8;
|
||||
data |= byte1;
|
||||
data <<= 8;
|
||||
data |= byte0;
|
||||
return data;
|
||||
}
|
||||
uint64_t
|
||||
Buffer::Iterator::ReadLsbtohU64 (void)
|
||||
{
|
||||
uint8_t byte0 = ReadU8 ();
|
||||
uint8_t byte1 = ReadU8 ();
|
||||
uint8_t byte2 = ReadU8 ();
|
||||
uint8_t byte3 = ReadU8 ();
|
||||
uint8_t byte4 = ReadU8 ();
|
||||
uint8_t byte5 = ReadU8 ();
|
||||
uint8_t byte6 = ReadU8 ();
|
||||
uint8_t byte7 = ReadU8 ();
|
||||
uint32_t data = byte7;
|
||||
data <<= 8;
|
||||
data |= byte6;
|
||||
data <<= 8;
|
||||
data |= byte5;
|
||||
data <<= 8;
|
||||
data |= byte4;
|
||||
data <<= 8;
|
||||
data |= byte3;
|
||||
data <<= 8;
|
||||
data |= byte2;
|
||||
data <<= 8;
|
||||
data |= byte1;
|
||||
data <<= 8;
|
||||
data |= byte0;
|
||||
|
||||
return data;
|
||||
}
|
||||
void
|
||||
Buffer::Iterator::Read (uint8_t *buffer, uint32_t size)
|
||||
{
|
||||
|
||||
@@ -91,12 +91,14 @@ namespace ns3 {
|
||||
*
|
||||
* A simple state invariant is that m_start <= m_zeroStart <= m_zeroEnd <= m_end
|
||||
*/
|
||||
class Buffer {
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief iterator in a Buffer instance
|
||||
*/
|
||||
class Iterator {
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator ();
|
||||
/**
|
||||
@@ -188,6 +190,30 @@ public:
|
||||
* by two bytes. The data is written in network order and the
|
||||
* input data is expected to be in host order.
|
||||
*/
|
||||
void WriteHtolsbU16 (uint16_t data);
|
||||
/**
|
||||
* \param data data to write in buffer
|
||||
*
|
||||
* Write the data in buffer and avance the iterator position
|
||||
* by four bytes. The data is written in least significant byte order and the
|
||||
* input data is expected to be in host order.
|
||||
*/
|
||||
void WriteHtolsbU32 (uint32_t data);
|
||||
/**
|
||||
* \param data data to write in buffer
|
||||
*
|
||||
* Write the data in buffer and avance the iterator position
|
||||
* by eight bytes. The data is written in least significant byte order and the
|
||||
* input data is expected to be in host order.
|
||||
*/
|
||||
void WriteHtolsbU64 (uint64_t data);
|
||||
/**
|
||||
* \param data data to write in buffer
|
||||
*
|
||||
* Write the data in buffer and avance the iterator position
|
||||
* by two bytes. The data is written in least significant byte order and the
|
||||
* input data is expected to be in host order.
|
||||
*/
|
||||
void WriteHtonU16 (uint16_t data);
|
||||
/**
|
||||
* \param data data to write in buffer
|
||||
@@ -281,6 +307,30 @@ public:
|
||||
* The data is read in network format and return in host format.
|
||||
*/
|
||||
uint64_t ReadNtohU64 (void);
|
||||
/**
|
||||
* \return the two bytes read in the buffer.
|
||||
*
|
||||
* Read data and advance the Iterator by the number of bytes
|
||||
* read.
|
||||
* The data is read in network format and return in host format.
|
||||
*/
|
||||
uint16_t ReadLsbtohU16 (void);
|
||||
/**
|
||||
* \return the four bytes read in the buffer.
|
||||
*
|
||||
* Read data and advance the Iterator by the number of bytes
|
||||
* read.
|
||||
* The data is read in network format and return in host format.
|
||||
*/
|
||||
uint32_t ReadLsbtohU32 (void);
|
||||
/**
|
||||
* \return the eight bytes read in the buffer.
|
||||
*
|
||||
* Read data and advance the Iterator by the number of bytes
|
||||
* read.
|
||||
* The data is read in network format and return in host format.
|
||||
*/
|
||||
uint64_t ReadLsbtohU64 (void);
|
||||
/**
|
||||
* \param buffer buffer to copy data into
|
||||
* \param size number of bytes to copy
|
||||
|
||||
Reference in New Issue
Block a user