… | |
… | |
263 | data16 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
263 | data16 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
264 | data16 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } |
264 | data16 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } |
265 | }; |
265 | }; |
266 | |
266 | |
267 | /* Contains the base information we use to make up a packet we want to send. */ |
267 | /* Contains the base information we use to make up a packet we want to send. */ |
268 | struct SockList |
268 | struct packet |
269 | { |
269 | { |
270 | SockList (int size) : buf ((uint8 *)malloc (size)), len (0) { } |
270 | packet () : buf ((uint8 *)malloc (MAXSOCKBUF)), len (0) { } |
|
|
271 | ~packet () { free (buf); } |
271 | |
272 | |
272 | void reset () { len = 0; } |
273 | void reset () { len = 0; } |
273 | int length () const { return len; } |
274 | int length () const { return len; } |
274 | |
275 | |
275 | SockList &operator <<(uint8 v) { buf [len++] = v; return *this; } |
276 | packet &operator <<(uint8 v) { buf [len++] = v; return *this; } |
276 | |
277 | |
277 | SockList &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); } |
278 | packet &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); } |
278 | SockList &operator <<(uint32 v) { return *this << uint16 (v >> 16) << uint16 (v); } |
279 | packet &operator <<(uint32 v) { return *this << uint16 (v >> 16) << uint16 (v); } |
279 | SockList &operator <<(uint64 v) { return *this << uint32 (v >> 32) << uint32 (v); } |
280 | packet &operator <<(uint64 v) { return *this << uint32 (v >> 32) << uint32 (v); } |
280 | |
281 | |
281 | SockList &operator <<(sint8 v) { return *this << (uint8 )v; } |
282 | packet &operator <<(sint8 v) { return *this << (uint8 )v; } |
282 | SockList &operator <<(sint16 v) { return *this << (uint16)v; } |
283 | packet &operator <<(sint16 v) { return *this << (uint16)v; } |
283 | SockList &operator <<(sint32 v) { return *this << (uint32)v; } |
284 | packet &operator <<(sint32 v) { return *this << (uint32)v; } |
284 | SockList &operator <<(sint64 v) { return *this << (uint64)v; } |
285 | packet &operator <<(sint64 v) { return *this << (uint64)v; } |
285 | |
286 | |
286 | SockList &operator <<(const data &v); |
287 | packet &operator <<(const data &v); |
287 | SockList &operator <<(const data8 &v); |
288 | packet &operator <<(const data8 &v); |
288 | SockList &operator <<(const data16 &v); |
289 | packet &operator <<(const data16 &v); |
289 | |
290 | |
290 | SockList &operator <<(const char *v); |
291 | packet &operator <<(const char *v); |
291 | SockList &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); } |
292 | packet &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); } |
292 | |
293 | |
293 | void printf (const char *format, ...); |
294 | void printf (const char *format, ...); |
294 | |
|
|
295 | void free () { ::free (buf); } |
|
|
296 | |
295 | |
297 | public: |
296 | public: |
298 | uint8 *buf; |
297 | uint8 *buf; |
299 | int len; |
298 | int len; |
300 | }; |
299 | }; |