51 char *XDRStreamUnMarshaller::d_buf = 0;
53 XDRStreamUnMarshaller::XDRStreamUnMarshaller(istream &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), d_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.");
87 xdr_destroy( &d_source );
93 if (xdr_setpos( &d_source, 0 ) < 0)
94 throw Error(
"Failed to reposition input stream");
95 if (!(d_in.read(d_buf, 4))) {
97 throw Error(
"Premature EOF in input stream");
99 ostringstream ss(
"Error reading from input stream: ");
100 ss << d_in.rdstate();
101 throw Error(ss.str());
105 DBG2( std::cerr <<
"_in.gcount(): " << d_in.gcount() << std::endl );
DBG2( std::cerr <<
"_in.tellg(): " << d_in.tellg() << std::endl );
DBG2( std::cerr <<
"_buf[0]: " << hex << d_buf[0] <<
"; _buf[1]: " << d_buf[1]
106 <<
"; _buf[2]: " << d_buf[2] <<
"; _buf[3]: " << d_buf[3]
107 << dec << std::endl );
109 if (!xdr_char(&d_source, (
char *) &val))
110 throw Error(
"Network I/O Error. Could not read byte data.");
112 DBG2(std::cerr <<
"get_byte: " << val << std::endl );
117 xdr_setpos( &d_source, 0);
121 throw Error(
"Network I/O Error. Could not read int 16 data.");
126 xdr_setpos( &d_source, 0);
130 throw Error(
"Network I/O Error. Could not read int 32 data.");
135 xdr_setpos( &d_source, 0);
138 if (!xdr_float(&d_source, &val))
139 throw Error(
"Network I/O Error. Could not read float 32 data.");
144 xdr_setpos( &d_source, 0);
147 if (!xdr_double(&d_source, &val))
148 throw Error(
"Network I/O Error. Could not read float 64 data.");
153 xdr_setpos( &d_source, 0);
157 throw Error(
"Network I/O Error. Could not read uint 16 data.");
162 xdr_setpos( &d_source, 0);
166 throw Error(
"Network I/O Error. Could not read uint 32 data.");
173 DBG(std::cerr <<
"i: " << i << std::endl);
176 i = ((i + 3) / 4) * 4;
177 DBG(std::cerr <<
"i: " << i << std::endl);
185 char *buf = (
char *) malloc(i + 4);
187 throw InternalErr(__FILE__, __LINE__,
"Error allocating memory");
189 vector<char> buf(i+4);
192 xdrmem_create(&source, &buf[0], i + 4, XDR_DECODE);
193 memcpy(&buf[0], d_buf, 4);
195 d_in.read(&buf[0] + 4, i);
197 xdr_setpos( &source, 0);
199 xdr_destroy( &source );
200 throw Error(
"Network I/O Error. Could not read string data.");
203 xdr_destroy( &source );
206 d_in.read(d_buf + 4, i);
208 xdr_setpos( &d_source, 0);
210 throw Error(
"Network I/O Error. Could not read string data.");
225 xdr_setpos( &d_source, 0);
231 throw Error(
"Network I/O Error. Length of opaque data larger than allowed");
233 d_in.read(d_buf, len);
235 xdr_opaque(&d_source, val, len);
240 xdr_setpos( &d_source, 0);
243 if (!xdr_int(&d_source, &val))
244 throw Error(
"Network I/O Error(1).");
246 DBG(std::cerr <<
"get_int: " << val << std::endl);
253 DBG(std::cerr <<
"i: " << i << std::endl);
257 DBG(std::cerr <<
"i: " << i << std::endl);
263 vector<char> buf(i+4);
265 xdrmem_create(&source, &buf[0], i + 4, XDR_DECODE);
266 memcpy(&buf[0], d_buf, 4);
268 d_in.read(&buf[0] + 4, i);
269 DBG2(cerr <<
"bytes read: " << d_in.gcount() << endl);
271 xdr_setpos(&source, 0);
273 xdr_destroy(&source);
274 throw Error(
"Network I/O Error. Could not read byte array data.");
277 xdr_destroy( &source );
280 d_in.read(d_buf + 4, i);
281 DBG2(cerr <<
"bytes read: " << d_in.gcount() << endl);
283 xdr_setpos(&d_source, 0);
285 throw Error(
"Network I/O Error. Could not read byte array data.");
298 DBG(std::cerr <<
"i: " << i << std::endl);
301 DBG(std::cerr <<
"width: " << width << std::endl);
303 int size = i * width;
307 vector<char> buf(size+4);
309 xdrmem_create(&source, &buf[0], size + 4, XDR_DECODE);
310 DBG(cerr <<
"size: " << size << endl);
311 memcpy(&buf[0], d_buf, 4);
313 d_in.read(&buf[0] + 4, size);
314 DBG(cerr <<
"bytes read: " << d_in.gcount() << endl);
316 xdr_setpos(&source, 0);
318 xdr_destroy( &source );
319 throw Error(
"Network I/O Error. Could not read array data.");
322 xdr_destroy( &source );
325 d_in.read(d_buf + 4, size);
326 DBG(cerr <<
"bytes read (2): " << d_in.gcount() << endl);
328 xdr_setpos( &d_source, 0);
330 throw Error(
"Network I/O Error. Could not read array data.");
336 strm <<
DapIndent::LMarg <<
"XDRStreamUnMarshaller::dump - (" << (
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
Identifies the data type.
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)
virtual void get_str(string &val)
static ostream & LMarg(ostream &strm)
virtual void get_float32(dods_float32 &val)
virtual void get_url(string &val)
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)