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