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 ;