libdap++  Updated for version 3.8.2
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "XDRFileMarshaller.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 
49 #include "util.h"
50 #include "InternalErr.h"
51 
52 namespace libdap {
53 
54 XDRFileMarshaller::XDRFileMarshaller( FILE *out )
55  : _sink( 0 )
56 {
57  _sink = new_xdrstdio( out, XDR_ENCODE ) ;
58 }
59 
60 XDRFileMarshaller::XDRFileMarshaller()
61  : Marshaller(),
62  _sink( 0 )
63 {
64  throw InternalErr( __FILE__, __LINE__, "Default constructor not implemented." ) ;
65 }
66 
67 XDRFileMarshaller::XDRFileMarshaller( const XDRFileMarshaller &m )
68  : Marshaller( m ),
69  _sink( 0 )
70 {
71  throw InternalErr( __FILE__, __LINE__, "Copy constructor not implemented." ) ;
72 }
73 
75 XDRFileMarshaller::operator=( const XDRFileMarshaller & )
76 {
77  throw InternalErr( __FILE__, __LINE__, "Copy operator not implemented." ) ;
78 
79  return *this ;
80 }
81 
83 {
84  delete_xdrstdio( _sink ) ;
85 }
86 
87 void
89 {
90  if( !xdr_char( _sink, (char *)&val ) )
91  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.");
92 }
93 
94 void
96 {
97  if( !XDR_INT16( _sink, &val ) )
98  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.");
99 }
100 
101 void
103 {
104  if( !XDR_INT32( _sink, &val ) )
105  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.");
106 }
107 
108 void
110 {
111  if( !xdr_float( _sink, &val ) )
112  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.");
113 }
114 
115 void
117 {
118  if( !xdr_double( _sink, &val ) )
119  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.");
120 }
121 
122 void
124 {
125  if( !XDR_UINT16( _sink, &val ) )
126  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.");
127 }
128 
129 void
131 {
132  if( !XDR_UINT32( _sink, &val ) )
133  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.");
134 }
135 
136 void
137 XDRFileMarshaller::put_str( const string &val )
138 {
139  const char *out_tmp = val.c_str() ;
140 
141  if( !xdr_string( _sink, (char **)&out_tmp, max_str_len) )
142  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.");
143 }
144 
145 void
146 XDRFileMarshaller::put_url( const string &val )
147 {
148  put_str( val ) ;
149 }
150 
151 void
152 XDRFileMarshaller::put_opaque( char *val, unsigned int len )
153 {
154  if( !xdr_opaque( _sink, val, len ) )
155  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.");
156 }
157 
158 void
160 {
161  if( !xdr_int( _sink, &val) )
162  throw Error("Network I/O Error(1). This may be due to a bug in libdap or a\nproblem with the network connection.");
163 }
164 
165 void
166 XDRFileMarshaller::put_vector( char *val, int num, Vector & )
167 {
168  if (!val)
169  throw InternalErr(__FILE__, __LINE__,
170  "Buffer pointer is not set.");
171 
172  put_int( num ) ;
173 
174  if( !xdr_bytes( _sink, (char **)&val,
175  (unsigned int *) &num,
176  DODS_MAX_ARRAY) )
177  {
178  throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
179  }
180 }
181 
182 void
183 XDRFileMarshaller::put_vector( char *val, int num, int width, Vector &vec )
184 {
185  if (!val)
186  throw InternalErr(__FILE__, __LINE__,
187  "Buffer pointer is not set.");
188 
189  put_int( num ) ;
190 
191  BaseType *var = vec.var() ;
192  if( !xdr_array( _sink, (char **)&val,
193  (unsigned int *) & num,
194  DODS_MAX_ARRAY, width,
195  XDRUtils::xdr_coder( var->type() ) ) )
196  {
197  throw Error("Network I/O Error(2). This may be due to a bug in libdap or a\nproblem with the network connection.");
198  }
199 }
200 
201 void
202 XDRFileMarshaller::dump(ostream &strm) const
203 {
204  strm << DapIndent::LMarg << "XDRFileMarshaller::dump - ("
205  << (void *)this << ")" << endl ;
206 }
207 
208 } // namespace libdap
209 
#define XDR_UINT32
Definition: config.h:395
uint8_t dods_byte
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:78
#define XDR_UINT16
Definition: config.h:392
virtual void put_opaque(char *val, unsigned int len)
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:48
virtual void put_vector(char *val, int num, Vector &vec)
#define XDR_INT32
Definition: config.h:389
uint16_t dods_uint16
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
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:383
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:56
Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:238
uint32_t dods_uint32
void delete_xdrstdio(XDR *xdr)
Definition: XDRUtils.cc:69
marshaller that knows how to marshall/serialize dap data objects to a file using XDR ...
#define XDR_INT16
Definition: config.h:386
static ostream & LMarg(ostream &strm)
Definition: DapIndent.cc:78
int16_t dods_int16
const int DODS_MAX_ARRAY
Definition: Array.h:56
The basic data type for the DODS DAP types.
Definition: BaseType.h:190
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:143
A class for error processing.
Definition: Error.h:90
virtual void put_url(const string &val)
int32_t dods_int32