automatically resized byte buffer More...
#include <buffer.h>
Classes | |
class | Iterator |
iterator in a Buffer instance More... | |
Public Member Functions | |
uint32_t | GetSize (void) const |
uint8_t const * | PeekData (void) const |
bool | AddAtStart (uint32_t start) |
bool | AddAtEnd (uint32_t end) |
void | AddAtEnd (const Buffer &o) |
void | RemoveAtStart (uint32_t start) |
void | RemoveAtEnd (uint32_t end) |
Buffer | CreateFragment (uint32_t start, uint32_t length) const |
Buffer::Iterator | Begin (void) const |
Buffer::Iterator | End (void) const |
Buffer | CreateFullCopy (void) const |
int32_t | GetCurrentStartOffset (void) const |
int32_t | GetCurrentEndOffset (void) const |
Buffer (Buffer const &o) | |
Buffer & | operator= (Buffer const &o) |
Buffer () | |
Buffer (uint32_t dataSize) | |
~Buffer () | |
Private Member Functions | |
void | TransformIntoRealBuffer (void) const |
bool | CheckInternalState (void) const |
void | Initialize (uint32_t zeroSize) |
uint32_t | GetInternalSize (void) const |
uint32_t | GetInternalEnd (void) const |
Static Private Member Functions | |
static void | Recycle (struct BufferData *data) |
static struct BufferData * | Create (uint32_t size) |
Private Attributes | |
struct BufferData * | m_data |
uint32_t | m_zeroAreaStart |
uint32_t | m_zeroAreaEnd |
uint32_t | m_start |
uint32_t | m_end |
automatically resized byte buffer
This represents a buffer of bytes. Its size is automatically adjusted to hold any data prepended or appended by the user. Its implementation is optimized to ensure that the number of buffer resizes is minimized, by creating new Buffers of the maximum size ever used. The correct maximum size is learned at runtime during use by recording the maximum size of each packet.
Definition at line 96 of file buffer.h.
ns3::Buffer::Buffer | ( | Buffer const & | o | ) |
Definition at line 260 of file buffer.cc.
References CheckInternalState(), ns3::BufferData::m_count, m_data, NS_ASSERT, and NS_LOG_FUNCTION.
ns3::Buffer::Buffer | ( | ) |
Definition at line 204 of file buffer.cc.
References Initialize(), and NS_LOG_FUNCTION.
ns3::Buffer::Buffer | ( | uint32_t | dataSize | ) |
Definition at line 210 of file buffer.cc.
References Initialize(), and NS_LOG_FUNCTION.
ns3::Buffer::~Buffer | ( | ) |
Definition at line 303 of file buffer.cc.
References CheckInternalState(), ns3::g_recommendedStart, HEURISTICS, ns3::BufferData::m_count, m_data, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().
void ns3::Buffer::AddAtEnd | ( | const Buffer & | o | ) |
o | the buffer to append to the end of this buffer. |
Add bytes at the end of the Buffer. Any call to this method invalidates any Iterator pointing to this Buffer.
This is an optimization which kicks in when we attempt to aggregate two buffers which contain adjacent zero areas.
Definition at line 457 of file buffer.cc.
References AddAtEnd(), Begin(), CheckInternalState(), CreateFullCopy(), End(), GetSize(), ns3::BufferData::m_count, m_data, ns3::BufferData::m_dirtyEnd, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, ns3::Buffer::Iterator::Prev(), and ns3::Buffer::Iterator::Write().
bool ns3::Buffer::AddAtEnd | ( | uint32_t | end | ) |
end | size to reserve |
Add bytes at the end of the Buffer. The content of these bytes is undefined but debugging builds initialize them to 0x33. Any call to this method invalidates any Iterator pointing to this Buffer.
Definition at line 400 of file buffer.cc.
References CheckInternalState(), Create(), ns3::g_nAddNoRealloc, ns3::g_nAddRealloc, GetInternalEnd(), GetInternalSize(), HEURISTICS, LOG_INTERNAL_STATE, ns3::BufferData::m_count, ns3::BufferData::m_data, m_data, ns3::BufferData::m_dirtyEnd, ns3::BufferData::m_dirtyStart, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().
Referenced by ns3::Packet::AddAtEnd(), AddAtEnd(), ns3::Packet::AddPaddingAtEnd(), ns3::Packet::AddTrailer(), CreateFullCopy(), ns3::BufferTest::RunTests(), and ns3::Packet::Serialize().
bool ns3::Buffer::AddAtStart | ( | uint32_t | start | ) |
start | size to reserve |
Add bytes at the start of the Buffer. The content of these bytes is undefined but debugging builds initialize them to 0x33. Any call to this method invalidates any Iterator pointing to this Buffer.
Definition at line 347 of file buffer.cc.
References CheckInternalState(), Create(), ns3::g_nAddNoRealloc, ns3::g_nAddRealloc, GetInternalSize(), HEURISTICS, LOG_INTERNAL_STATE, ns3::BufferData::m_count, ns3::BufferData::m_data, m_data, ns3::BufferData::m_dirtyEnd, ns3::BufferData::m_dirtyStart, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().
Referenced by ns3::Packet::AddHeader(), CreateFullCopy(), ns3::Packet::Packet(), ns3::BufferTest::RunTests(), and ns3::Packet::Serialize().
Buffer::Iterator ns3::Buffer::Begin | ( | void | ) | const |
Definition at line 323 of file buffer.cc.
References CheckInternalState(), and NS_ASSERT.
Referenced by AddAtEnd(), ns3::Packet::AddHeader(), ns3::Packet::CopyData(), CreateFullCopy(), ns3::Packet::Deserialize(), ns3::PacketMetadata::ItemIterator::Next(), ns3::Packet::Packet(), ns3::Packet::PeekHeader(), ns3::Packet::RemoveHeader(), ns3::BufferTest::RunTests(), and ns3::Packet::Serialize().
bool ns3::Buffer::CheckInternalState | ( | void | ) | const [private] |
Definition at line 217 of file buffer.cc.
References LOG_INTERNAL_STATE, ns3::BufferData::m_count, m_data, ns3::BufferData::m_dirtyEnd, ns3::BufferData::m_dirtyStart, m_end, ns3::BufferData::m_size, m_start, m_zeroAreaEnd, and m_zeroAreaStart.
Referenced by AddAtEnd(), AddAtStart(), Begin(), Buffer(), CreateFragment(), CreateFullCopy(), End(), GetSize(), Initialize(), operator=(), PeekData(), RemoveAtEnd(), RemoveAtStart(), TransformIntoRealBuffer(), and ~Buffer().
BufferData * ns3::Buffer::Create | ( | uint32_t | size | ) | [static, read, private] |
Definition at line 169 of file buffer.cc.
References ns3::BufferAllocate(), ns3::BufferDeallocate(), ns3::g_freeList, ns3::g_nAllocs, ns3::g_nCreates, ns3::BufferData::m_count, ns3::BufferData::m_size, and NS_ASSERT.
Referenced by AddAtEnd(), AddAtStart(), and Initialize().
Buffer ns3::Buffer::CreateFragment | ( | uint32_t | start, | |
uint32_t | length | |||
) | const |
start | offset from start of packet | |
length |
Definition at line 579 of file buffer.cc.
References CheckInternalState(), GetSize(), NS_ASSERT, NS_LOG_FUNCTION, RemoveAtEnd(), and RemoveAtStart().
Referenced by ns3::Packet::CreateFragment(), and ns3::BufferTest::RunTests().
Buffer ns3::Buffer::CreateFullCopy | ( | void | ) | const |
Definition at line 591 of file buffer.cc.
References AddAtEnd(), AddAtStart(), Begin(), CheckInternalState(), End(), ns3::BufferData::m_data, m_data, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, ns3::Buffer::Iterator::Prev(), ns3::Buffer::Iterator::Write(), and ns3::Buffer::Iterator::WriteU8().
Referenced by AddAtEnd(), ns3::Packet::Serialize(), and TransformIntoRealBuffer().
Buffer::Iterator ns3::Buffer::End | ( | void | ) | const |
Definition at line 329 of file buffer.cc.
References CheckInternalState(), and NS_ASSERT.
Referenced by AddAtEnd(), ns3::Packet::AddTrailer(), CreateFullCopy(), ns3::PacketMetadata::ItemIterator::Next(), ns3::Packet::PeekTrailer(), ns3::Packet::RemoveTrailer(), and ns3::BufferTest::RunTests().
int32_t ns3::Buffer::GetCurrentEndOffset | ( | void | ) | const |
Definition at line 621 of file buffer.cc.
References m_end.
Referenced by ns3::Packet::AddAtEnd(), ns3::Packet::AddPaddingAtEnd(), ns3::Packet::AddTag(), ns3::Packet::AddTrailer(), and ns3::Packet::GetTagIterator().
int32_t ns3::Buffer::GetCurrentStartOffset | ( | void | ) | const |
Definition at line 616 of file buffer.cc.
References m_start.
Referenced by ns3::Packet::AddAtEnd(), ns3::Packet::AddHeader(), ns3::Packet::AddTag(), ns3::Packet::AddTrailer(), and ns3::Packet::GetTagIterator().
uint32_t ns3::Buffer::GetInternalEnd | ( | void | ) | const [private] |
Definition at line 341 of file buffer.cc.
References m_end, m_zeroAreaEnd, and m_zeroAreaStart.
Referenced by AddAtEnd().
uint32_t ns3::Buffer::GetInternalSize | ( | void | ) | const [private] |
Definition at line 336 of file buffer.cc.
References m_end, m_start, m_zeroAreaEnd, and m_zeroAreaStart.
Referenced by AddAtEnd(), and AddAtStart().
uint32_t ns3::Buffer::GetSize | ( | void | ) | const |
Definition at line 316 of file buffer.cc.
References CheckInternalState(), m_end, m_start, and NS_ASSERT.
Referenced by AddAtEnd(), ns3::Packet::CreateFragment(), CreateFragment(), ns3::Packet::Deserialize(), ns3::Packet::GetSize(), ns3::PacketMetadata::ItemIterator::Next(), ns3::BufferTest::RunTests(), and ns3::Packet::Serialize().
void ns3::Buffer::Initialize | ( | uint32_t | zeroSize | ) | [private] |
Definition at line 242 of file buffer.cc.
References CheckInternalState(), Create(), ns3::g_recommendedStart, m_data, ns3::BufferData::m_dirtyEnd, ns3::BufferData::m_dirtyStart, m_end, ns3::BufferData::m_size, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by Buffer().
Definition at line 276 of file buffer.cc.
References CheckInternalState(), ns3::g_recommendedStart, HEURISTICS, ns3::BufferData::m_count, m_data, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().
uint8_t const * ns3::Buffer::PeekData | ( | void | ) | const |
The returned pointer points to an area of memory which is ns3::Buffer::GetSize () bytes big. Please, try to never ever use this method. It is really evil and is present only for a few specific uses.
Definition at line 638 of file buffer.cc.
References CheckInternalState(), ns3::BufferData::m_data, m_data, m_start, NS_ASSERT, and TransformIntoRealBuffer().
Referenced by ns3::BufferTest::EnsureWrittenBytes(), ns3::Packet::PeekData(), and ns3::BufferTest::RunTests().
void ns3::Buffer::Recycle | ( | struct BufferData * | data | ) | [static, private] |
Definition at line 152 of file buffer.cc.
References ns3::BufferDeallocate(), ns3::g_freeList, ns3::g_maxSize, ns3::BufferData::m_count, ns3::BufferData::m_size, and NS_ASSERT.
Referenced by AddAtEnd(), AddAtStart(), operator=(), and ~Buffer().
void ns3::Buffer::RemoveAtEnd | ( | uint32_t | end | ) |
end | size to remove |
Remove bytes at the end of the Buffer. Any call to this method invalidates any Iterator pointing to this Buffer.
Definition at line 543 of file buffer.cc.
References CheckInternalState(), HEURISTICS, LOG_INTERNAL_STATE, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by CreateFragment(), ns3::Packet::Deserialize(), ns3::PacketMetadata::ItemIterator::Next(), ns3::Packet::RemoveAtEnd(), ns3::Packet::RemoveTrailer(), and ns3::BufferTest::RunTests().
void ns3::Buffer::RemoveAtStart | ( | uint32_t | start | ) |
start | size to remove |
Remove bytes at the start of the Buffer. Any call to this method invalidates any Iterator pointing to this Buffer.
Definition at line 498 of file buffer.cc.
References CheckInternalState(), HEURISTICS, LOG_INTERNAL_STATE, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by CreateFragment(), ns3::Packet::Deserialize(), ns3::PacketMetadata::ItemIterator::Next(), ns3::Packet::RemoveAtStart(), ns3::Packet::RemoveHeader(), and ns3::BufferTest::RunTests().
void ns3::Buffer::TransformIntoRealBuffer | ( | void | ) | const [private] |
Definition at line 628 of file buffer.cc.
References CheckInternalState(), CreateFullCopy(), and NS_ASSERT.
Referenced by PeekData().
struct BufferData* ns3::Buffer::m_data [private] |
Definition at line 506 of file buffer.h.
Referenced by AddAtEnd(), AddAtStart(), Buffer(), CheckInternalState(), ns3::Buffer::Iterator::Construct(), CreateFullCopy(), Initialize(), operator=(), PeekData(), and ~Buffer().
uint32_t ns3::Buffer::m_end [private] |
Definition at line 536 of file buffer.h.
Referenced by AddAtEnd(), AddAtStart(), CheckInternalState(), ns3::Buffer::Iterator::Construct(), CreateFullCopy(), GetCurrentEndOffset(), GetInternalEnd(), GetInternalSize(), GetSize(), Initialize(), operator=(), RemoveAtEnd(), and RemoveAtStart().
uint32_t ns3::Buffer::m_start [private] |
Definition at line 532 of file buffer.h.
Referenced by AddAtEnd(), AddAtStart(), CheckInternalState(), ns3::Buffer::Iterator::Construct(), CreateFullCopy(), GetCurrentStartOffset(), GetInternalSize(), GetSize(), Initialize(), operator=(), PeekData(), RemoveAtEnd(), and RemoveAtStart().
uint32_t ns3::Buffer::m_zeroAreaEnd [private] |
Definition at line 528 of file buffer.h.
Referenced by AddAtEnd(), AddAtStart(), CheckInternalState(), ns3::Buffer::Iterator::Construct(), CreateFullCopy(), GetInternalEnd(), GetInternalSize(), Initialize(), operator=(), RemoveAtEnd(), and RemoveAtStart().
uint32_t ns3::Buffer::m_zeroAreaStart [private] |
Definition at line 524 of file buffer.h.
Referenced by AddAtEnd(), AddAtStart(), CheckInternalState(), ns3::Buffer::Iterator::Construct(), CreateFullCopy(), GetInternalEnd(), GetInternalSize(), Initialize(), operator=(), RemoveAtEnd(), and RemoveAtStart().