Qt 4.8
Public Functions | Properties | List of all members
QByteDataBuffer Class Reference

#include <qbytedata_p.h>

Public Functions

void append (QByteDataBuffer &other)
 
void append (const QByteArray &bd)
 
qint64 bufferCount () const
 
qint64 byteAmount () const
 
bool canReadLine () const
 
void clear ()
 
char getChar ()
 
bool isEmpty () const
 
QByteArrayoperator[] (int i)
 
void prepend (QByteArray &bd)
 
 QByteDataBuffer ()
 
QByteArray read ()
 
QByteArray read (qint64 amount)
 
qint64 read (char *dst, qint64 amount)
 
QByteArray readAll ()
 
qint64 sizeNextBlock () const
 
 ~QByteDataBuffer ()
 

Properties

qint64 bufferCompleteSize
 
QList< QByteArraybuffers
 

Detailed Description

Definition at line 62 of file qbytedata_p.h.

Constructors and Destructors

◆ QByteDataBuffer()

QByteDataBuffer::QByteDataBuffer ( )
inline

Definition at line 68 of file qbytedata_p.h.

69  {
70  }
qint64 bufferCompleteSize
Definition: qbytedata_p.h:66

◆ ~QByteDataBuffer()

QByteDataBuffer::~QByteDataBuffer ( )
inline

Definition at line 72 of file qbytedata_p.h.

73  {
74  clear();
75  }

Functions

◆ append() [1/2]

void QByteDataBuffer::append ( QByteDataBuffer other)
inline

◆ append() [2/2]

void QByteDataBuffer::append ( const QByteArray bd)
inline

Definition at line 87 of file qbytedata_p.h.

88  {
89  if (bd.isEmpty())
90  return;
91 
92  buffers.append(bd);
93  bufferCompleteSize += bd.size();
94  }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
qint64 bufferCompleteSize
Definition: qbytedata_p.h:66
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QList< QByteArray > buffers
Definition: qbytedata_p.h:65

◆ bufferCount()

qint64 QByteDataBuffer::bufferCount ( ) const
inline

Definition at line 187 of file qbytedata_p.h.

Referenced by QHttpNetworkReplyPrivate::appendCompressedReplyData(), and QNetworkReplyImplPrivate::appendDownstreamData().

188  {
189  return buffers.length();
190  }
int length() const
This function is identical to count().
Definition: qlist.h:281
QList< QByteArray > buffers
Definition: qbytedata_p.h:65

◆ byteAmount()

qint64 QByteDataBuffer::byteAmount ( ) const
inline

Definition at line 181 of file qbytedata_p.h.

Referenced by append(), isEmpty(), QNetworkReplyImplPrivate::nextDownstreamBlockSize(), read(), and readAll().

182  {
183  return bufferCompleteSize;
184  }
qint64 bufferCompleteSize
Definition: qbytedata_p.h:66

◆ canReadLine()

bool QByteDataBuffer::canReadLine ( ) const
inline

Definition at line 210 of file qbytedata_p.h.

210  {
211  for (int i = 0; i < buffers.length(); i++)
212  if (buffers.at(i).contains('\n'))
213  return true;
214  return false;
215  }
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int length() const
This function is identical to count().
Definition: qlist.h:281
QList< QByteArray > buffers
Definition: qbytedata_p.h:65
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
Definition: qbytearray.h:525

◆ clear()

void QByteDataBuffer::clear ( )
inline

◆ getChar()

char QByteDataBuffer::getChar ( )
inline

Definition at line 167 of file qbytedata_p.h.

168  {
169  char c;
170  read(&c, 1);
171  return c;
172  }
QByteArray read()
Definition: qbytedata_p.h:107
unsigned char c[8]
Definition: qnumeric_p.h:62

◆ isEmpty()

bool QByteDataBuffer::isEmpty ( ) const
inline

Definition at line 192 of file qbytedata_p.h.

Referenced by QHttpNetworkConnectionChannel::_q_receiveReply(), and append().

193  {
194  return byteAmount() == 0;
195  }
qint64 byteAmount() const
Definition: qbytedata_p.h:181

◆ operator[]()

