Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

wvserialize.h File Reference

#include "wvbuf.h"
#include <stdint.h>
#include <netinet/in.h>

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  WvDeserialize< T >
 Deserialize a complex templated object. More...
class  WvDeserialize< T * >
 If there's a deserializer for type "T", this will make a default deserializer for type "T *"; that is, it'll allocate the new object dynamically and you'll have to free it after. More...
class  WvDeserialize< WvBuf * >
 Deserialize a WvBuf. More...
class  WvDeserialize< WvList< T > * >
 Deserialize a list of serializable things. More...

Functions

template<typename T>
void wv_serialize (WvBuf &buf, const T &t)
 Encode an object as an array of bytes and put it into a WvBuf.
int32_t _wv_htonl (int32_t i)
 This function shouldn't be necessary at all, but using it makes totally insane assembler errors go away (gcc 2.95.4, glibc 2.3.1).
template<typename T>
void wv_serialize_scalar (WvBuf &buf, const T t)
 A helper function that serializes different types of integers.
void _wv_serialize (WvBuf &buf, long long i)
void _wv_serialize (WvBuf &buf, unsigned long long i)
void _wv_serialize (WvBuf &buf, long i)
void _wv_serialize (WvBuf &buf, unsigned long i)
void _wv_serialize (WvBuf &buf, int i)
void _wv_serialize (WvBuf &buf, unsigned int i)
void _wv_serialize (WvBuf &buf, short i)
void _wv_serialize (WvBuf &buf, unsigned short i)
void _wv_serialize (WvBuf &buf, bool i)
void _wv_serialize (WvBuf &buf, char i)
 Note: char != signed char for purposes of function overloading!
void _wv_serialize (WvBuf &buf, signed char i)
void _wv_serialize (WvBuf &buf, unsigned char i)
void _wv_serialize (WvBuf &buf, WvStringParm s)
 Serialize a WvString.
void _wv_serialize (WvBuf &buf, const WvBuf &inbuf)
 Serialize a WvBuf.
template<typename T>
void _wv_serialize (WvBuf &buf, const WvList< T > &list)
 Serialize a list of serializable things.
template<typename T>
T _wv_deserialize (WvBuf &buf)
 Deserialize an object.
template<typename T>
T wv_deserialize (WvBuf &buf)
 Deserialize an object: read bytes from a buffer, and return an object constructed from that.
int32_t _wv_ntohl (int32_t i)
 This function shouldn't be necessary at all, but using it makes totally insane assembler errors go away (gcc 2.95.4, glibc 2.3.1).
template<typename T>
T wv_deserialize_scalar (WvBuf &buf)
 A helper function that deserializes different types of integers.
template<typename T>
T xwv_deserialize_scalar (WvBuf &buf)
template<>
long long _wv_deserialize< long long > (WvBuf &buf)
template<>
unsigned long long _wv_deserialize< unsigned long long > (WvBuf &buf)
template<>
long _wv_deserialize< long > (WvBuf &buf)
template<>
unsigned long _wv_deserialize< unsigned long > (WvBuf &buf)
template<>
int _wv_deserialize< int > (WvBuf &buf)
template<>
unsigned int _wv_deserialize< unsigned int > (WvBuf &buf)
template<>
short _wv_deserialize< short > (WvBuf &buf)
template<>
unsigned short _wv_deserialize< unsigned short > (WvBuf &buf)
template<>
bool _wv_deserialize< bool > (WvBuf &buf)
template<>
char _wv_deserialize< char > (WvBuf &buf)
template<>
signed char _wv_deserialize< signed char > (WvBuf &buf)
template<>
unsigned char _wv_deserialize< unsigned char > (WvBuf &buf)
template<>
WvString _wv_deserialize< WvString > (WvBuf &buf)
 Deserialize a WvString.


Function Documentation

template<typename T>
T _wv_deserialize WvBuf buf  ) 
 

Deserialize an object.

See wv_deserialize().

template<>
bool _wv_deserialize< bool > WvBuf buf  )  [inline]
 

template<>
char _wv_deserialize< char > WvBuf buf  )  [inline]
 

template<>
int _wv_deserialize< int > WvBuf buf  )  [inline]
 

template<>
long _wv_deserialize< long > WvBuf buf  )  [inline]
 

template<>
long long _wv_deserialize< long long > WvBuf buf  )  [inline]
 

template<>
short _wv_deserialize< short > WvBuf buf  )  [inline]
 

template<>
signed char _wv_deserialize< signed char > WvBuf buf  )  [inline]
 

template<>
unsigned char _wv_deserialize< unsigned char > WvBuf buf  )  [inline]
 

template<>
unsigned int _wv_deserialize< unsigned int > WvBuf buf  )  [inline]
 

template<>
unsigned long _wv_deserialize< unsigned long > WvBuf buf  )  [inline]
 

template<>
unsigned long long _wv_deserialize< unsigned long long > WvBuf buf  )  [inline]
 

template<>
unsigned short _wv_deserialize< unsigned short > WvBuf buf  )  [inline]
 

template<>
WvString _wv_deserialize< WvString > WvBuf buf  ) 
 

Deserialize a WvString.

Stops at (and includes) the terminating nul (zero) character. Serialized WvStrings are guaranteed not to contain nul except as the last character.

