libdap++  Updated for version 3.12.0
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 "XDRFileUnMarshaller.h"
34 
35 #include "Byte.h"
36 #include "Int16.h"
37 #include "UInt16.h"
38 #include "Int32.h"
39 #include "UInt32.h"
40 #include "Float32.h"
41 #include "Float64.h"
42 #include "Str.h"
43 #include "Url.h"
44 #include "Array.h"
45 #include "Structure.h"
46 #include "Sequence.h"
47 #include "Grid.h"
48 #if 0
49 #include "Vector.h"
50 #endif
51 #include "util.h"
52 #include "InternalErr.h"
53 
54 namespace libdap {
55 
56 XDRFileUnMarshaller::XDRFileUnMarshaller( FILE *out )
57  : _source( 0 )
58 {
59  _source = new_xdrstdio( out, XDR_DECODE ) ;
60 }
61 
62 XDRFileUnMarshaller::XDRFileUnMarshaller()
63  : UnMarshaller(), _source( 0 )
64 {
65  throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ;
66 }
67 
68 XDRFileUnMarshaller::XDRFileUnMarshaller( const XDRFileUnMarshaller &um )
69  : UnMarshaller( um ), _source( 0 )
70 {
71  throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ;
72 }
73 
74 XDRFileUnMarshaller &
75 XDRFileUnMarshaller::operator=( const XDRFileUnMarshaller & )
76 {
77  throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ;
78 
79  return *this ;
80 }
81 
83 {
84  // Some static code analysis tools complain that delete_xdrstdio
85  // does not close the FILE* it holds, but that's not true with
86  // modern XDR libraries. Don't try to close that FILE*. jhrg 8/27/13
87 
88  delete_xdrstdio( _source ) ;
89 }
90 
91 void
93 {
94  if( !xdr_char( _source, (char *)&val ) )
95  throw Error("Network I/O Error. Could not read byte data. This may be due to a\nbug in DODS or a problem with the network connection.");
96 }
97 
98 void
100 {
101  if( !XDR_INT16( _source, &val ) )
102  throw Error("Network I/O Error. Could not read int 16 data. This may be due to a\nbug in libdap or a problem with the network connection.");
103 }
104 
105 void
107 {
108  if( !XDR_INT32( _source, &val ) )
109  throw Error("Network I/O Error. Could not read int 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
110 }
111 
112 void
114 {
115  if( !xdr_float( _source, &val ) )
116  throw Error("Network I/O Error. Could not read float 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
117 }
118 
119 void
121 {
122  if( !xdr_double( _source, &val ) )
123  throw Error("Network I/O Error. Could not read float 64 data. This may be due to a\nbug in libdap or a problem with the network connection.");
124 }
125 
126 void
128 {
129  if( !XDR_UINT16( _source, &val ) )
130  throw Error("Network I/O Error. Could not read uint 16 data. This may be due to a\nbug in libdap or a problem with the network connection.");
131 }
132 
133 void
135 {
136  if( !XDR_UINT32( _source, &val ) )
137  throw Error("Network I/O Error. Could not read uint 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
138 }
139 
140 void
142 {
143  char *in_tmp = NULL ;
144 
145  if( !xdr_string( _source, &in_tmp, max_str_len ) )
146  throw Error("Network I/O Error. Could not read string data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
147 
148  val = in_tmp ;
149 
150  free( in_tmp ) ;
151 }
152 
153 void
155 {
156  get_str( val ) ;
157 }
158 
159 void
160 XDRFileUnMarshaller::get_opaque( char *val, unsigned int len )
161 {
162  xdr_opaque( _source, val, len ) ;
163 }
164 
165 void
167 {
168  if( !xdr_int( _source, &val ) )
169  throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
170 }
171 
172 void
173 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, Vector & )
174 {
175  if( !xdr_bytes( _source, val, &num, DODS_MAX_ARRAY) )
176  throw Error("Network I/O error. Could not read packed array data.\nThis may be due to a bug in libdap or a problem with\nthe network connection.");
177 }
178 
179 void
180 XDRFileUnMarshaller::get_vector( char **val, unsigned int &num, int width, Vector &vec )
181 {
182  BaseType *var = vec.var() ;
183 
184  if( !xdr_array( _source, val, &num, DODS_MAX_ARRAY, width,
185  XDRUtils::xdr_coder( var->type() ) ) )
186  {
187  throw Error("Network I/O error. Could not read packed array data.\nThis may be due to a bug in libdap or a problem with\nthe network connection.");
188  }
189 }
190 
191 void
192 XDRFileUnMarshaller::dump(ostream &strm) const
193 {
194  strm << DapIndent::LMarg << "XDRFileUnMarshaller::dump - ("
195  << (void *)this << ")" << endl ;
196 }
197 
198 } // namespace libdap
199