XDRFileMarshaller.cc

Go to the documentation of this file.
00001 // XDRFileMarshaller.cc
00002 
00003 #include "XDRFileMarshaller.h"
00004 
00005 #include "Vector.h"
00006 #include "util.h"
00007 
00008 XDRFileMarshaller::XDRFileMarshaller( FILE *out )
00009     : _sink( 0 )
00010 {
00011     _sink = new_xdrstdio( out, XDR_ENCODE ) ;
00012 }
00013 
00014 XDRFileMarshaller::~XDRFileMarshaller( )
00015 {
00016     delete_xdrstdio( _sink ) ;
00017 }
00018 
00019 void
00020 XDRFileMarshaller::put_byte( dods_byte val )
00021 {
00022     if( !xdr_char( _sink, (char *)&val ) )
00023         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.");
00024 }
00025 
00026 void
00027 XDRFileMarshaller::put_int16( dods_int16 val )
00028 {
00029     if( !XDR_INT16( _sink, &val ) )
00030         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.");
00031 }
00032 
00033 void
00034 XDRFileMarshaller::put_int32( dods_int32 val )
00035 {
00036     if( !XDR_INT32( _sink, &val ) )
00037         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.");
00038 }
00039 
00040 void
00041 XDRFileMarshaller::put_float32( dods_float32 val )
00042 {
00043     if( !xdr_float( _sink, &val ) )
00044         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.");
00045 }
00046 
00047 void
00048 XDRFileMarshaller::put_float64( dods_float64 val )
00049 {
00050     if( !xdr_double( _sink, &val ) )
00051         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.");
00052 }
00053 
00054 void
00055 XDRFileMarshaller::put_uint16( dods_uint16 val )
00056 {
00057     if( !XDR_UINT16( _sink, &val ) )
00058         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.");
00059 }
00060 
00061 void
00062 XDRFileMarshaller::put_uint32( dods_uint32 val )
00063 {
00064     if( !XDR_UINT32( _sink, &val ) )
00065         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.");
00066 }
00067 
00068 void
00069 XDRFileMarshaller::put_str( const string &val )
00070 {
00071     const char *out_tmp = val.c_str() ;
00072 
00073     if( !xdr_string( _sink, (char **)&out_tmp, max_str_len) )
00074         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.");
00075 }
00076 
00077 void
00078 XDRFileMarshaller::put_url( const string &val )
00079 {
00080     put_str( val ) ;
00081 }
00082 
00083 void
00084 XDRFileMarshaller::put_opaque( char *val, unsigned int len )
00085 {
00086     if( !xdr_opaque( _sink, val, len ) )
00087         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.");
00088 }
00089 
00090 void
00091 XDRFileMarshaller::put_int( int val )
00092 {
00093     if( !xdr_int( _sink, &val) )
00094         throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
00095 }
00096 
00097 void
00098 XDRFileMarshaller::put_vector( char *val, int num, Vector & )
00099 {
00100     if (!val)
00101         throw InternalErr(__FILE__, __LINE__,
00102                           "Buffer pointer is not set.");
00103 
00104     put_int( num ) ;
00105 
00106     if( !xdr_bytes( _sink, (char **)&val,
00107                     (unsigned int *) &num,
00108                     DODS_MAX_ARRAY) )
00109     {
00110         throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
00111     }
00112 }
00113 
00114 void
00115 XDRFileMarshaller::put_vector( char *val, int num, int width, Vector &vec )
00116 {
00117     if (!val)
00118         throw InternalErr(__FILE__, __LINE__,
00119                           "Buffer pointer is not set.");
00120 
00121     put_int( num ) ;
00122 
00123     BaseType *var = vec.var() ;
00124     if( !xdr_array( _sink, (char **)&val,
00125                     (unsigned int *) & num,
00126                     DODS_MAX_ARRAY, width,
00127                     XDRUtils::xdr_coder( var->type() ) ) )
00128     {
00129         throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
00130     }
00131 }
00132 
00133 void
00134 XDRFileMarshaller::dump(ostream &strm) const
00135 {
00136     strm << DapIndent::LMarg << "XDRFileMarshaller::dump - ("
00137          << (void *)this << ")" << endl ;
00138 }
00139 

Generated on Wed Nov 14 03:15:44 2007 for libdap++ by  doxygen 1.5.1