51 char *XDRStreamUnMarshaller::_buf = 0 ;
53 XDRStreamUnMarshaller::XDRStreamUnMarshaller( istream &in )
54 : _source( 0 ), _in( in )
59 throw Error(
"Failed to allocate memory for data serialization.");
65 XDRStreamUnMarshaller::XDRStreamUnMarshaller()
68 throw InternalErr( __FILE__, __LINE__,
"Default constructor not implemented." ) ;
74 throw InternalErr( __FILE__, __LINE__,
"Copy constructor not implemented." ) ;
80 throw InternalErr( __FILE__, __LINE__,
"Copy operator not implemented." ) ;
95 if (xdr_setpos( _source, 0 ) < 0)
96 throw Error(
"Failed to reposition input stream");
97 if (!(_in.read( _buf, 4 ))) {
99 throw Error(
"Premature EOF in input stream");
101 ostringstream ss(
"Error reading from input stream: ");
103 throw Error(ss.str());
107 DBG2( std::cerr <<
"_in.gcount(): " << _in.gcount() << std::endl );
108 DBG2( std::cerr <<
"_in.tellg(): " << _in.tellg() << std::endl );
109 DBG2( std::cerr <<
"_buf[0]: " << hex << _buf[0] <<
"; _buf[1]: " << _buf[1]
110 <<
"; _buf[2]: " << _buf[2] <<
"; _buf[3]: " << _buf[3]
111 << dec << std::endl );
113 if( !xdr_char( _source, (
char *)&val ) )
114 throw Error(
"Network I/O Error. Could not read byte data.");
116 DBG2(std::cerr <<
"get_byte: " << val << std::endl );
122 xdr_setpos( _source, 0 );
126 throw Error(
"Network I/O Error. Could not read int 16 data.");
132 xdr_setpos( _source, 0 );
136 throw Error(
"Network I/O Error. Could not read int 32 data.");
142 xdr_setpos( _source, 0 );
145 if( !xdr_float( _source, &val ) )
146 throw Error(
"Network I/O Error. Could not read float 32 data.");
152 xdr_setpos( _source, 0 );
155 if( !xdr_double( _source, &val ) )
156 throw Error(
"Network I/O Error. Could not read float 64 data.");
162 xdr_setpos( _source, 0 );
166 throw Error(
"Network I/O Error. Could not read uint 16 data.");
172 xdr_setpos( _source, 0 );
176 throw Error(
"Network I/O Error. Could not read uint 32 data.");
184 DBG(std::cerr <<
"i: " << i << std::endl);
187 i = ( ( i + 3 ) / 4 ) * 4;
188 DBG(std::cerr <<
"i: " << i << std::endl);
196 buf = (
char *) malloc( i + 4 );
197 xdrmem_create(source, buf, i + 4, XDR_DECODE);
198 memcpy( buf, _buf, 4 );
200 _in.read( buf + 4, i );
202 xdr_setpos( source, 0 );
204 throw Error(
"Network I/O Error. Could not read string data.");
209 _in.read( _buf + 4, i );
211 xdr_setpos( _source, 0 );
213 throw Error(
"Network I/O Error. Could not read string data.");
230 xdr_setpos( _source, 0 );
236 throw Error(
"Network I/O Error. Length of opaque data larger than allowed");
238 _in.read( _buf, len );
240 xdr_opaque( _source, val, len ) ;
246 xdr_setpos( _source, 0 );
249 if( !xdr_int( _source, &val ) )
250 throw Error(
"Network I/O Error(1).");
252 DBG(std::cerr <<
"get_int: " << val << std::endl);
260 DBG(std::cerr <<
"i: " << i << std::endl);
264 DBG(std::cerr <<
"i: " << i << std::endl);
271 buf = (
char *) malloc( i + 4 );
272 xdrmem_create(source, buf, i + 4, XDR_DECODE);
273 memcpy( buf, _buf, 4 );
275 _in.read( buf + 4, i );
276 DBG2(cerr <<
"bytes read: " << _in.gcount() << endl);
278 xdr_setpos( source, 0 );
280 throw Error(
"Network I/O Error. Could not read byte array data.");
285 _in.read( _buf + 4, i );
286 DBG2(cerr <<
"bytes read: " << _in.gcount() << endl);
288 xdr_setpos( _source, 0 );
290 throw Error(
"Network I/O Error. Could not read byte array data.");
299 DBG(std::cerr <<
"i: " << i << std::endl);
302 DBG(std::cerr <<
"width: " << width << std::endl);
306 int size = i * width;
312 buf = (
char *) malloc( size + 4 );
313 xdrmem_create(source, buf, size + 4, XDR_DECODE);
314 DBG2(cerr <<
"size: " << size << endl);
315 memcpy(buf, _buf, 4);
317 _in.read(buf + 4, size);
318 DBG2(cerr <<
"bytes read: " << _in.gcount() << endl);
320 xdr_setpos( source, 0 );
323 throw Error(
"Network I/O Error. Could not read array data.");
328 _in.read(_buf + 4, size);
329 DBG2(cerr <<
"bytes read: " << _in.gcount() << endl);
331 xdr_setpos( _source, 0 );
334 throw Error(
"Network I/O Error. Could not read array data.");
342 << (
void *)
this <<
")" << endl ;
abstract base class used to unmarshall/deserialize dap data objects
virtual void get_uint32(dods_uint32 &val)
virtual void get_vector(char **val, unsigned int &num, Vector &vec)
Holds a one-dimensional collection of DAP2 data types.
virtual void get_uint16(dods_uint16 &val)
virtual void get_int16(dods_int16 &val)
virtual void get_int(int &val)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
const int XDR_DAP_BUFF_SIZE
virtual ~XDRStreamUnMarshaller()
A class for software fault reporting.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
virtual void get_int32(dods_int32 &val)
unmarshaller that knows how to unmarshall/deserialize dap objects using XDR from a file ...
const unsigned int max_str_len
virtual void get_byte(dods_byte &val)
Type type() const
Returns the type of the class instance.
virtual void get_float64(dods_float64 &val)
void delete_xdrstdio(XDR *xdr)
virtual void get_str(string &val)
static ostream & LMarg(ostream &strm)
virtual void get_float32(dods_float32 &val)
virtual void get_url(string &val)
The basic data type for the DODS DAP types.
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 get_opaque(char *val, unsigned int len)