22#include "ns3/assert.h"
28#define BUFFER_FREE_LIST 1
795#ifdef BUFFER_FREE_LIST
813#include "ns3/assert.h"
833 m_current = m_dataStart;
839 m_current = m_dataEnd;
848 m_dataEnd = buffer->
m_end;
869 NS_ASSERT(m_current + delta <= m_dataEnd);
885 if (m_current < m_zeroStart)
892 m_data[m_current - (m_zeroEnd - m_zeroStart)] =
data;
900 NS_ASSERT_MSG(CheckNoZero(m_current, m_current + len), GetWriteErrorMessage());
901 if (m_current <= m_zeroStart)
908 uint8_t* buffer = &
m_data[m_current - (m_zeroEnd - m_zeroStart)];
909 std::memset(buffer,
data, len);
917 NS_ASSERT_MSG(CheckNoZero(m_current, m_current + 2), GetWriteErrorMessage());
919 if (m_current + 2 <= m_zeroStart)
921 buffer = &
m_data[m_current];
925 buffer = &
m_data[m_current - (m_zeroEnd - m_zeroStart)];
927 buffer[0] = (
data >> 8) & 0xff;
928 buffer[1] = (
data >> 0) & 0xff;
935 NS_ASSERT_MSG(CheckNoZero(m_current, m_current + 4), GetWriteErrorMessage());
938 if (m_current + 4 <= m_zeroStart)
940 buffer = &
m_data[m_current];
944 buffer = &
m_data[m_current - (m_zeroEnd - m_zeroStart)];
946 buffer[0] = (
data >> 24) & 0xff;
947 buffer[1] = (
data >> 16) & 0xff;
948 buffer[2] = (
data >> 8) & 0xff;
949 buffer[3] = (
data >> 0) & 0xff;
957 if (m_current + 2 <= m_zeroStart)
959 buffer = &
m_data[m_current];
961 else if (m_current >= m_zeroEnd)
963 buffer = &
m_data[m_current - (m_zeroEnd - m_zeroStart)];
967 return SlowReadNtohU16();
981 if (m_current + 4 <= m_zeroStart)
983 buffer = &
m_data[m_current];
985 else if (m_current >= m_zeroEnd)
987 buffer = &
m_data[m_current - (m_zeroEnd - m_zeroStart)];
991 return SlowReadNtohU32();
1000 retval |= buffer[3];
1008 NS_ASSERT_MSG(m_current >= m_dataStart && m_current < m_dataEnd, GetReadErrorMessage());
1010 if (m_current < m_zeroStart)
1015 else if (m_current < m_zeroEnd)
1021 uint8_t
data =
m_data[m_current - (m_zeroEnd - m_zeroStart)];
1029 uint8_t ret = PeekU8();
1037 uint8_t byte0 = ReadU8();
1038 uint8_t byte1 = ReadU8();
1039 uint16_t
data = byte1;
1052 start.Write(*
this, end);
iterator in a Buffer instance
void WriteU64(uint64_t data)
uint32_t GetRemainingSize() const
void Construct(const Buffer *buffer)
Initializes the iterator values.
void WriteU32(uint32_t data)
uint32_t m_dataEnd
offset in virtual bytes from the start of the data buffer to the end of the data which can be read by...
void WriteHtonU64(uint64_t data)
void WriteHtolsbU16(uint16_t data)
uint32_t m_dataStart
offset in virtual bytes from the start of the data buffer to the start of the data which can be read ...
std::string GetReadErrorMessage() const
Returns an appropriate message indicating a read error.
uint16_t CalculateIpChecksum(uint16_t size)
Calculate the checksum.
void WriteU8(uint8_t data)
uint16_t SlowReadNtohU16()
uint8_t * m_data
a pointer to the underlying byte buffer.
void WriteHtolsbU32(uint32_t data)
void Write(const uint8_t *buffer, uint32_t size)
uint32_t m_zeroEnd
offset in virtual bytes from the start of the data buffer to the end of the "virtual zero area".
bool Check(uint32_t i) const
Checks that the buffer position is not in the "virtual zero area".
void WriteU16(uint16_t data)
uint32_t m_current
offset in virtual bytes from the start of the data buffer to the current position represented by this...
uint32_t SlowReadNtohU32()
void Read(uint8_t *buffer, uint32_t size)
void WriteHtolsbU64(uint64_t data)
void WriteHtonU16(uint16_t data)
uint32_t m_zeroStart
offset in virtual bytes from the start of the data buffer to the start of the "virtual zero area".
bool CheckNoZero(uint32_t start, uint32_t end) const
Checks that the [start, end) is not in the "virtual zero area".
void WriteHtonU32(uint32_t data)
uint32_t GetDistanceFrom(const Iterator &o) const
void Prev()
go backward by one byte
std::string GetWriteErrorMessage() const
Returns an appropriate message indicating a write error.
void Next()
go forward by one byte
automatically resized byte buffer
uint32_t GetSerializedSize() const
Return the number of bytes required for serialization.
std::vector< Buffer::Data * > FreeList
Container for buffer data.
uint32_t GetInternalEnd() const
Get the buffer end position.
uint32_t m_end
offset to the end of the data referenced by this Buffer instance from the start of m_data->m_data
static Buffer::Data * Allocate(uint32_t reqSize)
Allocate a buffer data storage.
Buffer CreateFragment(uint32_t start, uint32_t length) const
static FreeList * g_freeList
Buffer data container.
Data * m_data
the buffer data storage
static Buffer::Data * Create(uint32_t size)
Create a buffer data storage.
static uint32_t g_maxSize
Max observed data size.
static LocalStaticDestructor g_localStaticDestructor
Local static destructor.
uint32_t m_zeroAreaEnd
offset to the end of the virtual zero area from the start of m_data->m_data
uint32_t m_maxZeroAreaStart
keep track of the maximum value of m_zeroAreaStart across the lifetime of a Buffer instance.
static uint32_t g_recommendedStart
location in a newly-allocated buffer where you should start writing data.
static void Deallocate(Buffer::Data *data)
Deallocate the buffer memory.
void CopyData(std::ostream *os, uint32_t size) const
Copy the specified amount of data from the buffer to the given output stream.
void RemoveAtEnd(uint32_t end)
void TransformIntoRealBuffer() const
Transform a "Virtual byte buffer" into a "Real byte buffer".
void AddAtStart(uint32_t start)
uint32_t GetInternalSize() const
Get the buffer real size.
Buffer::Iterator Begin() const
void AddAtEnd(uint32_t end)
Buffer::Iterator End() const
Buffer & operator=(const Buffer &o)
Assignment operator.
Buffer CreateFullCopy() const
Create a full copy of the buffer, including all the internal structures.
static void Recycle(Buffer::Data *data)
Recycle the buffer memory.
bool CheckInternalState() const
Checks the internal buffer structures consistency.
void Initialize(uint32_t zeroSize)
Initializes the buffer with a number of zeroes.
uint32_t Deserialize(const uint8_t *buffer, uint32_t size)
void RemoveAtStart(uint32_t start)
uint32_t m_zeroAreaStart
offset to the start of the virtual zero area from the start of m_data->m_data
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
const uint8_t * PeekData() const
uint32_t m_start
offset to the start of the data referenced by this Buffer instance from the start of m_data->m_data
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
This data structure is variable-sized through its last member whose size is determined at allocation ...
uint8_t m_data[1]
The real data buffer holds at least one byte.
uint32_t m_dirtyEnd
offset from the start of the m_data field below to the end of the area in which user bytes were writt...
uint32_t m_count
The reference count of an instance of this data structure.
uint32_t m_size
the size of the m_data field below.
uint32_t m_dirtyStart
offset from the start of the m_data field below to the start of the area in which user bytes were wri...
Local static destructor structure.