… | |
… | |
255 | }; |
255 | }; |
256 | |
256 | |
257 | /* Contains the base information we use to make up a packet we want to send. */ |
257 | /* Contains the base information we use to make up a packet we want to send. */ |
258 | struct SockList |
258 | struct SockList |
259 | { |
259 | { |
260 | uint8 *buf; |
|
|
261 | int len; |
|
|
262 | |
|
|
263 | // SockList () buf (0), len (0) { } |
260 | SockList () : buf (0), len (0) { } |
264 | // SockList (int size) buf (malloc (size)), len (0) { } |
261 | SockList (int size) : buf ((uint8 *)malloc (size)), len (0) { } |
|
|
262 | |
|
|
263 | int length () const { return len; } |
265 | |
264 | |
266 | SockList &operator <<(uint8 v) { buf [len++] = v; return *this; } |
265 | SockList &operator <<(uint8 v) { buf [len++] = v; return *this; } |
267 | |
266 | |
268 | SockList &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); } |
267 | SockList &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); } |
269 | SockList &operator <<(uint32 v) { return *this << uint16 (v >> 16) << uint16 (v); } |
268 | SockList &operator <<(uint32 v) { return *this << uint16 (v >> 16) << uint16 (v); } |
… | |
… | |
274 | SockList &operator <<(sint32 v) { return *this << (uint32)v; } |
273 | SockList &operator <<(sint32 v) { return *this << (uint32)v; } |
275 | SockList &operator <<(sint64 v) { return *this << (uint64)v; } |
274 | SockList &operator <<(sint64 v) { return *this << (uint64)v; } |
276 | |
275 | |
277 | SockList &operator <<(const data8 &v); |
276 | SockList &operator <<(const data8 &v); |
278 | SockList &operator <<(const data16 &v); |
277 | SockList &operator <<(const data16 &v); |
|
|
278 | |
|
|
279 | SockList &operator <<(const char *v); |
|
|
280 | |
|
|
281 | void free () { ::free (buf); } |
|
|
282 | |
|
|
283 | public: |
|
|
284 | uint8 *buf; |
|
|
285 | int len; |
279 | }; |
286 | }; |
280 | |
287 | |
281 | inline void SockList_AddChar (SockList *sl, uint8 data) { *sl << data; } |
288 | inline void SockList_AddChar (SockList *sl, uint8 data) { *sl << data; } |
282 | inline void SockList_AddShort(SockList *sl, uint16 data) { *sl << data; } |
289 | inline void SockList_AddShort(SockList *sl, uint16 data) { *sl << data; } |
283 | inline void SockList_AddInt (SockList *sl, uint32 data) { *sl << data; } |
290 | inline void SockList_AddInt (SockList *sl, uint32 data) { *sl << data; } |