00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "XDRFileMarshaller.h"
00034
00035 #include "Vector.h"
00036 #include "util.h"
00037 #include "InternalErr.h"
00038
00039 XDRFileMarshaller::XDRFileMarshaller( FILE *out )
00040 : _sink( 0 )
00041 {
00042 _sink = new_xdrstdio( out, XDR_ENCODE ) ;
00043 }
00044
00045 XDRFileMarshaller::XDRFileMarshaller()
00046 : Marshaller(),
00047 _sink( 0 )
00048 {
00049 throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ;
00050 }
00051
00052 XDRFileMarshaller::XDRFileMarshaller( const XDRFileMarshaller &m )
00053 : Marshaller( m ),
00054 _sink( 0 )
00055 {
00056 throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ;
00057 }
00058
00059 XDRFileMarshaller &
00060 XDRFileMarshaller::operator=( const XDRFileMarshaller & )
00061 {
00062 throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ;
00063
00064 return *this ;
00065 }
00066
00067 XDRFileMarshaller::~XDRFileMarshaller( )
00068 {
00069 delete_xdrstdio( _sink ) ;
00070 }
00071
00072 void
00073 XDRFileMarshaller::put_byte( dods_byte val )
00074 {
00075 if( !xdr_char( _sink, (char *)&val ) )
00076 throw Error("Network I/O Error. Could not send byte data.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
00077 }
00078
00079 void
00080 XDRFileMarshaller::put_int16( dods_int16 val )
00081 {
00082 if( !XDR_INT16( _sink, &val ) )
00083 throw Error("Network I/O Error. Could not send int 16 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00084 }
00085
00086 void
00087 XDRFileMarshaller::put_int32( dods_int32 val )
00088 {
00089 if( !XDR_INT32( _sink, &val ) )
00090 throw Error("Network I/O Error. Culd not read int 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00091 }
00092
00093 void
00094 XDRFileMarshaller::put_float32( dods_float32 val )
00095 {
00096 if( !xdr_float( _sink, &val ) )
00097 throw Error("Network I/O Error. Could not send float 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00098 }
00099
00100 void
00101 XDRFileMarshaller::put_float64( dods_float64 val )
00102 {
00103 if( !xdr_double( _sink, &val ) )
00104 throw Error("Network I/O Error. Could not send float 64 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00105 }
00106
00107 void
00108 XDRFileMarshaller::put_uint16( dods_uint16 val )
00109 {
00110 if( !XDR_UINT16( _sink, &val ) )
00111 throw Error("Network I/O Error. Could not send uint 16 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00112 }
00113
00114 void
00115 XDRFileMarshaller::put_uint32( dods_uint32 val )
00116 {
00117 if( !XDR_UINT32( _sink, &val ) )
00118 throw Error("Network I/O Error. Could not send uint 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00119 }
00120
00121 void
00122 XDRFileMarshaller::put_str( const string &val )
00123 {
00124 const char *out_tmp = val.c_str() ;
00125
00126 if( !xdr_string( _sink, (char **)&out_tmp, max_str_len) )
00127 throw Error("Network I/O Error. Could not send string data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00128 }
00129
00130 void
00131 XDRFileMarshaller::put_url( const string &val )
00132 {
00133 put_str( val ) ;
00134 }
00135
00136 void
00137 XDRFileMarshaller::put_opaque( char *val, unsigned int len )
00138 {
00139 if( !xdr_opaque( _sink, val, len ) )
00140 throw Error("Network I/O Error. Could not send opaque data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00141 }
00142
00143 void
00144 XDRFileMarshaller::put_int( int val )
00145 {
00146 if( !xdr_int( _sink, &val) )
00147 throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
00148 }
00149
00150 void
00151 XDRFileMarshaller::put_vector( char *val, int num, Vector & )
00152 {
00153 if (!val)
00154 throw InternalErr(__FILE__, __LINE__,
00155 "Buffer pointer is not set.");
00156
00157 put_int( num ) ;
00158
00159 if( !xdr_bytes( _sink, (char **)&val,
00160 (unsigned int *) &num,
00161 DODS_MAX_ARRAY) )
00162 {
00163 throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
00164 }
00165 }
00166
00167 void
00168 XDRFileMarshaller::put_vector( char *val, int num, int width, Vector &vec )
00169 {
00170 if (!val)
00171 throw InternalErr(__FILE__, __LINE__,
00172 "Buffer pointer is not set.");
00173
00174 put_int( num ) ;
00175
00176 BaseType *var = vec.var() ;
00177 if( !xdr_array( _sink, (char **)&val,
00178 (unsigned int *) & num,
00179 DODS_MAX_ARRAY, width,
00180 XDRUtils::xdr_coder( var->type() ) ) )
00181 {
00182 throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
00183 }
00184 }
00185
00186 void
00187 XDRFileMarshaller::dump(ostream &strm) const
00188 {
00189 strm << DapIndent::LMarg << "XDRFileMarshaller::dump - ("
00190 << (void *)this << ")" << endl ;
00191 }
00192