51char *XDRStreamUnMarshaller::d_buf = 0;
53XDRStreamUnMarshaller::XDRStreamUnMarshaller(istream &in)
57 d_buf = (
char *)malloc(XDR_DAP_BUFF_SIZE);
62 xdrmem_create(&d_source, d_buf, XDR_DAP_BUFF_SIZE, XDR_DECODE);
65XDRStreamUnMarshaller::XDRStreamUnMarshaller() :
UnMarshaller(), d_in(cin) {
66 throw InternalErr(__FILE__, __LINE__,
"Default constructor not implemented.");
69XDRStreamUnMarshaller::XDRStreamUnMarshaller(
const XDRStreamUnMarshaller &um)
70 : UnMarshaller(um), d_in(cin) {
71 throw InternalErr(__FILE__, __LINE__,
"Copy constructor not implemented.");
75 throw InternalErr(__FILE__, __LINE__,
"Copy operator not implemented.");
79 xdr_destroy(&d_source);
84 if (xdr_setpos(&d_source, 0) < 0)
85 throw Error(
"Failed to reposition input stream");
86 if (!(d_in.read(d_buf, 4))) {
88 throw Error(
"Premature EOF in input stream");
90 ostringstream ss(
"Error reading from input stream: ");
92 throw Error(ss.str());
96 DBG2(std::cerr <<
"_in.gcount(): " << d_in.gcount() << std::endl);
97 DBG2(std::cerr <<
"_in.tellg(): " << d_in.tellg() << std::endl);
98 DBG2(std::cerr <<
"_buf[0]: " << hex << d_buf[0] <<
"; _buf[1]: " << d_buf[1] <<
"; _buf[2]: " << d_buf[2]
99 <<
"; _buf[3]: " << d_buf[3] << dec << std::endl);
101 if (!xdr_char(&d_source, (
char *)&val))
102 throw Error(
"Network I/O Error. Could not read byte data.");
104 DBG2(std::cerr <<
"get_byte: " << val << std::endl);
108 xdr_setpos(&d_source, 0);
112 throw Error(
"Network I/O Error. Could not read int 16 data.");
116 xdr_setpos(&d_source, 0);
120 throw Error(
"Network I/O Error. Could not read int 32 data.");
124 xdr_setpos(&d_source, 0);
127 if (!xdr_float(&d_source, &val))
128 throw Error(
"Network I/O Error. Could not read float 32 data.");
132 xdr_setpos(&d_source, 0);
135 if (!xdr_double(&d_source, &val))
136 throw Error(
"Network I/O Error. Could not read float 64 data.");
140 xdr_setpos(&d_source, 0);
144 throw Error(
"Network I/O Error. Could not read uint 16 data.");
148 xdr_setpos(&d_source, 0);
152 throw Error(
"Network I/O Error. Could not read uint 32 data.");
158 DBG(std::cerr <<
"i: " << i << std::endl);
161 i = ((i + 3) / 4) * 4;
162 DBG(std::cerr <<
"i: " << i << std::endl);
168 if (i + 4 > XDR_DAP_BUFF_SIZE) {
170 char *buf = (
char *) malloc(i + 4);
172 throw InternalErr(__FILE__, __LINE__,
"Error allocating memory");
174 vector<char> buf(i + 4);
177 xdrmem_create(&source, buf.data(), i + 4, XDR_DECODE);
178 memcpy(buf.data(), d_buf, 4);
180 d_in.read(buf.data() + 4, i);
182 xdr_setpos(&source, 0);
184 xdr_destroy(&source);
185 throw Error(
"Network I/O Error. Could not read string data.");
188 xdr_destroy(&source);
190 d_in.read(d_buf + 4, i);
192 xdr_setpos(&d_source, 0);
194 throw Error(
"Network I/O Error. Could not read string data.");
205 xdr_setpos(&d_source, 0);
210 if (
static_cast<int>(len) > XDR_DAP_BUFF_SIZE)
211 throw Error(
"Network I/O Error. Length of opaque data larger than allowed");
213 d_in.read(d_buf, len);
215 xdr_opaque(&d_source, val, len);
219 xdr_setpos(&d_source, 0);
222 if (!xdr_int(&d_source, &val))
223 throw Error(
"Network I/O Error(1).");
225 DBG(std::cerr <<
"get_int: " << val << std::endl);
231 DBG(std::cerr <<
"i: " << i << std::endl);
235 DBG(std::cerr <<
"i: " << i << std::endl);
240 if (i + 4 > XDR_DAP_BUFF_SIZE) {
241 vector<char> buf(i + 4);
243 xdrmem_create(&source, buf.data(), i + 4, XDR_DECODE);
244 memcpy(buf.data(), d_buf, 4);
246 d_in.read(buf.data() + 4, i);
247 DBG2(cerr <<
"bytes read: " << d_in.gcount() << endl);
249 xdr_setpos(&source, 0);
251 xdr_destroy(&source);
252 throw Error(
"Network I/O Error. Could not read byte array data.");
255 xdr_destroy(&source);
257 d_in.read(d_buf + 4, i);
258 DBG2(cerr <<
"bytes read: " << d_in.gcount() << endl);
260 xdr_setpos(&d_source, 0);
262 throw Error(
"Network I/O Error. Could not read byte array data.");
273 DBG(std::cerr <<
"i: " << i << std::endl);
276 DBG(std::cerr <<
"width: " << width << std::endl);
278 int size = i * width;
281 if (size > XDR_DAP_BUFF_SIZE) {
282 vector<char> buf(size + 4);
284 xdrmem_create(&source, buf.data(), size + 4, XDR_DECODE);
285 DBG(cerr <<
"size: " << size << endl);
286 memcpy(buf.data(), d_buf, 4);
288 d_in.read(buf.data() + 4, size);
289 DBG(cerr <<
"bytes read: " << d_in.gcount() << endl);
291 xdr_setpos(&source, 0);
293 xdr_destroy(&source);
294 throw Error(
"Network I/O Error. Could not read array data.");
297 xdr_destroy(&source);
299 d_in.read(d_buf + 4, size);
300 DBG(cerr <<
"bytes read (2): " << d_in.gcount() << endl);
302 xdr_setpos(&d_source, 0);
304 throw Error(
"Network I/O Error. Could not read array data.");
309 strm <<
DapIndent::LMarg <<
"XDRStreamUnMarshaller::dump - (" << (
void *)
this <<
")" << endl;
#define internal_error
Internal server error (500)
virtual Type type() const
Returns the type of the class instance.
static ostream & LMarg(ostream &strm)
A class for error processing.
A class for software fault reporting.
abstract base class used to unmarshall/deserialize dap data objects
Holds a one-dimensional collection of DAP2 data types.
BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr) override
unmarshaller that knows how to unmarshall/deserialize dap objects using XDR from a file
virtual void get_int(int &val)
virtual void get_str(string &val)
virtual void get_int32(dods_int32 &val)
virtual void get_byte(dods_byte &val)
virtual void get_int16(dods_int16 &val)
virtual void get_uint16(dods_uint16 &val)
virtual void get_url(string &val)
virtual void get_uint32(dods_uint32 &val)
virtual void get_float64(dods_float64 &val)
virtual ~XDRStreamUnMarshaller()
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void get_opaque(char *val, unsigned int len)
virtual void get_float32(dods_float32 &val)
virtual void get_vector(char **val, unsigned int &num, Vector &vec)
static xdrproc_t xdr_coder(const Type &t)
Returns a function used to encode elements of an array.
top level DAP object to house generic methods
Type
Identifies the data type.
const unsigned int max_str_len