Blame XDRFileMarshaller.cc

Packit a4aae4
// XDRFileMarshaller.cc
Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: Patrick West <pwest@ucar.edu>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 1994-1999
Packit a4aae4
// Please read the full copyright statement in the file COPYRIGHT_URI.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
//      pwest       Patrick West <pwest@ucar.edu>
Packit a4aae4
Packit a4aae4
#include "config.h"
Packit a4aae4
Packit a4aae4
#include "XDRFileMarshaller.h"
Packit a4aae4
Packit a4aae4
#include "Byte.h"
Packit a4aae4
#include "Int16.h"
Packit a4aae4
#include "UInt16.h"
Packit a4aae4
#include "Int32.h"
Packit a4aae4
#include "UInt32.h"
Packit a4aae4
#include "Float32.h"
Packit a4aae4
#include "Float64.h"
Packit a4aae4
#include "Str.h"
Packit a4aae4
#include "Url.h"
Packit a4aae4
#include "Array.h"
Packit a4aae4
#include "Structure.h"
Packit a4aae4
#include "Sequence.h"
Packit a4aae4
#include "Grid.h"
Packit a4aae4
Packit a4aae4
#include "util.h"
Packit a4aae4
#include "InternalErr.h"
Packit a4aae4
Packit a4aae4
namespace libdap {
Packit a4aae4
Packit a4aae4
XDRFileMarshaller::XDRFileMarshaller(FILE *out) :
Packit a4aae4
    _sink(0)//, d_out(out)
Packit a4aae4
{
Packit a4aae4
    _sink = new_xdrstdio(out, XDR_ENCODE);
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
XDRFileMarshaller::XDRFileMarshaller() :
Packit a4aae4
    Marshaller(), _sink(0)//, d_out(0)
Packit a4aae4
{
Packit a4aae4
    throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
XDRFileMarshaller::XDRFileMarshaller(const XDRFileMarshaller &m) :
Packit a4aae4
    Marshaller(m), _sink(0)//, d_out(0)
Packit a4aae4
{
Packit a4aae4
    throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
XDRFileMarshaller &
Packit a4aae4
XDRFileMarshaller::operator=(const XDRFileMarshaller &)
Packit a4aae4
{
Packit a4aae4
    throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented.");
Packit a4aae4
Packit a4aae4
    return *this;
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
XDRFileMarshaller::~XDRFileMarshaller()
Packit a4aae4
{
Packit a4aae4
    delete_xdrstdio(_sink);
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_byte(dods_byte val)
Packit a4aae4
{
Packit a4aae4
    if (!xdr_char(_sink, (char *) &val))
Packit a4aae4
        throw Error(
Packit a4aae4
            "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.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_int16(dods_int16 val)
Packit a4aae4
{
Packit a4aae4
    if (!XDR_INT16(_sink, &val))
Packit a4aae4
        throw Error(
Packit a4aae4
            "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.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_int32(dods_int32 val)
Packit a4aae4
{
Packit a4aae4
    if (!XDR_INT32(_sink, &val))
Packit a4aae4
        throw Error(
Packit a4aae4
            "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.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_float32(dods_float32 val)
Packit a4aae4
{
Packit a4aae4
    if (!xdr_float(_sink, &val))
Packit a4aae4
        throw Error(
Packit a4aae4
            "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.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_float64(dods_float64 val)
Packit a4aae4
{
Packit a4aae4
    if (!xdr_double(_sink, &val))
Packit a4aae4
        throw Error(
Packit a4aae4
            "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.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_uint16(dods_uint16 val)
Packit a4aae4
{
Packit a4aae4
    if (!XDR_UINT16(_sink, &val))
Packit a4aae4
        throw Error("Network I/O Error. Could not send uint 16 data.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_uint32(dods_uint32 val)
Packit a4aae4
{
Packit a4aae4
    if (!XDR_UINT32(_sink, &val))
Packit a4aae4
        throw Error("Network I/O Error. Could not send uint 32 data.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_str(const string &val)
Packit a4aae4
{
Packit a4aae4
    const char *out_tmp = val.c_str();
Packit a4aae4
Packit a4aae4
    if (!xdr_string(_sink, (char **) &out_tmp, max_str_len))
Packit a4aae4
        throw Error("Network I/O Error. Could not send string data.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_url(const string &val)
Packit a4aae4
{
Packit a4aae4
    put_str(val);
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_opaque(char *val, unsigned int len)
Packit a4aae4
{
Packit a4aae4
    if (!xdr_opaque(_sink, val, len))
Packit a4aae4
        throw Error("Network I/O Error. Could not send opaque data.");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_int(int val)
Packit a4aae4
{
Packit a4aae4
    if (!xdr_int(_sink, &val))
Packit a4aae4
        throw Error("Network I/O Error(1).");
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_vector(char *val, int num, Vector &)
Packit a4aae4
{
Packit a4aae4
    if (!val) throw InternalErr(__FILE__, __LINE__, "Buffer pointer is not set.");
Packit a4aae4
Packit a4aae4
    put_int(num);
Packit a4aae4
Packit a4aae4
    if (!xdr_bytes(_sink, (char **) &val, (unsigned int *) &num, DODS_MAX_ARRAY)) {
Packit a4aae4
        throw Error("Network I/O Error(2).");
Packit a4aae4
    }
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::put_vector(char *val, int num, int width, Vector &vec)
Packit a4aae4
{
Packit a4aae4
    if (!val) throw InternalErr(__FILE__, __LINE__, "Buffer pointer is not set.");
Packit a4aae4
Packit a4aae4
    put_int(num);
Packit a4aae4
Packit a4aae4
    BaseType *var = vec.var();
Packit a4aae4
    if (!xdr_array(_sink, (char **) &val, (unsigned int *) &num, DODS_MAX_ARRAY, width,
Packit a4aae4
        XDRUtils::xdr_coder(var->type()))) {
Packit a4aae4
        throw Error("Network I/O Error(2).");
Packit a4aae4
    }
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
void XDRFileMarshaller::dump(ostream &strm) const
Packit a4aae4
{
Packit a4aae4
    strm << DapIndent::LMarg << "XDRFileMarshaller::dump - (" << (void *) this << ")" << endl;
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4