libdap
Updated for version 3.17.0
|
00001 // D4StreamUnMarshaller.h 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) 2012 OPeNDAP, Inc. 00009 // Author: James Gallagher <jgallagher@opendap.org> 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 // 00025 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00026 00027 #ifndef I_D4StreamUnMarshaller_h 00028 #define I_D4StreamUnMarshaller_h 1 00029 00030 #include <iostream> 00031 00032 // See comment in D4StreamMarshaller 00033 #define USE_XDR_FOR_IEEE754_ENCODING 0 00034 00035 #if USE_XDR_FOR_IEEE754_ENCODING 00036 #ifdef WIN32 00037 #include <rpc.h> 00038 #include <winsock2.h> 00039 #include <xdr.h> 00040 #else 00041 #include <rpc/types.h> 00042 #include <netinet/in.h> 00043 #include <rpc/xdr.h> 00044 #endif 00045 #endif 00046 00047 #include <crc.h> 00048 00049 // #include "Type.h" 00050 #include "dods-datatypes.h" 00051 #include "UnMarshaller.h" 00052 #include "InternalErr.h" 00053 00054 #include "util.h" 00055 #include "debug.h" 00056 00057 using std::istream; 00058 00059 namespace libdap { 00060 00061 class Vector; 00062 00065 class D4StreamUnMarshaller: public UnMarshaller { 00066 public: 00067 const static unsigned int c_checksum_length = 4; 00068 00069 private: 00070 istream &d_in; 00071 bool d_twiddle_bytes; 00072 00073 #if USE_XDR_FOR_IEEE754_ENCODING 00074 // These are used for reals that need to be converted from IEEE 754 00075 XDR d_source; 00076 char d_buf[sizeof(dods_float64)]; 00077 #endif 00078 00079 D4StreamUnMarshaller(); 00080 D4StreamUnMarshaller(const D4StreamUnMarshaller &); 00081 D4StreamUnMarshaller & operator=(const D4StreamUnMarshaller &); 00082 #if USE_XDR_FOR_IEEE754_ENCODING 00083 void m_deserialize_reals(char *val, int64_t num, int width, Type type); 00084 #endif 00085 void m_twidle_vector_elements(char *vals, int64_t num, int width); 00086 00087 public: 00088 D4StreamUnMarshaller(istream &in, bool twiddle_bytes); 00089 D4StreamUnMarshaller(istream &in); 00090 virtual ~D4StreamUnMarshaller(); 00091 00092 void set_twiddle_bytes(bool twiddle) { d_twiddle_bytes = twiddle; } 00093 00104 bool is_source_big_endian() const { return (is_host_big_endian() && !d_twiddle_bytes) 00105 || (!is_host_big_endian() && d_twiddle_bytes); } 00106 00107 Crc32::checksum get_checksum(); 00108 string get_checksum_str(); 00109 int64_t get_count(); 00110 00111 virtual void get_byte(dods_byte &val); 00112 virtual void get_int8(dods_int8 &val); 00113 00114 virtual void get_int16(dods_int16 &val); 00115 virtual void get_int32(dods_int32 &val); 00116 00117 virtual void get_int64(dods_int64 &val); 00118 00119 virtual void get_float32(dods_float32 &val); 00120 virtual void get_float64(dods_float64 &val); 00121 00122 virtual void get_uint16(dods_uint16 &val); 00123 virtual void get_uint32(dods_uint32 &val); 00124 00125 virtual void get_uint64(dods_uint64 &val); 00126 00127 virtual void get_str(string &val); 00128 virtual void get_url(string &val); 00129 00130 virtual void get_opaque(char *, unsigned int) { 00131 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4, use get_opaque_dap4() instead."); 00132 } 00133 00134 virtual void get_opaque_dap4(char **val, int64_t &len); 00135 virtual void get_opaque_dap4( vector<uint8_t> &val ); 00136 00137 virtual void get_int(int &) { 00138 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4"); 00139 } 00140 00141 // Note that DAP4 assumes clients know the size of arrays when they 00142 // read the data; it's the 'varying' get methods that read & return the 00143 // number of elements. These methods are here to appease the UnMarshaller 00144 // 'interface' code 00145 virtual void get_vector(char **, unsigned int &, Vector &) { 00146 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4"); 00147 } 00148 00149 virtual void get_vector(char **, unsigned int &, int, Vector & ) { 00150 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4"); 00151 } 00152 00153 virtual void get_vector(char *val, int64_t num_bytes); 00154 virtual void get_vector(char *val, int64_t num_elem, int elem_size); 00155 virtual void get_vector_float32(char *val, int64_t num_elem); 00156 virtual void get_vector_float64(char *val, int64_t num_elem); 00157 00158 virtual void dump(ostream &strm) const; 00159 }; 00160 00161 } // namespace libdap 00162 00163 #endif // I_D4StreamUnMarshaller_h 00164