sources/network/bytestream.cpp

branch
protocol5
changeset 141
d9073c13dc98
parent 137
485cb6d6b98c
child 157
42bb29924218
equal deleted inserted replaced
136:8fb1c657e0b0 141:d9073c13dc98
147 int16_t Bytestream::read_short() 147 int16_t Bytestream::read_short()
148 { 148 {
149 ensure_read_space (2); 149 ensure_read_space (2);
150 short int result = 0; 150 short int result = 0;
151 151
152 for (int i = 0; i < 2; ++i) 152 for (int i : range(2))
153 result |= m_cursor[i] << (i * 8); 153 result |= m_cursor[i] << (i * 8);
154 154
155 m_cursor += 2; 155 m_cursor += 2;
156 return result; 156 return result;
157 } 157 }
161 int32_t Bytestream::read_long() 161 int32_t Bytestream::read_long()
162 { 162 {
163 ensure_read_space (4); 163 ensure_read_space (4);
164 long int result = 0; 164 long int result = 0;
165 165
166 for (int i = 0; i < 4; ++i) 166 for (int i : range(4))
167 result |= m_cursor[i] << (i * 8); 167 result |= m_cursor[i] << (i * 8);
168 168
169 m_cursor += 4; 169 m_cursor += 4;
170 return result; 170 return result;
171 } 171 }
256 // 256 //
257 void Bytestream::write_short (int16_t val) 257 void Bytestream::write_short (int16_t val)
258 { 258 {
259 grow_to_fit (2); 259 grow_to_fit (2);
260 260
261 for (int i = 0; i < 2; ++i) 261 for (int i : range(2))
262 write ((val >> (i * 8)) & 0xFF); 262 write ((val >> (i * 8)) & 0xFF);
263 } 263 }
264 264
265 // ------------------------------------------------------------------------------------------------- 265 // -------------------------------------------------------------------------------------------------
266 // 266 //
267 void Bytestream::write_long (int32_t val) 267 void Bytestream::write_long (int32_t val)
268 { 268 {
269 grow_to_fit (4); 269 grow_to_fit (4);
270 270
271 for (int i = 0; i < 4; ++i) 271 for (int i : range(4))
272 write ((val >> (i * 8)) & 0xFF); 272 write ((val >> (i * 8)) & 0xFF);
273 } 273 }
274 274
275 // ------------------------------------------------------------------------------------------------- 275 // -------------------------------------------------------------------------------------------------
276 // 276 //

mercurial