libdap
Updated for version 3.17.0
|
00001 // D4StreamMarshaller.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) 2002,2003,2012 OPeNDAP, Inc. 00009 // Author: Patrick West <pwest@ucar.edu>, 00010 // James Gallagher <jgallagher@opendap.org> 00011 // 00012 // This library is free software; you can redistribute it and/or 00013 // modify it under the terms of the GNU Lesser General Public 00014 // License as published by the Free Software Foundation; either 00015 // version 2.1 of the License, or (at your option) any later version. 00016 // 00017 // This library is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 // Lesser General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Lesser General Public 00023 // License along with this library; if not, write to the Free Software 00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 // 00026 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00027 00028 #ifndef I_D4StreamMarshaller_h 00029 #define I_D4StreamMarshaller_h 1 00030 00031 #include <iostream> 00032 00033 // By default, only support platforms that use IEEE754 for floating point values. 00034 // Hacked up code leftover from an older version of the class; largely untested. 00035 // jhrg 10/3/13 00036 #define USE_XDR_FOR_IEEE754_ENCODING 0 00037 00038 #if USE_XDR_FOR_IEEE754_ENCODING 00039 #ifdef WIN32 00040 #include <rpc.h> 00041 #include <winsock2.h> 00042 #include <xdr.h> 00043 #else 00044 #include <rpc/types.h> 00045 #include <netinet/in.h> 00046 #include <rpc/xdr.h> 00047 #endif 00048 #endif 00049 00050 #include <stdint.h> 00051 #include "crc.h" 00052 00053 #include "Marshaller.h" 00054 #include "InternalErr.h" 00055 00056 namespace libdap { 00057 00058 class Vector; 00059 00070 class D4StreamMarshaller: public Marshaller { 00071 00072 private: 00073 #if USE_XDR_FOR_IEEE754_ENCODING 00074 XDR d_scalar_sink; 00075 char d_ieee754_buf[sizeof(dods_float64)]; // used to serialize a float or double 00076 #endif 00077 00078 ostream &d_out; 00079 bool d_write_data; // jhrg 1/27/12 00080 00081 Crc32 d_checksum; 00082 00083 00084 // These are private so they won't ever get used. 00085 D4StreamMarshaller(); 00086 D4StreamMarshaller(const D4StreamMarshaller &); 00087 D4StreamMarshaller & operator=(const D4StreamMarshaller &); 00088 00089 #if USE_XDR_FOR_IEEE754_ENCODING 00090 void m_serialize_reals(char *val, int64_t num, int width, Type type); 00091 #endif 00092 00093 public: 00094 D4StreamMarshaller(std::ostream &out, bool write_data = true); 00095 virtual ~D4StreamMarshaller(); 00096 00097 virtual void reset_checksum(); 00098 virtual string get_checksum(); 00099 virtual void checksum_update(const void *data, unsigned long len); 00100 00101 virtual void put_checksum(); 00102 virtual void put_count(int64_t count); 00103 00104 virtual void put_byte(dods_byte val); 00105 virtual void put_int8(dods_int8 val); 00106 00107 virtual void put_int16(dods_int16 val); 00108 virtual void put_int32(dods_int32 val); 00109 // Added 00110 virtual void put_int64(dods_int64 val); 00111 00112 virtual void put_float32(dods_float32 val); 00113 virtual void put_float64(dods_float64 val); 00114 00115 virtual void put_uint16(dods_uint16 val); 00116 virtual void put_uint32(dods_uint32 val); 00117 // Added 00118 virtual void put_uint64(dods_uint64 val); 00119 00120 virtual void put_str(const string &val); 00121 virtual void put_url(const string &val); 00122 00123 virtual void put_opaque(char *, unsigned int) { 00124 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4; use put_opaque_dap4() instead."); 00125 } 00126 00127 virtual void put_opaque_dap4(const char *val, int64_t len); 00128 00129 // Never use put_int() to send length information in DAP4. 00130 virtual void put_int(int) { 00131 throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix."); 00132 } 00133 00134 virtual void put_vector(char *val, int64_t num_bytes); 00135 virtual void put_vector(char *val, int64_t num_elem, int elem_size); 00136 virtual void put_vector_float32(char *val, int64_t num_elem); 00137 virtual void put_vector_float64(char *val, int64_t num_elem); 00138 00139 virtual void put_vector(char *, int , Vector &) { 00140 throw InternalErr(__FILE__, __LINE__, "Not Implemented; use other put_vector() versions."); 00141 } 00142 virtual void put_vector(char *, int , int , Vector &) { 00143 throw InternalErr(__FILE__, __LINE__, "Not Implemented; use other put_vector() versions."); 00144 } 00145 00155 virtual void put_vector_start(int /*num*/) { 00156 } 00157 00158 virtual void put_vector_part(char */*val*/, unsigned int /*num*/, int /*width*/, Type /*type*/); 00159 00168 virtual void put_vector_end() { 00169 } 00170 00171 virtual void dump(std::ostream &strm) const; 00172 }; 00173 00174 } // namespace libdap 00175 00176 #endif // I_D4StreamMarshaller_h