int32_t _wv_htonl int32_t  i  )  [inline]
 

This function shouldn't be necessary at all, but using it makes totally insane assembler errors go away (gcc 2.95.4, glibc 2.3.1).

Definition at line 34 of file wvserialize.h.

Referenced by wv_serialize_scalar().

int32_t _wv_ntohl int32_t  i  )  [inline]
 

This function shouldn't be necessary at all, but using it makes totally insane assembler errors go away (gcc 2.95.4, glibc 2.3.1).

Definition at line 222 of file wvserialize.h.

Referenced by wv_deserialize_scalar().

template<typename T>
void _wv_serialize WvBuf buf,
const WvList< T > &  list
 

Serialize a list of serializable things.

Oh boy - I think I'm having a bit too much fun.

Definition at line 134 of file wvserialize.h.

References WvListBase::count(), and WvBuf.

Referenced by wv_serialize().

void _wv_serialize WvBuf buf,
const WvBuf inbuf
[inline]
 

Serialize a WvBuf.

This is handier than it sounds, because then WvGdbmHash's value can be a WvBuf.

Definition at line 121 of file wvserialize.h.

References WvBufBase< unsigned char >::put(), WvBufBaseCommonImpl< T >::used(), wv_serialize(), and WvBuf.

void _wv_serialize WvBuf buf,
WvStringParm  s
[inline]
 

Serialize a WvString.

The string serializer is guaranteed to not insert any nuls (character 0) into the output stream except for the string-terminating one, which is always present. This makes deserialization easy.

Definition at line 109 of file wvserialize.h.

References WvFastString::isnull(), WvBufBase< unsigned char >::put(), WvBufBase< unsigned char >::putstr(), WvBuf, and WvStringParm.

void _wv_serialize WvBuf buf,
unsigned char  i
[inline]
 

Definition at line 99 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
signed char  i
[inline]
 

Definition at line 97 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
char  i
[inline]
 

Note: char != signed char for purposes of function overloading!

Definition at line 95 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
bool  i
[inline]
 

Definition at line 91 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
unsigned short  i
[inline]
 

Definition at line 89 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
short  i
[inline]
 

Definition at line 87 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
unsigned int  i
[inline]
 

Definition at line 85 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
int  i
[inline]
 

Definition at line 83 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
unsigned long  i
[inline]
 

Definition at line 81 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
long  i
[inline]
 

Definition at line 79 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
unsigned long long  i
[inline]
 

Definition at line 77 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

void _wv_serialize WvBuf buf,
long long  i
[inline]
 

Definition at line 75 of file wvserialize.h.

References wv_serialize_scalar(), and WvBuf.

template<typename T>
T wv_deserialize WvBuf buf  )  [inline]
 

Deserialize an object: read bytes from a buffer, and return an object constructed from that.

Note that there is no default deserializer. You have to specialize this template for every data type you might want to deserialize. We do define some for a few standard C types.

Implementation note: If you define a deserializer for your own type, name it _wv_deserialize() (with the underscore). If you're unlucky, you may need to define a WvDeserialize class instead.

Note that if you have a data structure, you probably want to wv_deserialize<MyType *>(buf) instead of wv_deserialize<MyType>(buf) to avoid extra copies. You'll have to define _wv_deserialize() appropriately, of course. Pointer-based _wv_deserialize() functions allocate memory, so you'll have to 'delete' the returned object yourself.

Definition at line 212 of file wvserialize.h.

References WvDeserialize< T >::go(), and WvBuf.

template<typename T>
T wv_deserialize_scalar WvBuf buf  )  [inline]
 

A helper function that deserializes different types of integers.

Since it's inlined, the "if" is actually executed at compile time, so don't worry.

Definition at line 234 of file wvserialize.h.

References _wv_ntohl(), WvBufBaseCommonImpl< T >::get(), WvBufBaseCommonImpl< T >::used(), and WvBuf.

template<typename T>
void wv_serialize WvBuf buf,
const T t
[inline]
 

Encode an object as an array of bytes and put it into a WvBuf.

This function just calls an overloaded _wv_serialize() function. There was really no need for a template here at all, except for symmetry with wv_deserialize() which does need one.

Definition at line 24 of file wvserialize.h.

References _wv_serialize(), and WvBuf.

Referenced by _wv_serialize(), WvGdbmHash< K, D >::datumize< T >::datumize(), and WvGdbmList< T >::save().

template<typename T>
void wv_serialize_scalar WvBuf buf,
const T  t
 

A helper function that serializes different types of integers.

Since it's inlined, the "if" is actually executed at compile time, so don't worry.

The clever part: it doesn't really matter what size an 'int' or a 'long' is, as long as it's one of the sizes supported by this function. If an int is 32 bits, we'll use the 32-bit serializer... and so on.

Definition at line 51 of file wvserialize.h.

References _wv_htonl(), WvBufBase< unsigned char >::put(), and WvBuf.

Referenced by _wv_serialize().

template<typename T>
T xwv_deserialize_scalar WvBuf buf  )  [inline]
 

Definition at line 256 of file wvserialize.h.

References WvBuf.


Generated on Wed Dec 15 15:08:13 2004 for WvStreams by  doxygen 1.3.9.1