35#include "XDRFileMarshaller.h"
52#include "InternalErr.h"
56XDRFileMarshaller::XDRFileMarshaller(FILE *out) :
59 _sink = new_xdrstdio(out, XDR_ENCODE);
62XDRFileMarshaller::XDRFileMarshaller() :
63 Marshaller(), _sink(0)
65 throw InternalErr( __FILE__, __LINE__,
"Default constructor not implemented.");
68XDRFileMarshaller::XDRFileMarshaller(
const XDRFileMarshaller &m) :
69 Marshaller(m), _sink(0)
71 throw InternalErr( __FILE__, __LINE__,
"Copy constructor not implemented.");
75XDRFileMarshaller::operator=(
const XDRFileMarshaller &)
77 throw InternalErr( __FILE__, __LINE__,
"Copy operator not implemented.");
82XDRFileMarshaller::~XDRFileMarshaller()
84 delete_xdrstdio(_sink);
87void XDRFileMarshaller::put_byte(dods_byte val)
89 if (!xdr_char(_sink, (
char *) &val))
91 "Network I/O Error. Could not send byte data.\nThis may be due to a bug in DODS, on the server or a\nproblem with the network connection.");
94void XDRFileMarshaller::put_int16(dods_int16 val)
96 if (!XDR_INT16(_sink, &val))
98 "Network I/O Error. Could not send int 16 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
101void XDRFileMarshaller::put_int32(dods_int32 val)
103 if (!XDR_INT32(_sink, &val))
105 "Network I/O Error. Could not read int 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
108void XDRFileMarshaller::put_float32(dods_float32 val)
110 if (!xdr_float(_sink, &val))
112 "Network I/O Error. Could not send float 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
115void XDRFileMarshaller::put_float64(dods_float64 val)
117 if (!xdr_double(_sink, &val))
119 "Network I/O Error. Could not send float 64 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
122void XDRFileMarshaller::put_uint16(dods_uint16 val)
124 if (!XDR_UINT16(_sink, &val))
125 throw Error(
"Network I/O Error. Could not send uint 16 data.");
128void XDRFileMarshaller::put_uint32(dods_uint32 val)
130 if (!XDR_UINT32(_sink, &val))
131 throw Error(
"Network I/O Error. Could not send uint 32 data.");
134void XDRFileMarshaller::put_str(
const string &val)
136 const char *out_tmp = val.c_str();
138 if (!xdr_string(_sink, (
char **) &out_tmp, max_str_len))
139 throw Error(
"Network I/O Error. Could not send string data.");
142void XDRFileMarshaller::put_url(
const string &val)
147void XDRFileMarshaller::put_opaque(
char *val,
unsigned int len)
149 if (!xdr_opaque(_sink, val, len))
150 throw Error(
"Network I/O Error. Could not send opaque data.");
153void XDRFileMarshaller::put_int(
int val)
155 if (!xdr_int(_sink, &val))
156 throw Error(
"Network I/O Error(1).");
159void XDRFileMarshaller::put_vector(
char *val,
int num, Vector &)
161 if (!val)
throw InternalErr(__FILE__, __LINE__,
"Buffer pointer is not set.");
165 if (!xdr_bytes(_sink, (
char **) &val, (
unsigned int *) &num, DODS_MAX_ARRAY)) {
166 throw Error(
"Network I/O Error(2).");
170void XDRFileMarshaller::put_vector(
char *val,
int num,
int width, Vector &vec)
172 if (!val)
throw InternalErr(__FILE__, __LINE__,
"Buffer pointer is not set.");
176 BaseType *var = vec.var();
177 if (!xdr_array(_sink, (
char **) &val, (
unsigned int *) &num, DODS_MAX_ARRAY, width,
178 XDRUtils::xdr_coder(var->type()))) {
179 throw Error(
"Network I/O Error(2).");
183void XDRFileMarshaller::dump(ostream &strm)
const
185 strm << DapIndent::LMarg <<
"XDRFileMarshaller::dump - (" << (
void *)
this <<
")" << endl;