D4StreamMarshaller.h
// D4StreamMarshaller.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003,2012 OPeNDAP, Inc.
// Author: Patrick West <pwest@ucar.edu>,
// James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#ifndef I_D4StreamMarshaller_h
#define I_D4StreamMarshaller_h 1
#include <iostream>
// By default, only support platforms that use IEEE754 for floating point values.
// Hacked up code leftover from an older version of the class; largely untested.
// jhrg 10/3/13
#define USE_XDR_FOR_IEEE754_ENCODING 0
#if USE_XDR_FOR_IEEE754_ENCODING
#ifdef WIN32
#include <rpc.h>
#include <winsock2.h>
#include <xdr.h>
#else
#include <rpc/types.h>
#include <netinet/in.h>
#include <rpc/xdr.h>
#endif
#endif
#include <stdint.h>
#include "crc.h"
#include "Marshaller.h"
#include "InternalErr.h"
namespace libdap {
class Vector;
class MarshallerThread;
class D4StreamMarshaller: public Marshaller {
private:
#if USE_XDR_FOR_IEEE754_ENCODING
XDR d_scalar_sink;
char d_ieee754_buf[sizeof(dods_float64)]; // used to serialize a float or double
#endif
ostream &d_out;
bool d_write_data; // jhrg 1/27/12
Crc32 d_checksum;
MarshallerThread *tm;
// These are private so they won't ever get used.
D4StreamMarshaller();
D4StreamMarshaller(const D4StreamMarshaller &);
D4StreamMarshaller & operator=(const D4StreamMarshaller &);
#if USE_XDR_FOR_IEEE754_ENCODING
void m_serialize_reals(char *val, int64_t num, int width, Type type);
#endif
public:
D4StreamMarshaller(std::ostream &out, bool write_data = true);
virtual ~D4StreamMarshaller();
virtual void reset_checksum();
virtual string get_checksum();
virtual void checksum_update(const void *data, unsigned long len);
virtual void put_checksum();
virtual void put_count(int64_t count);
virtual void put_byte(dods_byte val);
virtual void put_int8(dods_int8 val);
virtual void put_int16(dods_int16 val);
virtual void put_int32(dods_int32 val);
// Added
virtual void put_int64(dods_int64 val);
virtual void put_float32(dods_float32 val);
virtual void put_float64(dods_float64 val);
virtual void put_uint16(dods_uint16 val);
virtual void put_uint32(dods_uint32 val);
// Added
virtual void put_uint64(dods_uint64 val);
virtual void put_str(const string &val);
virtual void put_url(const string &val);
virtual void put_opaque(char *, unsigned int) {
throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4; use put_opaque_dap4() instead.");
}
virtual void put_opaque_dap4(const char *val, int64_t len);
// Never use put_int() to send length information in DAP4.
virtual void put_int(int) {
throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix.");
}
virtual void put_vector(char *val, int64_t num_bytes);
virtual void put_vector(char *val, int64_t num_elem, int elem_size);
virtual void put_vector_float32(char *val, int64_t num_elem);
virtual void put_vector_float64(char *val, int64_t num_elem);
virtual void put_vector(char *, int , Vector &) {
throw InternalErr(__FILE__, __LINE__, "Not Implemented; use other put_vector() versions.");
}
virtual void put_vector(char *, int , int , Vector &) {
throw InternalErr(__FILE__, __LINE__, "Not Implemented; use other put_vector() versions.");
}
virtual void put_vector_start(int /*num*/) {
}
virtual void put_vector_part(char */*val*/, unsigned int /*num*/, int /*width*/, Type /*type*/);
virtual void put_vector_end() {
}
virtual void dump(std::ostream &strm) const;
};
} // namespace libdap
#endif // I_D4StreamMarshaller_h
Crc32
Definition: crc.h:77
libdap::D4StreamMarshaller
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiv...
Definition: D4StreamMarshaller.h:71
libdap::D4StreamMarshaller::put_checksum
virtual void put_checksum()
Write the checksum Write the checksum for the data sent since the last call to reset_checksum() to th...
Definition: D4StreamMarshaller.cc:263
libdap::D4StreamMarshaller::put_vector_start
virtual void put_vector_start(int)
Definition: D4StreamMarshaller.h:157
libdap::D4StreamMarshaller::reset_checksum
virtual void reset_checksum()
Definition: D4StreamMarshaller.cc:233
libdap::D4StreamMarshaller::put_vector_float32
virtual void put_vector_float32(char *val, int64_t num_elem)
Write a fixed size vector.
Definition: D4StreamMarshaller.cc:625
libdap::D4StreamMarshaller::put_vector_part
virtual void put_vector_part(char *, unsigned int, int, Type)
Definition: D4StreamMarshaller.cc:762
libdap::D4StreamMarshaller::put_vector
virtual void put_vector(char *val, int64_t num_bytes)
Write a fixed size vector.
Definition: D4StreamMarshaller.cc:546
libdap::D4StreamMarshaller::dump
virtual void dump(std::ostream &strm) const
dump the contents of this object to the specified ostream
Definition: D4StreamMarshaller.cc:820
libdap::D4StreamMarshaller::put_count
virtual void put_count(int64_t count)
Definition: D4StreamMarshaller.cc:489
libdap::D4StreamMarshaller::checksum_update
virtual void checksum_update(const void *data, unsigned long len)
Definition: D4StreamMarshaller.cc:276
libdap::D4StreamMarshaller::put_vector_float64
virtual void put_vector_float64(char *val, int64_t num_elem)
Write a fixed size vector of float64s.
Definition: D4StreamMarshaller.cc:699
libdap::D4StreamMarshaller::get_checksum
virtual string get_checksum()
Definition: D4StreamMarshaller.cc:248
libdap::D4StreamMarshaller::put_vector_end
virtual void put_vector_end()
Definition: D4StreamMarshaller.h:170
libdap::InternalErr
A class for software fault reporting.
Definition: InternalErr.h:65
libdap::MarshallerThread
Definition: MarshallerThread.h:96
libdap::Marshaller
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:50
libdap::Vector
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:81
libdap
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
libdap::Type
Type
Identifies the data type.
Definition: Type.h:94