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

Class that carries raw bytes. More...

#include <ByteArray.h>

Inheritance diagram for inet::ByteArray:
inet::ByteArray_Base

Public Member Functions

 ByteArray ()
 Constructor. More...
 
 ByteArray (const ByteArray &other)
 Copy constructor. More...
 
ByteArrayoperator= (const ByteArray &other)
 operator = More...
 
virtual ByteArraydup () const override
 Creates and returns an exact copy of this object. More...
 
virtual void setDataFromBuffer (const void *ptr, unsigned int length)
 Copy data from buffer. More...
 
virtual void copyDataFromBuffer (unsigned int destOffset, const void *ptr, unsigned int length)
 Copy data from buffer. More...
 
virtual void setDataFromByteArray (const ByteArray &other, unsigned int srcOffset, unsigned int length)
 Copy data from other ByteArray. More...
 
virtual void copyDataFromByteArray (unsigned int destOffset, const ByteArray &other, unsigned int srcOffset, unsigned int length)
 Copy data from other ByteArray. More...
 
virtual void addDataFromBuffer (const void *ptr, unsigned int length)
 Add data from buffer to the end of existing content. More...
 
virtual unsigned int copyDataToBuffer (void *ptr, unsigned int length, unsigned int srcOffs=0) const
 Copy data content to buffer. More...
 
virtual void assignBuffer (void *ptr, unsigned int length)
 Set buffer pointer and buffer length. More...
 
virtual void truncateData (unsigned int truncleft, unsigned int truncright)
 Truncate data content. More...
 
virtual void expandData (unsigned int addLeft, unsigned int addRight)
 Expand data content. More...
 
virtual char * getDataPtr ()
 
- Public Member Functions inherited from inet::ByteArray_Base
virtual ~ByteArray_Base ()
 
virtual void parsimPack (omnetpp::cCommBuffer *b) const override
 
virtual void parsimUnpack (omnetpp::cCommBuffer *b) override
 
virtual void setDataArraySize (unsigned int size)
 
virtual unsigned int getDataArraySize () const
 
virtual char getData (unsigned int k) const
 
virtual void setData (unsigned int k, char data)
 

Additional Inherited Members

- Protected Member Functions inherited from inet::ByteArray_Base
bool operator== (const ByteArray_Base &)
 
 ByteArray_Base ()
 
 ByteArray_Base (const ByteArray_Base &other)
 
ByteArray_Baseoperator= (const ByteArray_Base &other)
 
- Protected Attributes inherited from inet::ByteArray_Base
char * data
 
unsigned int data_arraysize
 

Detailed Description

Class that carries raw bytes.

Constructor & Destructor Documentation

inet::ByteArray::ByteArray ( )
inline

Constructor.

inet::ByteArray::ByteArray ( const ByteArray other)
inline

Copy constructor.

38 : ByteArray_Base(other) {}

Member Function Documentation

void inet::ByteArray::addDataFromBuffer ( const void *  ptr,
unsigned int  length 
)
virtual

Add data from buffer to the end of existing content.

Parameters
ptrpointer to input buffer
lengthlength of data

Referenced by inet::RawPacket::addDataFromBuffer().

58 {
59  if (0 == length)
60  return;
61 
62  unsigned int nlength = data_arraysize + length;
63  char *ndata = new char[nlength];
64  if (data_arraysize)
65  memcpy(ndata, data, data_arraysize);
66  memcpy(ndata + data_arraysize, ptr, length);
67  delete[] data;
68  data = ndata;
69  data_arraysize = nlength;
70 }
unsigned int data_arraysize
Definition: ByteArray_m.h:79
char * data
Definition: ByteArray_m.h:78
void inet::ByteArray::assignBuffer ( void *  ptr,
unsigned int  length 
)
virtual

Set buffer pointer and buffer length.

Parameters
ptrpointer to new buffer, must created by buffer = new char[length1]; where length1>=length
lengthlength of buffer

Referenced by inet::TCPSessionApp::createDataPacket(), inet::tcp::TCPByteStreamSendQueue::createSegmentWithBytes(), inet::tcp::TCP_NSC_ByteStreamReceiveQueue::extractBytesUpTo(), inet::tcp::TcpLwipByteStreamReceiveQueue::extractBytesUpTo(), and inet::tcp::TCPByteStreamRcvQueue::Region::merge().

84 {
85  delete[] data;
86  data = (char *)ptr;
87  data_arraysize = length;
88 }
unsigned int data_arraysize
Definition: ByteArray_m.h:79
char * data
Definition: ByteArray_m.h:78
void inet::ByteArray::copyDataFromBuffer ( unsigned int  destOffset,
const void *  ptr,
unsigned int  length 
)
virtual

Copy data from buffer.

Parameters
destOffsetfirst byte from buffer will be written to here
ptrpointer to buffer
lengthlength of data

Referenced by inet::IPv4FragBuf::addFragment(), and copyDataFromByteArray().

32 {
33  unsigned int nlength = destOffset + length;
34  if (data_arraysize < nlength) {
35  char *ndata = new char[nlength];
36  if (data_arraysize)
37  memcpy(ndata, data, data_arraysize);
38  delete[] data;
39  data = ndata;
40  }
41  memcpy(data + destOffset, ptr, length);
42 }
unsigned int data_arraysize
Definition: ByteArray_m.h:79
char * data
Definition: ByteArray_m.h:78
void inet::ByteArray::copyDataFromByteArray ( unsigned int  destOffset,
const ByteArray other,
unsigned int  srcOffset,
unsigned int  length 
)
virtual

