00001
00002
00003 #include "XDRFileUnMarshaller.h"
00004
00005 #include "Vector.h"
00006 #include "util.h"
00007
00008 XDRFileUnMarshaller::XDRFileUnMarshaller( FILE *out )
00009 : _source( 0 )
00010 {
00011 _source = new_xdrstdio( out, XDR_DECODE ) ;
00012 }
00013
00014 XDRFileUnMarshaller::~XDRFileUnMarshaller( )
00015 {
00016 delete_xdrstdio( _source ) ;
00017 }
00018
00019 void
00020 XDRFileUnMarshaller::get_byte( dods_byte &val )
00021 {
00022 if( !xdr_char( _source, (char *)&val ) )
00023 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.");
00024 }
00025
00026 void
00027 XDRFileUnMarshaller::get_int16( dods_int16 &val )
00028 {
00029 if( !XDR_INT16( _source, &val ) )
00030 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.");
00031 }
00032
00033 void
00034 XDRFileUnMarshaller::get_int32( dods_int32 &val )
00035 {
00036 if( !XDR_INT32( _source, &val ) )
00037 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.");
00038 }
00039
00040 void
00041 XDRFileUnMarshaller::get_float32( dods_float32 &val )
00042 {
00043 if( !xdr_float( _source, &val ) )
00044 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.");
00045 }
00046
00047 void
00048 XDRFileUnMarshaller::get_float64( dods_float64 &val )
00049 {
00050 if( !xdr_double( _source, &val ) )
00051 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.");
00052 }
00053
00054 void
00055 XDRFileUnMarshaller::get_uint16( dods_uint16 &val )
00056 {
00057 if( !XDR_UINT16( _source, &val ) )
00058 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.");
00059 }
00060
00061 void
00062 XDRFileUnMarshaller::get_uint32( dods_uint32 &val )
00063 {
00064 if( !XDR_UINT32( _source, &val ) )
00065 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.");
00066 }
00067
00068 void
00069 XDRFileUnMarshaller::get_str( string &val )
00070 {
00071 char *in_tmp = NULL ;
00072
00073 if( !xdr_string( _source, &in_tmp, max_str_len ) )
00074 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.");
00075
00076 val = in_tmp ;
00077
00078 free( in_tmp ) ;
00079 }
00080
00081 void
00082 XDRFileUnMarshaller::get_url( string &val )
00083 {
00084 get_str( val ) ;
00085 }
00086
00087 void
00088 XDRFileUnMarshaller::get_opaque( char *val, unsigned int len )
00089 {
00090 xdr_opaque( _source, val, len ) ;
00091 }
00092
00093 void
00094 XDRFileUnMarshaller::get_int( int &val )
00095 {
00096 if( !xdr_int( _source, &val ) )
00097 throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
00098 }
00099
00100 void
00101 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, Vector & )
00102 {
00103 if( !xdr_bytes( _source, val, &num, DODS_MAX_ARRAY) )
00104 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.");
00105 }
00106
00107 void
00108 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, int width, Vector &vec )
00109 {
00110 BaseType *var = vec.var() ;
00111
00112 if( !xdr_array( _source, val, &num, DODS_MAX_ARRAY, width,
00113 XDRUtils::xdr_coder( var->type() ) ) )
00114 {
00115 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.");
00116 }
00117 }
00118
00119 void
00120 XDRFileUnMarshaller::dump(ostream &strm) const
00121 {
00122 strm << DapIndent::LMarg << "XDRFileUnMarshaller::dump - ("
00123 << (void *)this << ")" << endl ;
00124 }
00125