12#include "wvstringlist.h"
22#include <netinet/in.h>
26typedef unsigned __int8 uint8_t;
27typedef __int16 int16_t;
28typedef unsigned __int16 uint16_t;
29typedef __int32 int32_t;
30typedef unsigned __int32 uint32_t;
31typedef __int64 int64_t;
32typedef unsigned __int64 uint64_t;
44inline void wv_serialize(
WvBuf &buf,
const T &t)
46 _wv_serialize(buf, t);
54inline int32_t _wv_htonl(int32_t i)
58inline int16_t _wv_htons(int16_t i)
66inline uint64_t ntohll(uint64_t n)
71 return (((uint64_t)ntohl(n)) << 32) | ntohl(n >> 32);
75inline uint64_t htonll(uint64_t n)
80 return (((uint64_t)htonl(n)) << 32) | htonl(n >> 32);
94void wv_serialize_scalar(
WvBuf &buf,
const T t)
98 int64_t i = htonll(t);
101 else if (
sizeof(T) == 4)
103 int32_t i = _wv_htonl(t);
106 else if (
sizeof(T) == 2)
108 int32_t i = _wv_htons(t);
111 else if (
sizeof(T) == 1)
117inline void _wv_serialize(
WvBuf &buf,
long long i)
118 { wv_serialize_scalar(buf, i); }
119inline void _wv_serialize(
WvBuf &buf,
unsigned long long i)
120 { wv_serialize_scalar(buf, i); }
121inline void _wv_serialize(
WvBuf &buf,
long i)
122 { wv_serialize_scalar(buf, i); }
123inline void _wv_serialize(
WvBuf &buf,
unsigned long i)
124 { wv_serialize_scalar(buf, i); }
125inline void _wv_serialize(
WvBuf &buf,
int i)
126 { wv_serialize_scalar(buf, i); }
127inline void _wv_serialize(
WvBuf &buf,
unsigned int i)
128 { wv_serialize_scalar(buf, i); }
129inline void _wv_serialize(
WvBuf &buf,
short i)
130 { wv_serialize_scalar(buf, i); }
131inline void _wv_serialize(
WvBuf &buf,
unsigned short i)
132 { wv_serialize_scalar(buf, i); }
133inline void _wv_serialize(
WvBuf &buf,
bool i)
134 { wv_serialize_scalar(buf, i); }
137inline void _wv_serialize(
WvBuf &buf,
char i)
138 { wv_serialize_scalar(buf, i); }
139inline void _wv_serialize(
WvBuf &buf,
signed char i)
140 { wv_serialize_scalar(buf, i); }
141inline void _wv_serialize(
WvBuf &buf,
unsigned char i)
142 { wv_serialize_scalar(buf, i); }
159inline void wv_serialize(
WvBuf &buf,
const char *t)
161 _wv_serialize(buf, t);
169inline void _wv_serialize(
WvBuf &buf,
const WvBuf &inbuf)
171 wv_serialize(buf, inbuf.
used());
172 buf.put(
const_cast<WvBuf *
>(&inbuf)->peek(0, inbuf.
used()), inbuf.
used());
185 _wv_serialize(buf, (
size_t)list.
count());
189 for (i.rewind(); i.next(); )
190 _wv_serialize(buf, *i);
197 T _wv_deserialize(
WvBuf &buf);
211 static T go(
WvBuf &buf)
212 {
return _wv_deserialize<T>(buf); }
234 static T *go(
WvBuf &buf)
235 {
return new T(_wv_deserialize<T>(buf)); }
260inline T wv_deserialize(
WvBuf &buf)
270inline int32_t _wv_ntohl(int32_t i)
274inline int16_t _wv_ntohs(int16_t i)
286inline T wv_deserialize_scalar(
WvBuf &buf)
288 if (buf.
used() <
sizeof(T))
292 return (T) ntohll(*(int64_t *)buf.
get(8));
293 else if (
sizeof(T) == 4)
294 return (T) _wv_ntohl(*(int32_t *)buf.
get(4));
295 else if (
sizeof(T) == 2)
296 return (T) _wv_ntohs(*(int16_t *)buf.
get(2));
297 else if (
sizeof(T) == 1)
298 return (T) *(int8_t *)buf.
get(1);
304inline T xwv_deserialize_scalar(
WvBuf &buf)
310 inline long long _wv_deserialize<long long>(
WvBuf &buf)
311 {
return wv_deserialize_scalar<long long>(buf); }
313 inline unsigned long long _wv_deserialize<unsigned long long>(
WvBuf &buf)
314 {
return wv_deserialize_scalar<unsigned long long>(buf); }
316 inline long _wv_deserialize<long>(
WvBuf &buf)
317 {
return wv_deserialize_scalar<long>(buf); }
319 inline unsigned long _wv_deserialize<unsigned long>(
WvBuf &buf)
320 {
return wv_deserialize_scalar<unsigned long>(buf); }
322 inline int _wv_deserialize<int>(
WvBuf &buf)
323 {
return wv_deserialize_scalar<int>(buf); }
325 inline unsigned int _wv_deserialize<unsigned int>(
WvBuf &buf)
326 {
return wv_deserialize_scalar<unsigned int>(buf); }
328 inline short _wv_deserialize<short>(
WvBuf &buf)
329 {
return wv_deserialize_scalar<short>(buf); }
331 inline unsigned short _wv_deserialize<unsigned short>(
WvBuf &buf)
332 {
return wv_deserialize_scalar<unsigned short>(buf); }
334 inline bool _wv_deserialize<bool>(
WvBuf &buf)
335 {
return wv_deserialize_scalar<bool>(buf); }
337 inline char _wv_deserialize<char>(
WvBuf &buf)
338 {
return wv_deserialize_scalar<char>(buf); }
340 inline signed char _wv_deserialize<signed char>(
WvBuf &buf)
341 {
return wv_deserialize_scalar<signed char>(buf); }
343 inline unsigned char _wv_deserialize<unsigned char>(
WvBuf &buf)
344 {
return wv_deserialize_scalar<unsigned char>(buf); }
363 size_t len = wv_deserialize<size_t>(buf);
365 outbuf->
merge(buf, len);
379 size_t nelems = wv_deserialize<size_t>(buf);
381 for (
size_t count = 0; count < nelems; count++)
383 T t = wv_deserialize<T>(buf);
384 list->
append(
new T(t),
true);
398 size_t nelems = wv_deserialize<size_t>(buf);
400 for (
size_t count = 0; count < nelems; count++)
402 WvString str = wv_deserialize<WvString>(buf);
void merge(Buffer &inbuf, size_t count)
Efficiently moves count bytes from the specified buffer into this one.
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
size_t used() const
Returns the number of elements in the buffer currently available for reading.
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
void putstr(WvStringParm str)
Copies a WvString into the buffer, excluding the null-terminator.
Deserialize a complex templated object.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
bool isnull() const
returns true if this string is null
The in place raw memory buffer type.
size_t count() const
Returns the number of elements in the list.
The iterator type for linked lists.
A linked list container class.
void append(T *data, bool autofree, const char *id=NULL)
Appends the element to the end of the list.
This is a WvList of WvStrings, and is a really handy way to parse strings.
WvString is an implementation of a simple and efficient printable-string class.