35 #include "XDRFileMarshaller.h" 47 #include "Structure.h" 52 #include "InternalErr.h" 53 #include "DapIndent.h" 57 XDRFileMarshaller::XDRFileMarshaller(FILE *out) :
60 _sink = new_xdrstdio(out, XDR_ENCODE);
63 XDRFileMarshaller::XDRFileMarshaller() :
64 Marshaller(), _sink(0)
66 throw InternalErr( __FILE__, __LINE__,
"Default constructor not implemented.");
69 XDRFileMarshaller::XDRFileMarshaller(
const XDRFileMarshaller &m) :
70 Marshaller(m), _sink(0)
72 throw InternalErr( __FILE__, __LINE__,
"Copy constructor not implemented.");
76 XDRFileMarshaller::operator=(
const XDRFileMarshaller &)
78 throw InternalErr( __FILE__, __LINE__,
"Copy operator not implemented.");
83 XDRFileMarshaller::~XDRFileMarshaller()
85 delete_xdrstdio(_sink);
88 void XDRFileMarshaller::put_byte(dods_byte val)
90 if (!xdr_char(_sink, (
char *) &val))
92 "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.");
95 void XDRFileMarshaller::put_int16(dods_int16 val)
97 if (!XDR_INT16(_sink, &val))
99 "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.");
102 void XDRFileMarshaller::put_int32(dods_int32 val)
104 if (!XDR_INT32(_sink, &val))
106 "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.");
109 void XDRFileMarshaller::put_float32(dods_float32 val)
111 if (!xdr_float(_sink, &val))
113 "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.");
116 void XDRFileMarshaller::put_float64(dods_float64 val)
118 if (!xdr_double(_sink, &val))
120 "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.");
123 void XDRFileMarshaller::put_uint16(dods_uint16 val)
125 if (!XDR_UINT16(_sink, &val))
126 throw Error(
"Network I/O Error. Could not send uint 16 data.");
129 void XDRFileMarshaller::put_uint32(dods_uint32 val)
131 if (!XDR_UINT32(_sink, &val))
132 throw Error(
"Network I/O Error. Could not send uint 32 data.");
135 void XDRFileMarshaller::put_str(
const string &val)
137 const char *out_tmp = val.c_str();
139 if (!xdr_string(_sink, (
char **) &out_tmp, max_str_len))
140 throw Error(
"Network I/O Error. Could not send string data.");
143 void XDRFileMarshaller::put_url(
const string &val)
148 void XDRFileMarshaller::put_opaque(
char *val,
unsigned int len)
150 if (!xdr_opaque(_sink, val, len))
151 throw Error(
"Network I/O Error. Could not send opaque data.");
154 void XDRFileMarshaller::put_int(
int val)
156 if (!xdr_int(_sink, &val))
157 throw Error(
"Network I/O Error(1).");
160 void XDRFileMarshaller::put_vector(
char *val,
int num,
Vector &)
162 if (!val)
throw InternalErr(__FILE__, __LINE__,
"Buffer pointer is not set.");
166 if (!xdr_bytes(_sink, (
char **) &val, (
unsigned int *) &num, DODS_MAX_ARRAY)) {
167 throw Error(
"Network I/O Error(2).");
171 void XDRFileMarshaller::put_vector(
char *val,
int num,
int width,
Vector &vec)
173 if (!val)
throw InternalErr(__FILE__, __LINE__,
"Buffer pointer is not set.");
178 if (!xdr_array(_sink, (
char **) &val, (
unsigned int *) &num, DODS_MAX_ARRAY, width,
180 throw Error(
"Network I/O Error(2).");
186 strm << DapIndent::LMarg <<
"XDRFileMarshaller::dump - (" << (
void *)
this <<
")" << endl;
virtual unsigned int width(bool constrained=false) const
Returns the width of the data, in bytes.
BaseType(const string &n, const Type &t, bool is_dap4=false)
The BaseType constructor.
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
top level DAP object to house generic methods
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
Vector(const string &n, BaseType *v, const Type &t, bool is_dap4=false)
The Vector constructor.
static xdrproc_t xdr_coder(const Type &t)
Returns a function used to encode elements of an array.