libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
XDRFileUnMarshaller.cc
Go to the documentation of this file.
1// XDRFileUnMarshaller.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 "XDRFileUnMarshaller.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
57XDRFileUnMarshaller::XDRFileUnMarshaller(FILE *out) : _source(0) { _source = new_xdrstdio(out, XDR_DECODE); }
58
59XDRFileUnMarshaller::XDRFileUnMarshaller() : UnMarshaller(), _source(0) {
60 throw InternalErr(__FILE__, __LINE__, "Default constructor not implemented.");
61}
62
63XDRFileUnMarshaller::XDRFileUnMarshaller(const XDRFileUnMarshaller &um) : UnMarshaller(um), _source(0) {
64 throw InternalErr(__FILE__, __LINE__, "Copy constructor not implemented.");
65}
66
67XDRFileUnMarshaller &XDRFileUnMarshaller::operator=(const XDRFileUnMarshaller &) {
68 throw InternalErr(__FILE__, __LINE__, "Copy operator not implemented.");
69}
70
72 // Some static code analysis tools complain that delete_xdrstdio
73 // does not close the FILE* it holds, but that's not true with
74 // modern XDR libraries. Don't try to close that FILE*. jhrg 8/27/13
75
76 delete_xdrstdio(_source);
77}
78
80 if (!xdr_char(_source, (char *)&val))
81 throw Error("Network I/O Error. Could not read byte data.");
82}
83
85 if (!XDR_INT16(_source, &val))
86 throw Error("Network I/O Error. Could not read int 16 data.");
87}
88
90 if (!XDR_INT32(_source, &val))
91 throw Error("Network I/O Error. Could not read int 32 data.");
92}
93
95 if (!xdr_float(_source, &val))
96 throw Error("Network I/O Error. Could not read float 32 data.");
97}
98
100 if (!xdr_double(_source, &val))
101 throw Error("Network I/O Error.Could not read float 64 data.");
102}
103
105 if (!XDR_UINT16(_source, &val))
106 throw Error("Network I/O Error. Could not read uint 16 data.");
107}
108
110 if (!XDR_UINT32(_source, &val))
111 throw Error("Network I/O Error. Could not read uint 32 data.");
112}
113
115 char *in_tmp = NULL;
116
117 if (!xdr_string(_source, &in_tmp, max_str_len))
118 throw Error("Network I/O Error. Could not read string data.");
119
120 val = in_tmp;
121
122 free(in_tmp);
123}
124
125void XDRFileUnMarshaller::get_url(string &val) { get_str(val); }
126
127void XDRFileUnMarshaller::get_opaque(char *val, unsigned int len) { xdr_opaque(_source, val, len); }
128
130 if (!xdr_int(_source, &val))
131 throw Error(
132 "Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
133}
134
135void XDRFileUnMarshaller::get_vector(char **val, unsigned int &num, Vector &) {
136 if (!xdr_bytes(_source, val, &num, DODS_MAX_ARRAY))
137 throw Error("Network I/O error (1).");
138}
139
140void XDRFileUnMarshaller::get_vector(char **val, unsigned int &num, int width, Vector &vec) {
141 BaseType *var = vec.var();
142
143 if (!xdr_array(_source, val, &num, DODS_MAX_ARRAY, width, XDRUtils::xdr_coder(var->type()))) {
144 throw Error("Network I/O error (2).");
145 }
146}
147
148void XDRFileUnMarshaller::dump(ostream &strm) const {
149 strm << DapIndent::LMarg << "XDRFileUnMarshaller::dump - (" << (void *)this << ")" << endl;
150}
151
152} // 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 unmarshall/deserialize dap data objects
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
unmarshaller that knows how to unmarshall/deserialize dap objects using XDR from a file
virtual void get_uint16(dods_uint16 &val)
virtual void get_int32(dods_int32 &val)
virtual void get_opaque(char *val, unsigned int len)
virtual void get_float32(dods_float32 &val)
virtual void get_uint32(dods_uint32 &val)
virtual void get_str(string &val)
virtual void get_vector(char **val, unsigned int &num, Vector &vec)
virtual void get_byte(dods_byte &val)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void get_float64(dods_float64 &val)
virtual void get_url(string &val)
virtual void get_int16(dods_int16 &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