sources/network/bytestream.cpp

changeset 158
de7574d292ad
parent 157
42bb29924218
child 167
0150f86e68f0
equal deleted inserted replaced
157:42bb29924218 158:de7574d292ad
34 34
35 /*! 35 /*!
36 * \brief Constructs a byte cursor. The cursor is placed to the beginning of the stream. 36 * \brief Constructs a byte cursor. The cursor is placed to the beginning of the stream.
37 * \param data 37 * \param data
38 */ 38 */
39 Bytestream::Bytestream(Vector<unsigned char>& data) : 39 Bytestream::Bytestream(ByteArray& data) :
40 m_data(data), 40 m_data(data),
41 m_position(0) {} 41 m_position(0) {}
42 42
43 /*! 43 /*!
44 * \brief Ensures that the specified amount of bytes can be read. Raises IOError if this is not the case. 44 * \brief Ensures that the specified amount of bytes can be read. Raises IOError if this is not the case.
64 } 64 }
65 65
66 /*! 66 /*!
67 * \returns an iterator to the current data position. 67 * \returns an iterator to the current data position.
68 */ 68 */
69 Vector<unsigned char>::Iterator Bytestream::getCurrentIterator() 69 ByteArray::Iterator Bytestream::getCurrentIterator()
70 { 70 {
71 return m_data.begin() + m_position; 71 return m_data.begin() + m_position;
72 } 72 }
73 73
74 /*! 74 /*!
127 * \brief Reads in characters until a null terminator is encountered. 127 * \brief Reads in characters until a null terminator is encountered.
128 * \returns the read string. 128 * \returns the read string.
129 */ 129 */
130 String Bytestream::readString() 130 String Bytestream::readString()
131 { 131 {
132 Vector<unsigned char>::Iterator stringEndIterator; 132 ByteArray::Iterator stringEndIterator;
133 133
134 // Where's the end of the string? 134 // Where's the end of the string?
135 for (stringEndIterator = getCurrentIterator(); *stringEndIterator != '\0'; ++stringEndIterator) 135 for (stringEndIterator = getCurrentIterator(); *stringEndIterator != '\0'; ++stringEndIterator)
136 { 136 {
137 if (stringEndIterator == m_data.end()) 137 if (stringEndIterator == m_data.end())
156 /*! 156 /*!
157 * \brief Reads in a buffer of the specified length. 157 * \brief Reads in a buffer of the specified length.
158 * \param length Amount of bytes to read. 158 * \param length Amount of bytes to read.
159 * \returns the read buffer. 159 * \returns the read buffer.
160 */ 160 */
161 Vector<unsigned char> Bytestream::readBuffer(int length) 161 ByteArray Bytestream::readBuffer(int length)
162 { 162 {
163 ensureReadSpace(length); 163 ensureReadSpace(length);
164 Vector<unsigned char> result(length); 164 ByteArray result(length);
165 memcpy(result.data(), m_data.data() + m_position, length); 165 memcpy(result.data(), m_data.data() + m_position, length);
166 m_position += length; 166 m_position += length;
167 return result; 167 return result;
168 } 168 }
169 169

mercurial