libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
XDRFileMarshaller.cc
Go to the documentation of this file.
1// XDRFileMarshaller.cc
2
3// -*- mode: c++; c-basic-offset:4 -*-
4
5// This file is part of libdap, A C++ implementation of the OPeNDAP Data
6// Access Protocol.
7
8// Copyright (c) 2002,2003 OPeNDAP, Inc.
9// Author: Patrick West <pwest@ucar.edu>
10//
11// This library is free software; you can redistribute it and/or
12// modify it under the terms of the GNU Lesser General Public
13// License as published by the Free Software Foundation; either
14// version 2.1 of the License, or (at your option) any later version.
15//
16// This library is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19// Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public
22// License along with this library; if not, write to the Free Software
23// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24//
25// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26
27// (c) COPYRIGHT URI/MIT 1994-1999
28// Please read the full copyright statement in the file COPYRIGHT_URI.
29//
30// Authors:
31// pwest Patrick West <pwest@ucar.edu>
32
33#include "config.h"
34
35#include "XDRFileMarshaller.h"
36
37#include "Array.h"
38#include "Byte.h"
39#include "Float32.h"
40#include "Float64.h"
41#include "Grid.h"
42#include "Int16.h"
43#include "Int32.h"
44#include "Sequence.h"
45#include "Str.h"
46#include "Structure.h"
47#include "UInt16.h"
48#include "UInt32.h"
49#include "Url.h"
50
51#include "DapIndent.h"
52#include "InternalErr.h"
53#include "util.h"
54
55namespace libdap {
56
57XDRFileMarshaller::XDRFileMarshaller(FILE *out)
58 : _sink(0) //, d_out(out)
59{
60 _sink = new_xdrstdio(out, XDR_ENCODE);
61}
62
63XDRFileMarshaller::XDRFileMarshaller()
64 : Marshaller(), _sink(0) //, d_out(0)
65{
66 throw InternalErr(__FILE__, __LINE__, "Default constructor not implemented.");
67}
68
69XDRFileMarshaller::XDRFileMarshaller(const XDRFileMarshaller &m)
70 : Marshaller(m), _sink(0) //, d_out(0)
71{
72 throw InternalErr(__FILE__, __LINE__, "Copy constructor not implemented.");
73}
74
75XDRFileMarshaller &XDRFileMarshaller::operator=(const XDRFileMarshaller &) {
76 throw InternalErr(__FILE__, __LINE__, "Copy operator not implemented.");
77}
78
80
82 if (!xdr_char(_sink, (char *)&val))
83 throw Error("Network I/O Error. Could not send byte data.\nThis may be due to a bug in DODS, on the server or "
84 "a\nproblem with the network connection.");
85}
86
88 if (!XDR_INT16(_sink, &val))
89 throw Error("Network I/O Error. Could not send int 16 data.\nThis may be due to a bug in libdap, on the server "
90 "or a\nproblem with the network connection.");
91}
92
94 if (!XDR_INT32(_sink, &val))
95 throw Error("Network I/O Error. Could not read int 32 data.\nThis may be due to a bug in libdap, on the server "
96 "or a\nproblem with the network connection.");
97}
98
100 if (!xdr_float(_sink, &val))
101 throw Error("Network I/O Error. Could not send float 32 data.\nThis may be due to a bug in libdap, on the "
102 "server or a\nproblem with the network connection.");
103}
104
106 if (!xdr_double(_sink, &val))
107 throw Error("Network I/O Error. Could not send float 64 data.\nThis may be due to a bug in libdap, on the "
108 "server or a\nproblem with the network connection.");
109}
110
112 if (!XDR_UINT16(_sink, &val))
113 throw Error("Network I/O Error. Could not send uint 16 data.");
114}
115
117 if (!XDR_UINT32(_sink, &val))
118 throw Error("Network I/O Error. Could not send uint 32 data.");
119}
120
121void XDRFileMarshaller::put_str(const string &val) {
122 const char *out_tmp = val.c_str();
123
124 if (!xdr_string(_sink, (char **)&out_tmp, max_str_len))
125 throw Error("Network I/O Error. Could not send string data.");
126}
127
128void XDRFileMarshaller::put_url(const string &val) { put_str(val); }
129
130void XDRFileMarshaller::put_opaque(char *val, unsigned int len) {
131 if (!xdr_opaque(_sink, val, len))
132 throw Error("Network I/O Error. Could not send opaque data.");
133}
134
136 if (!xdr_int(_sink, &val))
137 throw Error("Network I/O Error(1).");
138}
139
140void XDRFileMarshaller::put_vector(char *val, int num, Vector &) {
141 if (!val)
142 throw InternalErr(__FILE__, __LINE__, "Buffer pointer is not set.");
143
144 put_int(num);
145
146 if (!xdr_bytes(_sink, (char **)&val, (unsigned int *)&num, DODS_MAX_ARRAY)) {
147 throw Error("Network I/O Error(2).");
148 }
149}
150
151void XDRFileMarshaller::put_vector(char *val, int num, int width, Vector &vec) {
152 if (!val)
153 throw InternalErr(__FILE__, __LINE__, "Buffer pointer is not set.");
154
155 put_int(num);
156
157 BaseType *var = vec.var();
158 if (!xdr_array(_sink, (char **)&val, (unsigned int *)&num, DODS_MAX_ARRAY, width,
159 XDRUtils::xdr_coder(var->type()))) {
160 throw Error("Network I/O Error(2).");
161 }
162}
163
164void XDRFileMarshaller::dump(ostream &strm) const {
165 strm << DapIndent::LMarg << "XDRFileMarshaller::dump - (" << (void *)this << ")" << endl;
166}
167
168} // namespace libdap
XDR * new_xdrstdio(FILE *stream, enum xdr_op xop)
Definition XDRUtils.cc:49
void delete_xdrstdio(XDR *xdr)
Definition XDRUtils.cc:66
The basic data type for the DODS DAP types.
Definition BaseType.h:118
virtual Type type() const
Returns the type of the class instance.
Definition BaseType.cc:329
static ostream & LMarg(ostream &strm)
Definition DapIndent.cc:61
A class for error processing.
Definition Error.h:92
A class for software fault reporting.
Definition InternalErr.h:61
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
Holds a one-dimensional collection of DAP2 data types.
Definition Vector.h:81
BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr) override
Definition Vector.cc:469
marshaller that knows how to marshall/serialize dap data objects to a file using XDR
virtual void put_float64(dods_float64 val)
virtual void put_int16(dods_int16 val)
virtual void put_opaque(char *val, unsigned int len)
virtual void put_int32(dods_int32 val)
virtual void put_str(const string &val)
virtual void put_url(const string &val)
virtual void put_uint32(dods_uint32 val)
virtual void put_vector(char *val, int num, Vector &vec)
virtual void put_uint16(dods_uint16 val)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void put_byte(dods_byte val)
virtual void put_int(int val)
virtual void put_float32(dods_float32 val)
static xdrproc_t xdr_coder(const Type &t)
Returns a function used to encode elements of an array.
Definition XDRUtils.cc:137
#define XDR_UINT16
Definition config.h:1128
#define XDR_INT16
Definition config.h:1122
#define XDR_INT32
Definition config.h:1125
#define XDR_UINT32
Definition config.h:1131
top level DAP object to house generic methods
Definition AISConnect.cc:30
const int DODS_MAX_ARRAY
Definition Array.h:60
uint32_t dods_uint32
const unsigned int max_str_len
Definition Str.h:53
uint16_t dods_uint16