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 "XDRFileUnMarshaller.h"
00034
00035 #include "Vector.h"
00036 #include "util.h"
00037 #include "InternalErr.h"
00038
00039 XDRFileUnMarshaller::XDRFileUnMarshaller( FILE *out )
00040 : _source( 0 )
00041 {
00042 _source = new_xdrstdio( out, XDR_DECODE ) ;
00043 }
00044
00045 XDRFileUnMarshaller::XDRFileUnMarshaller()
00046 : UnMarshaller(),
00047 _source( 0 )
00048 {
00049 throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ;
00050 }
00051
00052 XDRFileUnMarshaller::XDRFileUnMarshaller( const XDRFileUnMarshaller &um )
00053 : UnMarshaller( um ),
00054 _source( 0 )
00055 {
00056 throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ;
00057 }
00058
00059 XDRFileUnMarshaller &
00060 XDRFileUnMarshaller::operator=( const XDRFileUnMarshaller & )
00061 {
00062 throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ;
00063
00064 return *this ;
00065 }
00066
00067 XDRFileUnMarshaller::~XDRFileUnMarshaller( )
00068 {
00069 delete_xdrstdio( _source ) ;
00070 }
00071
00072 void
00073 XDRFileUnMarshaller::get_byte( dods_byte &val )
00074 {
00075 if( !xdr_char( _source, (char *)&val ) )
00076 throw Error("Network I/O Error. Could not read byte data. This may be due to a\nbug in DODS or a problem with the network connection.");
00077 }
00078
00079 void
00080 XDRFileUnMarshaller::get_int16( dods_int16 &val )
00081 {
00082 if( !XDR_INT16( _source, &val ) )
00083 throw Error("Network I/O Error. Could not read int 16 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00084 }
00085
00086 void
00087 XDRFileUnMarshaller::get_int32( dods_int32 &val )
00088 {
00089 if( !XDR_INT32( _source, &val ) )
00090 throw Error("Network I/O Error. Could not read int 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00091 }
00092
00093 void
00094 XDRFileUnMarshaller::get_float32( dods_float32 &val )
00095 {
00096 if( !xdr_float( _source, &val ) )
00097 throw Error("Network I/O Error. Could not read float 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00098 }
00099
00100 void
00101 XDRFileUnMarshaller::get_float64( dods_float64 &val )
00102 {
00103 if( !xdr_double( _source, &val ) )
00104 throw Error("Network I/O Error. Could not read float 64 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00105 }
00106
00107 void
00108 XDRFileUnMarshaller::get_uint16( dods_uint16 &val )
00109 {
00110 if( !XDR_UINT16( _source, &val ) )
00111 throw Error("Network I/O Error. Could not read uint 16 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00112 }
00113
00114 void
00115 XDRFileUnMarshaller::get_uint32( dods_uint32 &val )
00116 {
00117 if( !XDR_UINT32( _source, &val ) )
00118 throw Error("Network I/O Error. Could not read uint 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00119 }
00120
00121 void
00122 XDRFileUnMarshaller::get_str( string &val )
00123 {
00124 char *in_tmp = NULL ;
00125
00126 if( !xdr_string( _source, &in_tmp, max_str_len ) )
00127 throw Error("Network I/O Error. Could not read string data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00128
00129 val = in_tmp ;
00130
00131 free( in_tmp ) ;
00132 }
00133
00134 void
00135 XDRFileUnMarshaller::get_url( string &val )
00136 {
00137 get_str( val ) ;
00138 }
00139
00140 void
00141 XDRFileUnMarshaller::get_opaque( char *val, unsigned int len )
00142 {
00143 xdr_opaque( _source, val, len ) ;
00144 }
00145
00146 void
00147 XDRFileUnMarshaller::get_int( int &val )
00148 {
00149 if( !xdr_int( _source, &val ) )
00150 throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
00151 }
00152
00153 void
00154 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, Vector & )
00155 {
00156 if( !xdr_bytes( _source, val, &num, DODS_MAX_ARRAY) )
00157 throw Error("Network I/O error. Could not read packed array data.\nThis may be due to a bug in libdap or a problem with\nthe network connection.");
00158 }
00159
00160 void
00161 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, int width, Vector &vec )
00162 {
00163 BaseType *var = vec.var() ;
00164
00165 if( !xdr_array( _source, val, &num, DODS_MAX_ARRAY, width,
00166 XDRUtils::xdr_coder( var->type() ) ) )
00167 {
00168 throw Error("Network I/O error. Could not read packed array data.\nThis may be due to a bug in libdap or a problem with\nthe network connection.");
00169 }
00170 }
00171
00172 void
00173 XDRFileUnMarshaller::dump(ostream &strm) const
00174 {
00175 strm << DapIndent::LMarg << "XDRFileUnMarshaller::dump - ("
00176 << (void *)this << ")" << endl ;
00177 }
00178