libdap  Updated for version 3.20.6
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4StreamMarshaller.h
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 <rpc/types.h>
45 #include <netinet/in.h>
46 #include <rpc/xdr.h>
47 #endif
48 #endif
49 
50 #include <stdint.h>
51 #include "crc.h"
52 
53 #include "Marshaller.h"
54 #include "InternalErr.h"
55 
56 namespace libdap {
57 
58 class Vector;
59 class MarshallerThread;
60 
72 
73 private:
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 
84  MarshallerThread *tm;
85 
86  // These are private so they won't ever get used.
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 
95 public:
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) {
133  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix.");
134  }
135 
136  virtual void put_vector(char *val, int64_t num_bytes);
137  virtual void put_vector(char *val, int64_t num_elem, int elem_size);
138  virtual void put_vector_float32(char *val, int64_t num_elem);
139  virtual void put_vector_float64(char *val, int64_t num_elem);
140 
141  virtual void put_vector(char *, int , Vector &) {
142  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use other put_vector() versions.");
143  }
144  virtual void put_vector(char *, int , int , Vector &) {
145  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use other put_vector() versions.");
146  }
147 
157  virtual void put_vector_start(int /*num*/) {
158  }
159 
160  virtual void put_vector_part(char */*val*/, unsigned int /*num*/, int /*width*/, Type /*type*/);
161 
170  virtual void put_vector_end() {
171  }
172 
173  virtual void dump(std::ostream &strm) const;
174 };
175 
176 } // namespace libdap
177 
178 #endif // I_D4StreamMarshaller_h
virtual void put_count(int64_t count)
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:80
Definition: crc.h:76
virtual void dump(std::ostream &strm) const
dump the contents of this object to the specified ostream
virtual void put_vector_float32(char *val, int64_t num_elem)
Write a fixed size vector.
Type
Identifies the data type.
Definition: Type.h:94
top level DAP object to house generic methods
Definition: AISConnect.cc:30
A class for software fault reporting.
Definition: InternalErr.h:64
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4&#39;s receiv...
virtual void put_vector_part(char *, unsigned int, int, Type)
virtual void checksum_update(const void *data, unsigned long len)
virtual void put_vector(char *val, int64_t num_bytes)
Write a fixed size vector.
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:50
virtual void put_vector_float64(char *val, int64_t num_elem)
Write a fixed size vector of float64s.
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_vector_start(int)