Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

Serializer.h

Go to the documentation of this file.
00001 #ifndef INCLUDED_Serializer_h
00002 #define INCLUDED_Serializer_h
00003 
00004 //!provides a default serializer base class for simple objects
00005 class Serializer {
00006 public:
00007   
00008 protected:
00009   //! writes @a value to @a dst and advances @a dst
00010   template<class T>
00011   inline static void encode(char **dst, T value) {
00012     memcpy(*dst, (char *)&value, sizeof(T));
00013 //    hostToNetwork(*dst, (char *)&value, sizeof(T));
00014 //    it'd be nice to use network byte order, but we'll save the aibo
00015 //    extra work
00016     (*dst) += sizeof(T);
00017   }
00018 
00019   //! converts to network byte order (big endian - aibo is little endian)
00020   inline static void hostToNetwork(char *dst, char *src, int length) {
00021     for (int i=0; i<length; i++)
00022       dst[length-1-i]=src[i];
00023   }
00024 
00025   //! writes @a length bytes from @a src to @a dst
00026   inline static void encode(char **dst, char *src, int length) {
00027     memcpy(*dst, src, length);
00028     (*dst) +=length;
00029   }
00030 
00031   //! a simple form of compression - calls encode(@a dst,float(@a src[i])) for i=0..@a length
00032   inline static void encodeDoublesAsFloats(char **dst, double *src, int length) {
00033     for (int i=0; i<length; i++)
00034       encode(dst, float(src[i]));
00035   }
00036 };
00037 
00038 /*! @file
00039  * @brief Defines the Serializer base class, which provides a default serializer for simple objects
00040  * @author alokl (Creator)
00041  *
00042  * $Author: ejt $
00043  * $Name: tekkotsu-1_4_1 $
00044  * $Revision: 1.4 $
00045  * $State: Exp $
00046  * $Date: 2003/06/12 18:06:11 $
00047  */
00048 
00049 #endif

Tekkotsu v1.4
Generated Sat Jul 19 00:06:31 2003 by Doxygen 1.3.2