libdap++  Updated for version 3.13.3
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 "Byte.h"
38 #include "Int16.h"
39 #include "UInt16.h"
40 #include "Int32.h"
41 #include "UInt32.h"
42 #include "Float32.h"
43 #include "Float64.h"
44 #include "Str.h"
45 #include "Url.h"
46 #include "Array.h"
47 #include "Structure.h"
48 #include "Sequence.h"
49 #include "Grid.h"
50 
51 #include "util.h"
52 #include "InternalErr.h"
53 
54 namespace libdap {
55 
56 XDRFileMarshaller::XDRFileMarshaller( FILE *out )
57  : _sink( 0 )
58 {
59  _sink = new_xdrstdio( out, XDR_ENCODE ) ;
60 }
61 
62 XDRFileMarshaller::XDRFileMarshaller()
63  : Marshaller(),
64  _sink( 0 )
65 {
66  throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ;
67 }
68 
69 XDRFileMarshaller::XDRFileMarshaller( const XDRFileMarshaller &m )
70  : Marshaller( m ),
71  _sink( 0 )
72 {
73  throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ;
74 }
75 
76 XDRFileMarshaller &
77 XDRFileMarshaller::operator=( const XDRFileMarshaller & )
78 {
79  throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ;
80 
81  return *this ;
82 }
83 
85 {
86  delete_xdrstdio( _sink ) ;
87 }
88 
89 void
91 {
92  if( !xdr_char( _sink, (char *)&val ) )
93  throw Error("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.");
94 }
95 
96 void
98 {
99  if( !XDR_INT16( _sink, &val ) )
100  throw Error("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.");
101 }
102 
103 void
105 {
106  if( !XDR_INT32( _sink, &val ) )
107  throw Error("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.");
108 }
109 
110 void
112 {
113  if( !xdr_float( _sink, &val ) )
114  throw Error("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.");
115 }
116 
117 void
119 {
120  if( !xdr_double( _sink, &val ) )
121  throw Error("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.");
122 }
123 
124 void
126 {
127  if( !XDR_UINT16( _sink, &val ) )
128  throw Error("Network I/O Error. Could not send uint 16 data. This may be due to a\nbug in libdap or a problem with the network connection.");
129 }
130 
131 void
133 {
134  if( !XDR_UINT32( _sink, &val ) )
135  throw Error("Network I/O Error. Could not send uint 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
136 }
137 
138 void
139 XDRFileMarshaller::put_str( const string &val )
140 {
141  const char *out_tmp = val.c_str() ;
142 
143  if( !xdr_string( _sink, (char **)&out_tmp, max_str_len) )
144  throw Error("Network I/O Error. Could not send string data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
145 }
146 
147 void
148 XDRFileMarshaller::put_url( const string &val )
149 {
150  put_str( val ) ;
151 }
152 
153 void
154 XDRFileMarshaller::put_opaque( char *val, unsigned int len )
155 {
156  if( !xdr_opaque( _sink, val, len ) )
157  throw Error("Network I/O Error. Could not send opaque data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
158 }
159 
160 void
162 {
163  if( !xdr_int( _sink, &val) )
164  throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
165 }
166 
167 void
168 XDRFileMarshaller::put_vector( char *val, int num, Vector & )
169 {
170  if (!val)
171  throw InternalErr(__FILE__, __LINE__,
172  "Buffer pointer is not set.");
173 
174  put_int( num ) ;
175 
176  if( !xdr_bytes( _sink, (char **)&val,
177  (unsigned int *) &num,
178  DODS_MAX_ARRAY) )
179  {
180  throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
181  }
182 }
183 
184 void
185 XDRFileMarshaller::put_vector( char *val, int num, int width, Vector &vec )
186 {
187  if (!val)
188  throw InternalErr(__FILE__, __LINE__,
189  "Buffer pointer is not set.");
190 
191  put_int( num ) ;
192 
193  BaseType *var = vec.var() ;
194  if( !xdr_array( _sink, (char **)&val,
195  (unsigned int *) & num,
196  DODS_MAX_ARRAY, width,
197  XDRUtils::xdr_coder( var->type() ) ) )
198  {
199  throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
200  }
201 }
202 
203 void
204 XDRFileMarshaller::dump(ostream &strm) const
205 {
206  strm << DapIndent::LMarg << "XDRFileMarshaller::dump - ("
207  << (void *)this << ")" << endl ;
208 }
209 
210 } // namespace libdap
211 
#define XDR_UINT32
Definition: config.h:968
uint8_t dods_byte
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:78
#define XDR_UINT16
Definition: config.h:965
virtual void put_opaque(char *val, unsigned int len)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void put_uint16(dods_uint16 val)
virtual void put_float32(dods_float32 val)
virtual void put_str(const string &val)
XDR * new_xdrstdio(FILE *stream, enum xdr_op xop)
Definition: XDRUtils.cc:50
virtual void put_vector(char *val, int num, Vector &vec)
Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:282
#define XDR_INT32
Definition: config.h:962
uint16_t dods_uint16
A class for software fault reporting.
Definition: InternalErr.h:64
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Definition: Vector.cc:380
virtual void put_int(int val)
virtual void put_uint32(dods_uint32 val)
double dods_float64
const unsigned int max_str_len
Definition: Str.h:54
uint32_t dods_uint32
void delete_xdrstdio(XDR *xdr)
Definition: XDRUtils.cc:71
#define XDR_INT16
Definition: config.h:959
static ostream & LMarg(ostream &strm)
Definition: DapIndent.cc:80
int16_t dods_int16
const int DODS_MAX_ARRAY
Definition: Array.h:58
The basic data type for the DODS DAP types.
Definition: BaseType.h:199
virtual void put_float64(dods_float64 val)
virtual void put_byte(dods_byte val)
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:53
virtual void put_int32(dods_int32 val)
virtual void put_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:145
A class for error processing.
Definition: Error.h:90
virtual void put_url(const string &val)
int32_t dods_int32