sources/network/bytestream.cpp

changeset 10
3874575d924d
parent 9
e7a09ceb4505
child 11
cffa2777d917
equal deleted inserted replaced
9:e7a09ceb4505 10:3874575d924d
122 { 122 {
123 *ok = false; 123 *ok = false;
124 return false; 124 return false;
125 } 125 }
126 126
127 short int val = 0; 127 short int result = 0;
128 128
129 for (int i = 0; i < 2; ++i) 129 for (int i = 0; i < 2; ++i)
130 val |= *m_cursor++ << (i * 8); 130 result |= m_cursor[i] << (i * 8);
131 131
132 *ok = true; 132 m_cursor += 2;
133 return true; 133 return result;
134 } 134 }
135 135
136 // ------------------------------------------------------------------------------------------------- 136 // -------------------------------------------------------------------------------------------------
137 // 137 //
138 long int Bytestream::read_long (bool* ok) 138 long int Bytestream::read_long (bool* ok)
141 { 141 {
142 *ok = false; 142 *ok = false;
143 return -1; 143 return -1;
144 } 144 }
145 145
146 long int val = 0; 146 long int result = 0;
147 147
148 for (int i = 0; i < 4; ++i) 148 for (int i = 0; i < 4; ++i)
149 val |= *m_cursor++ << (i * 8); 149 result |= m_cursor[i] << (i * 8);
150 150
151 *ok = true; 151 m_cursor += 4;
152 return val; 152 return result;
153 } 153 }
154 154
155 // ------------------------------------------------------------------------------------------------- 155 // -------------------------------------------------------------------------------------------------
156 // 156 //
157 float Bytestream::read_float (bool* ok) 157 float Bytestream::read_float (bool* ok)
186 return ""; 186 return "";
187 } 187 }
188 } 188 }
189 189
190 m_cursor = stringEnd + 1; 190 m_cursor = stringEnd + 1;
191 *ok = true;
192 unsigned int length = stringEnd - m_cursor; 191 unsigned int length = stringEnd - m_cursor;
193 192
194 // ensure we won't write past the buffer (note: we still moved 193 // ensure we won't write past the buffer (note: we still moved
195 // past the excess bytes in the above statement, those are ignored) 194 // past the excess bytes in the above statement, those are ignored)
196 if (length >= MAX_NETWORK_STRING) 195 if (length >= MAX_NETWORK_STRING)
212 return; 211 return;
213 } 212 }
214 213
215 memcpy (buffer, m_cursor, length); 214 memcpy (buffer, m_cursor, length);
216 m_cursor += length; 215 m_cursor += length;
217 *ok = true;
218 } 216 }
219 217
220 // ------------------------------------------------------------------------------------------------- 218 // -------------------------------------------------------------------------------------------------
221 // 219 //
222 void Bytestream::write (unsigned char val) 220 void Bytestream::write (unsigned char val)

mercurial