00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include "converse.h"
00010 #include "pup.h"
00011 #include "pup_toNetwork.h"
00012
00013
00014
00015
00016 void PUP_toNetwork_sizer::bytes(void *p,size_t n,size_t itemSize,PUP::dataType t)
00017 {
00018 switch (t) {
00019 case PUP::Tchar:
00020 case PUP::Tuchar:
00021 case PUP::Tbyte:
00022 nBytes+=n;
00023 break;
00024 case PUP::Tulong:
00025 case PUP::Tlong:
00026 case PUP::Tulonglong:
00027 case PUP::Tlonglong:
00028 case PUP::Tdouble:
00029 case PUP::Tlongdouble:
00030 nBytes+=n*8;
00031 break;
00032 case PUP::Tpointer:
00033 nBytes+=n*sizeof(void*);
00034 break;
00035 default:
00036 nBytes+=n*4;
00037 break;
00038 }
00039 }
00040
00041 #define casesPUP_toNetwork_types \
00042 casePUP_toNetwork_type(Tfloat,float,float); \
00043 casePUP_toNetwork_type(Tdouble,double,double); \
00044 case PUP::Tushort: \
00045 casePUP_toNetwork_type(Tshort,short,int); \
00046 case PUP::Tuint: \
00047 casePUP_toNetwork_type(Tint,int,int); \
00048 case PUP::Tulong: \
00049 casePUP_toNetwork_type(Tlong,long,CMK_NETWORK_INT8); \
00050 case PUP::Tulonglong: \
00051 casePUP_toNetwork_type(Tlonglong,CMK_NETWORK_INT8,CMK_NETWORK_INT8); \
00052 casePUP_toNetwork_type(Tbool,bool,int); \
00053 case PUP::Tsync: break; \
00054 casePUP_toNetwork_type(Tpointer,void*,CMK_POINTER_SIZED_INT);
00055
00056 void PUP_toNetwork_pack::bytes(void *p,size_t n,size_t itemSize,PUP::dataType t)
00057 {
00058 size_t i;
00059 switch (t) {
00060 case PUP::Tchar:
00061 case PUP::Tuchar:
00062 case PUP::Tbyte:
00063 memcpy(buf,p,n);
00064 buf+=n;
00065 break;
00066 #define casePUP_toNetwork_type(enumName,typeName,writeAs) \
00067 case PUP::enumName: \
00068 for (i=0;i<n;i++) \
00069 w((writeAs)( ((typeName *)p)[i] ));\
00070 break
00071 casesPUP_toNetwork_types
00072 #if CMK_LONG_DOUBLE_DEFINED
00073 casePUP_toNetwork_type(Tlongdouble,long double,double);
00074 #endif
00075 #undef casePUP_toNetwork_type
00076
00077 default:
00078 CmiAbort("Unrecognized type passed to PUP_toNetwork_pack!\n");
00079 }
00080 }
00081
00082 void PUP_toNetwork_unpack::bytes(void *p,size_t n,size_t itemSize,PUP::dataType t)
00083 {
00084 size_t i;
00085 switch (t) {
00086 case PUP::Tchar:
00087 case PUP::Tuchar:
00088 case PUP::Tbyte:
00089 memcpy(p,buf,n);
00090 buf+=n;
00091 break;
00092 #define casePUP_toNetwork_type(enumName,typeName,readAs) \
00093 case PUP::enumName: \
00094 for (i=0;i<n;i++) \
00095 ((typeName *)p)[i]=(typeName)read_##readAs();\
00096 break
00097 casesPUP_toNetwork_types
00098 #if CMK_LONG_DOUBLE_DEFINED
00099 casePUP_toNetwork_type(Tlongdouble,long double,double);
00100 #endif
00101 #undef casePUP_toNetwork_type
00102
00103 default:
00104 CmiAbort("Unrecognized type passed to PUP_toNetwork_unpack!\n");
00105 }
00106 }
00107
00108
00109