INET Framework for OMNeT++/OMNEST
inet::ByteArrayBuffer Class Reference

Buffer that carries BytesArrays. More...

#include <ByteArrayBuffer.h>

Inheritance diagram for inet::ByteArrayBuffer:

Public Member Functions

 ByteArrayBuffer ()
 Ctor. More...
 
 ByteArrayBuffer (const ByteArrayBuffer &other)
 Copy ctor. More...
 
ByteArrayBufferoperator= (const ByteArrayBuffer &other)
 
virtual ByteArrayBufferdup () const override
 
virtual void clear ()
 Clear buffer. More...
 
virtual void push (const ByteArray &byteArrayP)
 Push data to end of buffer. More...
 
virtual void push (const void *bufferP, unsigned int bufferLengthP)
 Push data to end of buffer. More...
 
virtual uint64 getLength () const
 Returns length of stored data. More...
 
virtual unsigned int getBytesToBuffer (void *bufferP, unsigned int bufferLengthP, unsigned int srcOffsP=0) const
 Copy bytes to an external buffer. More...
 
virtual unsigned int popBytesToBuffer (void *bufferP, unsigned int bufferLengthP)
 Move bytes to an external buffer. More...
 
virtual unsigned int drop (unsigned int lengthP)
 Drop bytes from buffer. More...
 

Protected Types

typedef std::list< ByteArrayDataList
 

Protected Attributes

uint64 dataLengthM
 
DataList dataListM
 

Private Member Functions

void copy (const ByteArrayBuffer &other)
 

Detailed Description

Buffer that carries BytesArrays.

Member Typedef Documentation

typedef std::list<ByteArray> inet::ByteArrayBuffer::DataList
protected

Constructor & Destructor Documentation

inet::ByteArrayBuffer::ByteArrayBuffer ( )

Ctor.

20  :
21  dataLengthM(0)
22 {
23 }
uint64 dataLengthM
Definition: ByteArrayBuffer.h:29
inet::ByteArrayBuffer::ByteArrayBuffer ( const ByteArrayBuffer other)

Copy ctor.

26  : cObject(other)
27 {
28  copy(other);
29 }
void copy(const ByteArrayBuffer &other)
Definition: ByteArrayBuffer.h:33

Member Function Documentation

void inet::ByteArrayBuffer::clear ( )
virtual
void inet::ByteArrayBuffer::copy ( const ByteArrayBuffer other)
inlineprivate

Referenced by ByteArrayBuffer(), and operator=().

33 { dataLengthM = other.dataLengthM; dataListM = other.dataListM; }
DataList dataListM
Definition: ByteArrayBuffer.h:30
uint64 dataLengthM
Definition: ByteArrayBuffer.h:29
unsigned int inet::ByteArrayBuffer::drop ( unsigned int  lengthP)
virtual

Drop bytes from buffer.

Parameters
lengthPcount of droppable bytes
Returns
count of dropped bytes

Referenced by inet::tcp::TCP_NSC_ByteStreamSendQueue::dequeueTcpLayerMsg(), inet::tcp::TcpLwipByteStreamSendQueue::dequeueTcpLayerMsg(), inet::tcp::TCPByteStreamSendQueue::discardUpTo(), and popBytesToBuffer().

79 {
80  ASSERT(lengthP <= dataLengthM);
81 
82  unsigned int length = lengthP;
83 
84  while (length > 0) {
85  unsigned int sliceLength = dataListM.front().getDataArraySize();
86 
87  if (sliceLength <= length) {
88  dataListM.pop_front();
89  dataLengthM -= sliceLength;
90  length -= sliceLength;
91  }
92  else {
93  dataListM.front().truncateData(length, 0);
94  dataLengthM -= length;
95  length = 0;
96  }
97  }
98  ASSERT(0 == length);
99  return lengthP;
100 }
DataList dataListM
Definition: ByteArrayBuffer.h:30
uint64 dataLengthM
Definition: ByteArrayBuffer.h:29
virtual ByteArrayBuffer* inet::ByteArrayBuffer::dup ( ) const
inlineoverridevirtual
43 { return new ByteArrayBuffer(*this); }
ByteArrayBuffer()
Ctor.
Definition: ByteArrayBuffer.cc:19
unsigned int inet::ByteArrayBuffer::getBytesToBuffer ( void *  bufferP,
unsigned int  bufferLengthP,
unsigned int  srcOffsP = 0 
) const
virtual

