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." ) ;
71 XDRStreamUnMarshaller::XDRStreamUnMarshaller(
const XDRStreamUnMarshaller &um )
72 : UnMarshaller( um ), _source( 0 ), _in( cin )
74 throw InternalErr( __FILE__, __LINE__,
"Copy constructor not implemented." ) ;
77 XDRStreamUnMarshaller &
78 XDRStreamUnMarshaller::operator=(
const XDRStreamUnMarshaller & )
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);
195 char *buf = (
char *) malloc( i + 4 );
197 throw InternalErr(__FILE__, __LINE__,
"Error allocating memory");
198 XDR *source =
new XDR;
199 xdrmem_create(source, buf, i + 4, XDR_DECODE);
200 memcpy( buf, _buf, 4 );
202 _in.read( buf + 4, i );
204 xdr_setpos( source, 0 );
205 if( !xdr_string( source, &in_tmp,
max_str_len ) ) {
207 throw Error(
"Network I/O Error. Could not read string data.");
213 _in.read( _buf + 4, i );
215 xdr_setpos( _source, 0 );
217 throw Error(
"Network I/O Error. Could not read string data.");
234 xdr_setpos( _source, 0 );
240 throw Error(
"Network I/O Error. Length of opaque data larger than allowed");
242 _in.read( _buf, len );
244 xdr_opaque( _source, val, len ) ;
250 xdr_setpos( _source, 0 );
253 if( !xdr_int( _source, &val ) )
254 throw Error(
"Network I/O Error(1).");
256 DBG(std::cerr <<
"get_int: " << val << std::endl);
264 DBG(std::cerr <<
"i: " << i << std::endl);
268 DBG(std::cerr <<
"i: " << i << std::endl);
274 char *buf = (
char *) malloc( i + 4 );
276 throw InternalErr(__FILE__, __LINE__,
"Error allocating memory");
277 XDR *source =
new XDR;
278 xdrmem_create(source, buf, i + 4, XDR_DECODE);
279 memcpy( buf, _buf, 4 );
281 _in.read( buf + 4, i );
282 DBG2(cerr <<
"bytes read: " << _in.gcount() << endl);
284 xdr_setpos( source, 0 );
287 throw Error(
"Network I/O Error. Could not read byte array data.");
293 _in.read( _buf + 4, i );
294 DBG2(cerr <<
"bytes read: " << _in.gcount() << endl);
296 xdr_setpos( _source, 0 );
298 throw Error(
"Network I/O Error. Could not read byte array data.");
307 DBG(std::cerr <<
"i: " << i << std::endl);
310 DBG(std::cerr <<
"width: " << width << std::endl);
314 int size = i * width;
319 char *buf = (
char *) malloc( size + 4 );
321 throw InternalErr(__FILE__, __LINE__,
"Error allocating memory");
322 XDR *source =
new XDR;
323 xdrmem_create(source, buf, size + 4, XDR_DECODE);
324 DBG2(cerr <<
"size: " << size << endl);
325 memcpy(buf, _buf, 4);
327 _in.read(buf + 4, size);
328 DBG2(cerr <<
"bytes read: " << _in.gcount() << endl);
330 xdr_setpos( source, 0 );
334 throw Error(
"Network I/O Error. Could not read array data.");
340 _in.read(_buf + 4, size);
341 DBG2(cerr <<
"bytes read: " << _in.gcount() << endl);
343 xdr_setpos( _source, 0 );
346 throw Error(
"Network I/O Error. Could not read array data.");
354 << (
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)
Type type() const
Returns the type of the class instance.
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)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
const unsigned int max_str_len
virtual void get_byte(dods_byte &val)
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)