00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __OSL_PUP_TONETWORK_H
00009 #define __OSL_PUP_TONETWORK_H
00010
00011 #include "pup.h"
00012
00013
00014 typedef CMK_TYPEDEF_INT4 CMK_NETWORK_INT4;
00015 #ifdef CMK_PUP_LONG_LONG
00016 typedef CMK_PUP_LONG_LONG CMK_NETWORK_INT8;
00017 #else
00018 typedef CMK_TYPEDEF_INT8 CMK_NETWORK_INT8;
00019 #endif
00020
00022 typedef CMK_NETWORK_INT4 CMK_FLOAT_SIZED_INT;
00024 typedef CMK_NETWORK_INT8 CMK_DOUBLE_SIZED_INT;
00025
00026 #if CMK_SIZET_64BIT
00027 typedef CMK_NETWORK_INT8 CMK_POINTER_SIZED_INT;
00028 #else
00029 typedef CMK_NETWORK_INT4 CMK_POINTER_SIZED_INT;
00030 #endif
00031
00032 class PUP_toNetwork_sizer : public PUP::er {
00033 size_t nBytes;
00034 virtual void bytes(void *p,size_t n,size_t itemSize,PUP::dataType t);
00035 public:
00036 PUP_toNetwork_sizer(void) :PUP::er(IS_SIZING), nBytes(0) {}
00037 size_t size(void) const {return nBytes;}
00038 };
00039
00040 class PUP_toNetwork_pack : public PUP::er {
00041 unsigned char *buf,*start;
00042 inline void w(CMK_NETWORK_INT4 i) {
00043
00044 *buf++=(unsigned char)(i>>24);
00045 *buf++=(unsigned char)(i>>16);
00046 *buf++=(unsigned char)(i>>8);
00047 *buf++=(unsigned char)(i>>0);
00048 }
00049 inline void w(CMK_NETWORK_INT8 i) {
00050 w(CMK_NETWORK_INT4(i>>32));
00051 w(CMK_NETWORK_INT4(i));
00052 }
00053
00054
00055 inline void w(float f) {
00056 union { float f; CMK_FLOAT_SIZED_INT i; } uaw;
00057 uaw.f=f;
00058 w(uaw.i);
00059
00060 }
00061
00062 inline void w(double f) {
00063 union { double f; CMK_DOUBLE_SIZED_INT i; } uaw;
00064 uaw.f=f;
00065 w(uaw.i);
00066
00067 }
00068
00069 virtual void bytes(void *p,size_t n,size_t itemSize,PUP::dataType t);
00070 public:
00071 PUP_toNetwork_pack(void *dest) :PUP::er(IS_PACKING) {
00072 start=buf=(unsigned char *)dest;
00073 CmiAssert(sizeof(void *) == sizeof(CMK_POINTER_SIZED_INT));
00074 }
00075 inline size_t size(void) const {return buf-start;}
00076 };
00077
00078 class PUP_toNetwork_unpack : public PUP::er {
00079 const unsigned char *buf,*start;
00080 inline CMK_NETWORK_INT4 read_int(void) {
00081
00082 CMK_NETWORK_INT4 ret=(buf[0]<<24)|(buf[1]<<16)|(buf[2]<<8)|(buf[3]);
00083 buf+=4;
00084 return ret;
00085 }
00086 inline CMK_NETWORK_INT8 read_CMK_NETWORK_INT8(void) {
00087 CMK_NETWORK_INT8 hi=0xffFFffFFu&(CMK_NETWORK_INT8)read_int();
00088 CMK_NETWORK_INT8 lo=0xffFFffFFu&(CMK_NETWORK_INT8)read_int();
00089 return (hi<<32)|(lo);
00090 }
00091 inline void read_integer(CMK_NETWORK_INT4 &i) { i=read_int(); }
00092 inline void read_integer(CMK_NETWORK_INT8 &i) { i=read_CMK_NETWORK_INT8(); }
00093
00094 inline float read_float(void) {
00095 union { float f; CMK_FLOAT_SIZED_INT i; } uaw;
00096 read_integer(uaw.i);
00097 return uaw.f;
00098
00099
00100 }
00101 inline double read_double(void) {
00102 union { double f; CMK_DOUBLE_SIZED_INT i; } uaw;
00103 read_integer(uaw.i);
00104 return uaw.f;
00105
00106
00107 }
00108 inline void * read_CMK_POINTER_SIZED_INT(void) {
00109 CMK_POINTER_SIZED_INT i;
00110 read_integer(i);
00111 return *(void **)&i;
00112 }
00113
00114 virtual void bytes(void *p,size_t n,size_t itemSize,PUP::dataType t);
00115 public:
00116 PUP_toNetwork_unpack(const void *src) :PUP::er(IS_UNPACKING) {
00117 start=buf=(const unsigned char *)src;
00118 }
00119 inline size_t size(void) const {return buf-start;}
00120 };
00121
00122 #endif
00123