libdap
Updated for version 3.17.0
|
00001 // XDRFileMarshaller.cc 00002 00003 // -*- mode: c++; c-basic-offset:4 -*- 00004 00005 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00006 // Access Protocol. 00007 00008 // Copyright (c) 2002,2003 OPeNDAP, Inc. 00009 // Author: Patrick West <pwest@ucar.edu> 00010 // 00011 // This library is free software; you can redistribute it and/or 00012 // modify it under the terms of the GNU Lesser General Public 00013 // License as published by the Free Software Foundation; either 00014 // version 2.1 of the License, or (at your option) any later version. 00015 // 00016 // This library is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 // Lesser General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License along with this library; if not, write to the Free Software 00023 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00024 // 00025 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00026 00027 // (c) COPYRIGHT URI/MIT 1994-1999 00028 // Please read the full copyright statement in the file COPYRIGHT_URI. 00029 // 00030 // Authors: 00031 // pwest Patrick West <pwest@ucar.edu> 00032 00033 #include "config.h" 00034 00035 #include "XDRFileMarshaller.h" 00036 00037 #include "Byte.h" 00038 #include "Int16.h" 00039 #include "UInt16.h" 00040 #include "Int32.h" 00041 #include "UInt32.h" 00042 #include "Float32.h" 00043 #include "Float64.h" 00044 #include "Str.h" 00045 #include "Url.h" 00046 #include "Array.h" 00047 #include "Structure.h" 00048 #include "Sequence.h" 00049 #include "Grid.h" 00050 00051 #include "util.h" 00052 #include "InternalErr.h" 00053 00054 namespace libdap { 00055 00056 XDRFileMarshaller::XDRFileMarshaller(FILE *out) : 00057 _sink(0)//, d_out(out) 00058 { 00059 _sink = new_xdrstdio(out, XDR_ENCODE); 00060 } 00061 00062 XDRFileMarshaller::XDRFileMarshaller() : 00063 Marshaller(), _sink(0)//, d_out(0) 00064 { 00065 throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented."); 00066 } 00067 00068 XDRFileMarshaller::XDRFileMarshaller(const XDRFileMarshaller &m) : 00069 Marshaller(m), _sink(0)//, d_out(0) 00070 { 00071 throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented."); 00072 } 00073 00074 XDRFileMarshaller & 00075 XDRFileMarshaller::operator=(const XDRFileMarshaller &) 00076 { 00077 throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented."); 00078 00079 return *this; 00080 } 00081 00082 XDRFileMarshaller::~XDRFileMarshaller() 00083 { 00084 delete_xdrstdio(_sink); 00085 } 00086 00087 void XDRFileMarshaller::put_byte(dods_byte val) 00088 { 00089 if (!xdr_char(_sink, (char *) &val)) 00090 throw Error( 00091 "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."); 00092 } 00093 00094 void XDRFileMarshaller::put_int16(dods_int16 val) 00095 { 00096 if (!XDR_INT16(_sink, &val)) 00097 throw Error( 00098 "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."); 00099 } 00100 00101 void XDRFileMarshaller::put_int32(dods_int32 val) 00102 { 00103 if (!XDR_INT32(_sink, &val)) 00104 throw Error( 00105 "Network I/O Error. Could not read int 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection."); 00106 } 00107 00108 void XDRFileMarshaller::put_float32(dods_float32 val) 00109 { 00110 if (!xdr_float(_sink, &val)) 00111 throw Error( 00112 "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."); 00113 } 00114 00115 void XDRFileMarshaller::put_float64(dods_float64 val) 00116 { 00117 if (!xdr_double(_sink, &val)) 00118 throw Error( 00119 "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."); 00120 } 00121 00122 void XDRFileMarshaller::put_uint16(dods_uint16 val) 00123 { 00124 if (!XDR_UINT16(_sink, &val)) 00125 throw Error("Network I/O Error. Could not send uint 16 data."); 00126 } 00127 00128 void XDRFileMarshaller::put_uint32(dods_uint32 val) 00129 { 00130 if (!XDR_UINT32(_sink, &val)) 00131 throw Error("Network I/O Error. Could not send uint 32 data."); 00132 } 00133 00134 void XDRFileMarshaller::put_str(const string &val) 00135 { 00136 const char *out_tmp = val.c_str(); 00137 00138 if (!xdr_string(_sink, (char **) &out_tmp, max_str_len)) 00139 throw Error("Network I/O Error. Could not send string data."); 00140 } 00141 00142 void XDRFileMarshaller::put_url(const string &val) 00143 { 00144 put_str(val); 00145 } 00146 00147 void XDRFileMarshaller::put_opaque(char *val, unsigned int len) 00148 { 00149 if (!xdr_opaque(_sink, val, len)) 00150 throw Error("Network I/O Error. Could not send opaque data."); 00151 } 00152 00153 void XDRFileMarshaller::put_int(int val) 00154 { 00155 if (!xdr_int(_sink, &val)) 00156 throw Error("Network I/O Error(1)."); 00157 } 00158 00159 void XDRFileMarshaller::put_vector(char *val, int num, Vector &) 00160 { 00161 if (!val) throw InternalErr(__FILE__, __LINE__, "Buffer pointer is not set."); 00162 00163 put_int(num); 00164 00165 if (!xdr_bytes(_sink, (char **) &val, (unsigned int *) &num, DODS_MAX_ARRAY)) { 00166 throw Error("Network I/O Error(2)."); 00167 } 00168 } 00169 00170 void XDRFileMarshaller::put_vector(char *val, int num, int width, Vector &vec) 00171 { 00172 if (!val) throw InternalErr(__FILE__, __LINE__, "Buffer pointer is not set."); 00173 00174 put_int(num); 00175 00176 BaseType *var = vec.var(); 00177 if (!xdr_array(_sink, (char **) &val, (unsigned int *) &num, DODS_MAX_ARRAY, width, 00178 XDRUtils::xdr_coder(var->type()))) { 00179 throw Error("Network I/O Error(2)."); 00180 } 00181 } 00182 00183 void XDRFileMarshaller::dump(ostream &strm) const 00184 { 00185 strm << DapIndent::LMarg << "XDRFileMarshaller::dump - (" << (void *) this << ")" << endl; 00186 } 00187 00188 } // namespace libdap 00189