Copy data from other ByteArray.

Parameters
destOffsetfirst byte from other will be written to here
otherreference to other ByteArray
srcOffsetskipped first bytes from other
lengthlength of data from other
51 {
52  ASSERT(srcOffset + length <= other.data_arraysize);
53  copyDataFromBuffer(destOffset, other.data + srcOffset, length);
54 }
virtual void copyDataFromBuffer(unsigned int destOffset, const void *ptr, unsigned int length)
Copy data from buffer.
Definition: ByteArray.cc:31
unsigned int inet::ByteArray::copyDataToBuffer ( void *  ptr,
unsigned int  length,
unsigned int  srcOffs = 0 
) const
virtual

Copy data content to buffer.

Parameters
ptrpointer to output buffer
lengthlength of buffer, maximum of copied bytes
srcOffsnumber of skipped bytes from source
Returns
: length of copied data

Referenced by inet::RawPacket::copyDataToBuffer(), and inet::tcp::TCPByteStreamRcvQueue::Region::merge().

73 {
74  if (srcOffs >= data_arraysize)
75  return 0;
76 
77  if (srcOffs + length > data_arraysize)
78  length = data_arraysize - srcOffs;
79  memcpy(ptr, data + srcOffs, length);
80  return length;
81 }
unsigned int data_arraysize
Definition: ByteArray_m.h:79
char * data
Definition: ByteArray_m.h:78
virtual ByteArray* inet::ByteArray::dup ( ) const
inlineoverridevirtual

Creates and returns an exact copy of this object.

Reimplemented from inet::ByteArray_Base.

48 { return new ByteArray(*this); }
ByteArray()
Constructor.
Definition: ByteArray.h:33
void inet::ByteArray::expandData ( unsigned int  addLeft,
unsigned int  addRight 
)
virtual

Expand data content.

Parameters
addLeftThe number of bytes will be added at beginning of the content
addRightThe number of bytes will be added at end of the content added bytes are unfilled

Referenced by inet::IPv4FragBuf::addFragment().

108 {
109  ASSERT(data_arraysize <= (data_arraysize + addleft + addright));
110 
111  if ((addleft || addright)) {
112  unsigned int nlength = data_arraysize + (addleft + addright);
113  char *ndata = new char[nlength];
114  memmove(ndata + addleft, data, data_arraysize);
115  delete[] data;
116  data = ndata;
117  data_arraysize = nlength;
118  }
119 }
unsigned int data_arraysize
Definition: ByteArray_m.h:79
char * data
Definition: ByteArray_m.h:78
virtual char* inet::ByteArray::getDataPtr ( )
inlinevirtual

Referenced by inet::IPv4FragBuf::addFragment().

121 { return data; }
char * data
Definition: ByteArray_m.h:78
ByteArray& inet::ByteArray::operator= ( const ByteArray other)
inline

operator =

43 { ByteArray_Base::operator=(other); return *this; }
ByteArray_Base & operator=(const ByteArray_Base &other)
void inet::ByteArray::setDataFromBuffer ( const void *  ptr,
unsigned int  length 
)
virtual

Copy data from buffer.

Parameters
ptrpointer to buffer
lengthlength of data

Referenced by inet::serializer::TCPSerializer::deserialize(), inet::RawPacket::setDataFromBuffer(), and setDataFromByteArray().

21 {
22  if (length != data_arraysize) {
23  delete[] data;
24  data = length ? new char[length] : nullptr;
25  data_arraysize = length;
26  }
27  if (length)
28  memcpy(data, ptr, length);
29 }
unsigned int data_arraysize
Definition: ByteArray_m.h:79
char * data
Definition: ByteArray_m.h:78
void inet::ByteArray::setDataFromByteArray ( const ByteArray other,
unsigned int  srcOffset,
unsigned int  length 
)
virtual

Copy data from other ByteArray.

Parameters
otherreference to other ByteArray
srcOffsetskipped first bytes from other
lengthlength of data

Referenced by inet::tcp::TCPByteStreamRcvQueue::Region::split().

45 {
46  ASSERT(srcOffs + length <= other.data_arraysize);
47  setDataFromBuffer(other.data + srcOffs, length);
48 }
virtual void setDataFromBuffer(const void *ptr, unsigned int length)
Copy data from buffer.
Definition: ByteArray.cc:20
void inet::ByteArray::truncateData ( unsigned int  truncleft,
unsigned int  truncright 
)
virtual

Truncate data content.

Parameters
truncleftThe number of bytes from the beginning of the content be remove
truncrightThe number of bytes from the end of the content be remove Generate assert when not have enough bytes for truncation

Referenced by inet::RawPacket::removePrefix(), and inet::tcp::TCPByteStreamRcvQueue::Region::split().

91 {
92  ASSERT(data_arraysize >= (truncleft + truncright));
93 
94  if ((truncleft || truncright)) {
95  unsigned int nlength = data_arraysize - (truncleft + truncright);
96  char *ndata = nullptr;
97  if (nlength) {
98  ndata = new char[nlength];
99  memcpy(ndata, data + truncleft, nlength);
100  }
101  delete[] data;
102  data = ndata;
103  data_arraysize = nlength;
104  }
105 }
unsigned int data_arraysize
Definition: ByteArray_m.h:79
char * data
Definition: ByteArray_m.h:78

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