libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4StreamMarshaller.h
Go to the documentation of this file.
1// D4StreamMarshaller.h
2
3// -*- mode: c++; c-basic-offset:4 -*-
4
5// This file is part of libdap, A C++ implementation of the OPeNDAP Data
6// Access Protocol.
7
8// Copyright (c) 2002,2003,2012 OPeNDAP, Inc.
9// Author: Patrick West <pwest@ucar.edu>,
10// James Gallagher <jgallagher@opendap.org>
11//
12// This library is free software; you can redistribute it and/or
13// modify it under the terms of the GNU Lesser General Public
14// License as published by the Free Software Foundation; either
15// version 2.1 of the License, or (at your option) any later version.
16//
17// This library is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20// Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public
23// License along with this library; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25//
26// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
27
28#ifndef I_D4StreamMarshaller_h
29#define I_D4StreamMarshaller_h 1
30
31#include <iostream>
32
33// By default, only support platforms that use IEEE754 for floating point values.
34// Hacked up code leftover from an older version of the class; largely untested.
35// jhrg 10/3/13
36#define USE_XDR_FOR_IEEE754_ENCODING 0
37
38#if USE_XDR_FOR_IEEE754_ENCODING
39#ifdef WIN32
40#include <rpc.h>
41#include <winsock2.h>
42#include <xdr.h>
43#else
44#include <netinet/in.h>
45#include <rpc/types.h>
46#include <rpc/xdr.h>
47#endif
48#endif
49
50#include "crc.h"
51#include <stdint.h>
52
53#include "InternalErr.h"
54#include "Marshaller.h"
55
56namespace libdap {
57
58class Vector;
59class MarshallerThread;
60
71class D4StreamMarshaller : public Marshaller {
72
73private:
74#if USE_XDR_FOR_IEEE754_ENCODING
75 XDR d_scalar_sink;
76 char d_ieee754_buf[sizeof(dods_float64)]; // used to serialize a float or double
77#endif
78
79 ostream &d_out;
80 bool d_write_data; // jhrg 1/27/12
81
82 Crc32 d_checksum;
83
85
86 // These are private so they won't ever get used.
87 D4StreamMarshaller();
88 D4StreamMarshaller(const D4StreamMarshaller &);
89 D4StreamMarshaller &operator=(const D4StreamMarshaller &);
90
91#if USE_XDR_FOR_IEEE754_ENCODING
92 void m_serialize_reals(char *val, int64_t num, int width, Type type);
93#endif
94
95public:
96 D4StreamMarshaller(std::ostream &out, bool write_data = true);
97 virtual ~D4StreamMarshaller();
98
99 virtual void reset_checksum();
100 virtual string get_checksum();
101 virtual void checksum_update(const void *data, unsigned long len);
102
103 virtual void put_checksum();
104 virtual void put_count(int64_t count);
105
106 virtual void put_byte(dods_byte val);
107 virtual void put_int8(dods_int8 val);
108
109 virtual void put_int16(dods_int16 val);
110 virtual void put_int32(dods_int32 val);
111 // Added
112 virtual void put_int64(dods_int64 val);
113
114 virtual void put_float32(dods_float32 val);
115 virtual void put_float64(dods_float64 val);
116
117 virtual void put_uint16(dods_uint16 val);
118 virtual void put_uint32(dods_uint32 val);
119 // Added
120 virtual void put_uint64(dods_uint64 val);
121
122 virtual void put_str(const string &val);
123 virtual void put_url(const string &val);
124
125 virtual void put_opaque(char *, unsigned int) {
126 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4; use put_opaque_dap4() instead.");
127 }
128
129 virtual void put_opaque_dap4(const char *val, int64_t len);
130
131 // Never use put_int() to send length information in DAP4.
132 virtual void put_int(int) { throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix."); }
133
134 virtual void put_vector(char *val, int64_t num_bytes);
135 virtual void put_vector(char *val, int64_t num_elem, int elem_size);
136 virtual void put_vector_float32(char *val, int64_t num_elem);
137 virtual void put_vector_float64(char *val, int64_t num_elem);
138
139 virtual void put_vector(char *, int, Vector &) {
140 throw InternalErr(__FILE__, __LINE__, "Not Implemented; use other put_vector() versions.");
141 }
142 virtual void put_vector(char *, int, int, Vector &) {
143 throw InternalErr(__FILE__, __LINE__, "Not Implemented; use other put_vector() versions.");
144 }
145
155 virtual void put_vector_start(int /*num*/) {}
156
157 virtual void put_vector_part(char * /*val*/, unsigned int /*num*/, int /*width*/, Type /*type*/);
158
167 virtual void put_vector_end() {}
168
169 virtual void dump(std::ostream &strm) const;
170};
171
172} // namespace libdap
173
174#endif // I_D4StreamMarshaller_h
Definition crc.h:43
virtual void put_uint16(dods_uint16 val)
virtual void put_checksum()
Write the checksum Write the checksum for the data sent since the last call to reset_checksum() to th...
virtual void put_int32(dods_int32 val)
virtual void put_opaque_dap4(const char *val, int64_t len)
virtual void put_uint64(dods_uint64 val)
virtual void put_vector_float32(char *val, int64_t num_elem)
Write a fixed size vector.
virtual void put_vector_part(char *, unsigned int, int, Type)
virtual void put_byte(dods_byte val)
virtual void put_str(const string &val)
virtual void put_vector(char *val, int64_t num_bytes)
Write a fixed size vector.
virtual void dump(std::ostream &strm) const
dump the contents of this object to the specified ostream
virtual void put_count(int64_t count)
virtual void put_int8(dods_int8 val)
virtual void put_int64(dods_int64 val)
virtual void put_url(const string &val)
virtual void put_int16(dods_int16 val)
virtual void put_vector(char *, int, Vector &)
virtual void put_uint32(dods_uint32 val)
virtual void checksum_update(const void *data, unsigned long len)
virtual void put_float64(dods_float64 val)
virtual void put_vector(char *, int, int, Vector &)
virtual void put_vector_float64(char *val, int64_t num_elem)
Write a fixed size vector of float64s.
virtual void put_opaque(char *, unsigned int)
virtual void put_float32(dods_float32 val)
A class for software fault reporting.
Definition InternalErr.h:61
abstract base class used to marshal/serialize dap data objects
Definition Marshaller.h:50
Holds a one-dimensional collection of DAP2 data types.
Definition Vector.h:81
top level DAP object to house generic methods
Definition AISConnect.cc:30
Type
Identifies the data type.
Definition Type.h:94
uint64_t dods_uint64
uint32_t dods_uint32
uint16_t dods_uint16