QByteArray& QByteDataBuffer::operator[] ( int  i)
inline

Definition at line 205 of file qbytedata_p.h.

206  {
207  return buffers[i];
208  }
QList< QByteArray > buffers
Definition: qbytedata_p.h:65

◆ prepend()

void QByteDataBuffer::prepend ( QByteArray bd)
inline

Definition at line 96 of file qbytedata_p.h.

97  {
98  if (bd.isEmpty())
99  return;
100 
101  buffers.prepend(bd);
102  bufferCompleteSize += bd.size();
103  }
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
qint64 bufferCompleteSize
Definition: qbytedata_p.h:66
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QList< QByteArray > buffers
Definition: qbytedata_p.h:65

◆ read() [1/3]

QByteArray QByteDataBuffer::read ( )
inline

Definition at line 107 of file qbytedata_p.h.

Referenced by getChar(), read(), and readAll().

108  {
110  return buffers.takeFirst();
111  }
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
qint64 bufferCompleteSize
Definition: qbytedata_p.h:66
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QList< QByteArray > buffers
Definition: qbytedata_p.h:65

◆ read() [2/3]

QByteArray QByteDataBuffer::read ( qint64  amount)
inline

Definition at line 122 of file qbytedata_p.h.

123  {
124  amount = qMin(byteAmount(), amount);
125  QByteArray byteData;
126  byteData.resize(amount);
127  read(byteData.data(), byteData.size());
128  return byteData;
129  }
QByteArray read()
Definition: qbytedata_p.h:107
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
qint64 byteAmount() const
Definition: qbytedata_p.h:181

◆ read() [3/3]

qint64 QByteDataBuffer::read ( char *  dst,
qint64  amount 
)
inline

Definition at line 133 of file qbytedata_p.h.

134  {
135  amount = qMin(amount, byteAmount());
136  qint64 originalAmount = amount;
137  char *writeDst = dst;
138 
139  while (amount > 0) {
140  QByteArray first = buffers.takeFirst();
141  if (amount >= first.size()) {
142  // take it completely
143  bufferCompleteSize -= first.size();
144  amount -= first.size();
145  memcpy(writeDst, first.constData(), first.size());
146  writeDst += first.size();
147  first.clear();
148  } else {
149  // take a part of it & it is the last one to take
150  bufferCompleteSize -= amount;
151  memcpy(writeDst, first.constData(), amount);
152 
153  qint64 newFirstSize = first.size() - amount;
154  QByteArray newFirstData;
155  newFirstData.resize(newFirstSize);
156  memcpy(newFirstData.data(), first.constData() + amount, newFirstSize);
157  buffers.prepend(newFirstData);
158 
159  amount = 0;
160  first.clear();
161  }
162  }
163 
164  return originalAmount;
165  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
__int64 qint64
Definition: qglobal.h:942
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void resize(int size)
Sets the size of the byte array to size bytes.
qint64 bufferCompleteSize
Definition: qbytedata_p.h:66
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QList< QByteArray > buffers
Definition: qbytedata_p.h:65
qint64 byteAmount() const
Definition: qbytedata_p.h:181
void clear()
Clears the contents of the byte array and makes it empty.

◆ readAll()

QByteArray QByteDataBuffer::readAll ( )
inline

Definition at line 115 of file qbytedata_p.h.

116  {
117  return read(byteAmount());
118  }
QByteArray read()
Definition: qbytedata_p.h:107
qint64 byteAmount() const
Definition: qbytedata_p.h:181

◆ sizeNextBlock()

qint64 QByteDataBuffer::sizeNextBlock ( ) const
inline

Definition at line 197 of file qbytedata_p.h.

198  {
199  if(buffers.isEmpty())
200  return 0;
201  else
202  return buffers.first().size();
203  }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QList< QByteArray > buffers
Definition: qbytedata_p.h:65

Properties

◆ bufferCompleteSize

qint64 QByteDataBuffer::bufferCompleteSize
private

Definition at line 66 of file qbytedata_p.h.

Referenced by byteAmount().

◆ buffers

QList<QByteArray> QByteDataBuffer::buffers
private

Definition at line 65 of file qbytedata_p.h.

Referenced by append().


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