43 char *XDRStreamMarshaller::_buf = 0 ;
45 #define XDR_DAP_BUFF_SIZE 256 47 XDRStreamMarshaller::XDRStreamMarshaller( ostream &out )
54 throw Error(
"Failed to allocate memory for data serialization.");
60 XDRStreamMarshaller::XDRStreamMarshaller()
65 throw InternalErr( __FILE__, __LINE__,
"Default constructor not implemented." ) ;
73 throw InternalErr( __FILE__, __LINE__,
"Copy constructor not implemented." ) ;
79 throw InternalErr( __FILE__, __LINE__,
"Copy operator not implemented." ) ;
94 DBG( std::cerr <<
"put_byte: " << val << std::endl );
95 if( !xdr_setpos( _sink, 0 ) )
96 throw Error(
"Network I/O Error. Could not send byte data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
98 if( !xdr_char( _sink, (
char *)&val ) )
99 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.");
101 unsigned int bytes_written = xdr_getpos( _sink ) ;
103 throw Error(
"Network I/O Error. Could not send byte data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
105 _out.write( _buf, bytes_written ) ;
111 if( !xdr_setpos( _sink, 0 ) )
112 throw Error(
"Network I/O Error. Could not send int 16 data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
115 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.");
117 unsigned int bytes_written = xdr_getpos( _sink ) ;
119 throw Error(
"Network I/O Error. Could not send int 16 data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
121 _out.write( _buf, bytes_written ) ;
127 if( !xdr_setpos( _sink, 0 ) )
128 throw Error(
"Network I/O Error. Could not send int 32 data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
131 throw Error(
"Network I/O Error. Culd not read int 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
133 unsigned int bytes_written = xdr_getpos( _sink ) ;
135 throw Error(
"Network I/O Error. Could not send int 32 data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
137 _out.write( _buf, bytes_written ) ;
143 if( !xdr_setpos( _sink, 0 ) )
144 throw Error(
"Network I/O Error. Could not send float 32 data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
146 if( !xdr_float( _sink, &val ) )
147 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.");
149 unsigned int bytes_written = xdr_getpos( _sink ) ;
151 throw Error(
"Network I/O Error. Could not send float 32 data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
153 _out.write( _buf, bytes_written ) ;
159 if( !xdr_setpos( _sink, 0 ) )
160 throw Error(
"Network I/O Error. Could not send float 64 data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
162 if( !xdr_double( _sink, &val ) )
163 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.");
165 unsigned int bytes_written = xdr_getpos( _sink ) ;
167 throw Error(
"Network I/O Error. Could not send float 64 data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
169 _out.write( _buf, bytes_written ) ;
175 if( !xdr_setpos( _sink, 0 ) )
176 throw Error(
"Network I/O Error. Could not send uint 16 data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
179 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.");
181 unsigned int bytes_written = xdr_getpos( _sink ) ;
183 throw Error(
"Network I/O Error. Could not send uint 16 data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
185 _out.write( _buf, bytes_written ) ;
191 if( !xdr_setpos( _sink, 0 ) )
192 throw Error(
"Network I/O Error. Could not send uint 32 data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
195 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.");
197 unsigned int bytes_written = xdr_getpos( _sink ) ;
199 throw Error(
"Network I/O Error. Could not send uint 32 data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
201 _out.write( _buf, bytes_written ) ;
207 int size = val.length() + 8 ;
208 char *str_buf = (
char *)malloc( size ) ;
211 throw Error(
"Failed to allocate memory for string data serialization.");
214 XDR *str_sink =
new XDR ;
215 xdrmem_create( str_sink, str_buf, size, XDR_ENCODE ) ;
217 if( !xdr_setpos( str_sink, 0 ) ) {
220 throw Error(
"Network I/O Error. Could not send string data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
223 const char *out_tmp = val.c_str() ;
224 if( !xdr_string( str_sink, (
char **)&out_tmp, size ) ) {
227 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.");
230 unsigned int bytes_written = xdr_getpos( str_sink ) ;
231 if( !bytes_written ) {
234 throw Error(
"Network I/O Error. Could not send string data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
237 _out.write( str_buf, bytes_written ) ;
253 throw Error(
"Network I/O Error. Could not send opaque data - length of opaque data larger than allowed");
255 if( !xdr_setpos( _sink, 0 ) )
256 throw Error(
"Network I/O Error. Could not send opaque data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
258 if( !xdr_opaque( _sink, val, len ) )
259 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.");
261 unsigned int bytes_written = xdr_getpos( _sink ) ;
263 throw Error(
"Network I/O Error. Could not send opaque data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
265 _out.write( _buf, bytes_written ) ;
271 if( !xdr_setpos( _sink, 0 ) )
272 throw Error(
"Network I/O Error. Could not send int data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
274 if( !xdr_int( _sink, &val) )
275 throw Error(
"Network I/O Error(1). Could not send int data.\nThis may be due to a bug in libdap or a\nproblem with the network connection.");
277 unsigned int bytes_written = xdr_getpos( _sink ) ;
279 throw Error(
"Network I/O Error. Could not send int data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
281 _out.write( _buf, bytes_written ) ;
288 throw InternalErr(__FILE__, __LINE__,
"Could not send byte vector data. Buffer pointer is not set.");
294 unsigned int add_to = 8 ;
296 char *byte_buf = (
char *)malloc( num + add_to ) ;
298 throw Error(
"Failed to allocate memory for byte vector data serialization.");
301 XDR *byte_sink =
new XDR ;
302 xdrmem_create( byte_sink, byte_buf, num + add_to, XDR_ENCODE ) ;
304 if( !xdr_setpos( byte_sink, 0 ) ) {
307 throw Error(
"Network I/O Error. Could not send byte vector data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
310 if( !xdr_bytes( byte_sink, (
char **)&val, (
unsigned int *) &num,
315 throw Error(
"Network I/O Error(2). Could not send byte vector data.\nThis may be due to a bug in libdap or a\nproblem with the network connection.");
318 unsigned int bytes_written = xdr_getpos( byte_sink ) ;
319 if( !bytes_written ) {
322 throw Error(
"Network I/O Error. Could not send byte vector data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
325 _out.write( byte_buf, bytes_written ) ;
336 "Buffer pointer is not set.");
340 int use_width = width ;
346 int size = ( num * use_width ) + 4 ;
349 char *vec_buf = (
char *)malloc( size ) ;
352 throw Error(
"Failed to allocate memory for vector data serialization.");
355 XDR *vec_sink =
new XDR ;
356 xdrmem_create( vec_sink, vec_buf, size, XDR_ENCODE ) ;
359 if( !xdr_setpos( vec_sink, 0 ) ) {
362 throw Error(
"Network I/O Error. Could not send vector data - unable to set stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
368 if( !xdr_array( vec_sink, (
char **)&val,
369 (
unsigned int *) & num,
375 throw Error(
"Network I/O Error(2). Could not send vector data.\nThis may be due to a bug in libdap or a\nproblem with the network connection.");
379 unsigned int bytes_written = xdr_getpos( vec_sink ) ;
380 if( !bytes_written ) {
383 throw Error(
"Network I/O Error. Could not send vector data - unable to get stream position.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
387 _out.write( vec_buf, bytes_written ) ;
397 << (
void *)
this <<
")" << endl ;
virtual ~XDRStreamMarshaller()
Holds a one-dimensional collection of DAP2 data types.
virtual void put_int16(dods_int16 val)
virtual void put_uint16(dods_uint16 val)
virtual void put_float64(dods_float64 val)
const int XDR_DAP_BUFF_SIZE
A class for software fault reporting.
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void put_byte(dods_byte val)
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
virtual void put_int(int val)
virtual void put_float32(dods_float32 val)
Type type() const
Returns the type of the class instance.
virtual void put_opaque(char *val, unsigned int len)
virtual void put_str(const string &val)
void delete_xdrstdio(XDR *xdr)
static ostream & LMarg(ostream &strm)
The basic data type for the DODS DAP types.
abstract base class used to marshal/serialize dap data objects
virtual void put_vector(char *val, int num, Vector &vec)
static xdrproc_t xdr_coder(const Type &t)
Returns a function used to encode elements of an array.
A class for error processing.
virtual void put_int32(dods_int32 val)
marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using XDR ...
virtual void put_uint32(dods_uint32 val)
virtual void put_url(const string &val)