35 #include "XDRFileMarshaller.h" 47 #include "Structure.h" 52 #include "InternalErr.h" 56 XDRFileMarshaller::XDRFileMarshaller(FILE *out) :
59 _sink = new_xdrstdio(out, XDR_ENCODE);
62 XDRFileMarshaller::XDRFileMarshaller() :
63 Marshaller(), _sink(0)
65 throw InternalErr( __FILE__, __LINE__,
"Default constructor not implemented.");
68 XDRFileMarshaller::XDRFileMarshaller(
const XDRFileMarshaller &m) :
69 Marshaller(m), _sink(0)
71 throw InternalErr( __FILE__, __LINE__,
"Copy constructor not implemented.");
75 XDRFileMarshaller::operator=(
const XDRFileMarshaller &)
77 throw InternalErr( __FILE__, __LINE__,
"Copy operator not implemented.");
82 XDRFileMarshaller::~XDRFileMarshaller()
84 delete_xdrstdio(_sink);
87 void 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.");
94 void 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.");
101 void 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.");
108 void 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.");
115 void 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.");
122 void 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.");
128 void 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.");
134 void 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.");
142 void XDRFileMarshaller::put_url(
const string &val)
147 void 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.");
153 void XDRFileMarshaller::put_int(
int val)
155 if (!xdr_int(_sink, &val))
156 throw Error(
"Network I/O Error(1).");
159 void 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).");
170 void 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,
179 throw Error(
"Network I/O Error(2).");
185 strm << DapIndent::LMarg <<
"XDRFileMarshaller::dump - (" << (
void *)
this <<
")" << endl;
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
static xdrproc_t xdr_coder(const Type &t)
Returns a function used to encode elements of an array.