add API to get bytes out of a packet without calling PeekData

This commit is contained in:
Mathieu Lacage
2008-10-17 14:16:53 +02:00
parent 36c0976a53
commit 79250d10c2
2 changed files with 24 additions and 0 deletions

View File

@@ -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
{

View File

@@ -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