add API to get bytes out of a packet without calling PeekData
This commit is contained in:
@@ -296,6 +296,19 @@ Packet::PeekData (void) const
|
||||
return m_buffer.PeekData ();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Packet::CopyData (uint8_t *buffer, uint32_t size) const
|
||||
{
|
||||
Buffer::Iterator i = m_buffer.Begin ();
|
||||
uint32_t cur = 0;
|
||||
while (!i.IsEnd () && cur < size)
|
||||
{
|
||||
buffer[cur] = i.ReadU8 ();
|
||||
cur++;
|
||||
}
|
||||
return cur;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Packet::GetUid (void) const
|
||||
{
|
||||
|
||||
@@ -280,6 +280,16 @@ public:
|
||||
*/
|
||||
uint8_t const *PeekData (void) const;
|
||||
|
||||
/**
|
||||
* \param buffer a pointer to a byte buffer where the packet data
|
||||
* should be copied.
|
||||
* \param size the size of the byte buffer.
|
||||
* \returns the number of bytes read from the packet
|
||||
*
|
||||
* No more than \b size bytes will be copied by this function.
|
||||
*/
|
||||
uint32_t CopyData (uint8_t *buffer, uint32_t size) const;
|
||||
|
||||
/**
|
||||
* A packet is allocated a new uid when it is created
|
||||
* empty or with zero-filled payload.
|
||||
@@ -437,6 +447,7 @@ std::ostream& operator<< (std::ostream& os, const Packet &packet);
|
||||
* - ns3::Packet::CreateFragment
|
||||
* - ns3::Packet::RemoveAtStart
|
||||
* - ns3::Packet::RemoveAtEnd
|
||||
* - ns3::Packet::CopyData
|
||||
*
|
||||
* Dirty operations will always be slower than non-dirty operations,
|
||||
* sometimes by several orders of magnitude. However, even the
|
||||
|
||||
Reference in New Issue
Block a user