Copy bytes to an external buffer.

Parameters
bufferPpointer to output buffer
bufferLengthPlength of output buffer
srcOffsPsource offset
Returns
count of copied bytes

Referenced by inet::tcp::TCPByteStreamSendQueue::createSegmentWithBytes(), inet::tcp::TcpLwipByteStreamSendQueue::getBytesForTcpLayer(), inet::tcp::TCP_NSC_ByteStreamSendQueue::getBytesForTcpLayer(), and popBytesToBuffer().

55 {
56  unsigned int copiedBytes = 0;
57  DataList::const_iterator i;
58 
59  for (i = this->dataListM.begin(); (copiedBytes < bufferLengthP) && (i != dataListM.end()); ++i) {
60  unsigned int cbytes = i->copyDataToBuffer((char *)bufferP + copiedBytes,
61  bufferLengthP - copiedBytes, srcOffsP);
62  if (cbytes) {
63  copiedBytes += cbytes;
64  srcOffsP = 0;
65  }
66  else {
67  srcOffsP -= i->getDataArraySize();
68  }
69  }
70  return copiedBytes;
71 }
DataList dataListM
Definition: ByteArrayBuffer.h:30
ByteArrayBuffer & inet::ByteArrayBuffer::operator= ( const ByteArrayBuffer other)
32 {
33  if (this == &other)
34  return *this;
35  cObject::operator=(other);
36  copy(other);
37  return *this;
38 }
void copy(const ByteArrayBuffer &other)
Definition: ByteArrayBuffer.h:33
unsigned int inet::ByteArrayBuffer::popBytesToBuffer ( void *  bufferP,
unsigned int  bufferLengthP 
)
virtual

Move bytes to an external buffer.

Parameters
bufferPpointer to output buffer
bufferLengthPlength of output buffer
Returns
count of moved bytes

Referenced by inet::tcp::TCP_NSC_ByteStreamReceiveQueue::extractBytesUpTo(), and inet::tcp::TcpLwipByteStreamReceiveQueue::extractBytesUpTo().

74 {
75  return drop(getBytesToBuffer(bufferP, bufferLengthP));
76 }
virtual unsigned int drop(unsigned int lengthP)
Drop bytes from buffer.
Definition: ByteArrayBuffer.cc:78
virtual unsigned int getBytesToBuffer(void *bufferP, unsigned int bufferLengthP, unsigned int srcOffsP=0) const
Copy bytes to an external buffer.
Definition: ByteArrayBuffer.cc:54
void inet::ByteArrayBuffer::push ( const ByteArray byteArrayP)
virtual
void inet::ByteArrayBuffer::push ( const void *  bufferP,
unsigned int  bufferLengthP 
)
virtual

Push data to end of buffer.

47 {
48  ByteArray byteArray;
49  dataListM.push_back(byteArray);
50  dataListM.back().setDataFromBuffer(bufferP, bufferLengthP);
51  dataLengthM += bufferLengthP;
52 }
DataList dataListM
Definition: ByteArrayBuffer.h:30
uint64 dataLengthM
Definition: ByteArrayBuffer.h:29

Member Data Documentation

uint64 inet::ByteArrayBuffer::dataLengthM
protected

Referenced by clear(), copy(), drop(), and push().

DataList inet::ByteArrayBuffer::dataListM
protected

Referenced by clear(), copy(), drop(), getBytesToBuffer(), and push().


The documentation for this class was generated from the following files: