35#include "XDRFileMarshaller.h"
52#include "InternalErr.h"
57XDRFileMarshaller::XDRFileMarshaller(FILE *out) :
60 _sink = new_xdrstdio(out, XDR_ENCODE);
63XDRFileMarshaller::XDRFileMarshaller() :
64 Marshaller(), _sink(0)
66 throw InternalErr( __FILE__, __LINE__,
"Default constructor not implemented.");
69XDRFileMarshaller::XDRFileMarshaller(
const XDRFileMarshaller &m) :
70 Marshaller(m), _sink(0)
72 throw InternalErr( __FILE__, __LINE__,
"Copy constructor not implemented.");
76XDRFileMarshaller::operator=(
const XDRFileMarshaller &)
78 throw InternalErr( __FILE__, __LINE__,
"Copy operator not implemented.");
81XDRFileMarshaller::~XDRFileMarshaller()
83 delete_xdrstdio(_sink);
86void XDRFileMarshaller::put_byte(dods_byte val)
88 if (!xdr_char(_sink, (
char *) &val))
90 "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.");
93void XDRFileMarshaller::put_int16(dods_int16 val)
95 if (!XDR_INT16(_sink, &val))
97 "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.");
100void XDRFileMarshaller::put_int32(dods_int32 val)
102 if (!XDR_INT32(_sink, &val))
104 "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.");
107void XDRFileMarshaller::put_float32(dods_float32 val)
109 if (!xdr_float(_sink, &val))
111 "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.");
114void XDRFileMarshaller::put_float64(dods_float64 val)
116 if (!xdr_double(_sink, &val))
118 "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.");
121void XDRFileMarshaller::put_uint16(dods_uint16 val)
123 if (!XDR_UINT16(_sink, &val))
124 throw Error(
"Network I/O Error. Could not send uint 16 data.");
127void XDRFileMarshaller::put_uint32(dods_uint32 val)
129 if (!XDR_UINT32(_sink, &val))
130 throw Error(
"Network I/O Error. Could not send uint 32 data.");
133void XDRFileMarshaller::put_str(
const string &val)
135 const char *out_tmp = val.c_str();
137 if (!xdr_string(_sink, (
char **) &out_tmp, max_str_len))
138 throw Error(
"Network I/O Error. Could not send string data.");
141void XDRFileMarshaller::put_url(
const string &val)
146void XDRFileMarshaller::put_opaque(
char *val,
unsigned int len)
148 if (!xdr_opaque(_sink, val, len))
149 throw Error(
"Network I/O Error. Could not send opaque data.");
152void XDRFileMarshaller::put_int(
int val)
154 if (!xdr_int(_sink, &val))
155 throw Error(
"Network I/O Error(1).");
158void XDRFileMarshaller::put_vector(
char *val,
int num, Vector &)
160 if (!val)
throw InternalErr(__FILE__, __LINE__,
"Buffer pointer is not set.");
164 if (!xdr_bytes(_sink, (
char **) &val, (
unsigned int *) &num, DODS_MAX_ARRAY)) {
165 throw Error(
"Network I/O Error(2).");
169void XDRFileMarshaller::put_vector(
char *val,
int num,
int width, Vector &vec)
171 if (!val)
throw InternalErr(__FILE__, __LINE__,
"Buffer pointer is not set.");
175 BaseType *var = vec.var();
176 if (!xdr_array(_sink, (
char **) &val, (
unsigned int *) &num, DODS_MAX_ARRAY, width,
177 XDRUtils::xdr_coder(var->type()))) {
178 throw Error(
"Network I/O Error(2).");
182void XDRFileMarshaller::dump(ostream &strm)
const
184 strm << DapIndent::LMarg <<
"XDRFileMarshaller::dump - (" << (
void *)
this <<
")" << endl;
top level DAP object to house generic methods