libdap++  Updated for version 3.14.0
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 <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 
71 
72 private:
73 #if USE_XDR_FOR_IEEE754_ENCODING
74  XDR d_scalar_sink;
75  char d_ieee754_buf[sizeof(dods_float64)]; // used to serialize a float or double
76 #endif
77 
78  ostream &d_out;
79  bool d_write_data; // jhrg 1/27/12
80 
81  Crc32 d_checksum;
82 
83  // These are private so they won't ever get used.
86  D4StreamMarshaller & operator=(const D4StreamMarshaller &);
87 
88 #if USE_XDR_FOR_IEEE754_ENCODING
89  void m_serialize_reals(char *val, int64_t num, int width, Type type);
90 #endif
91 
92 public:
93  D4StreamMarshaller(std::ostream &out, bool write_data = true);
94  virtual ~D4StreamMarshaller();
95 
96  virtual void reset_checksum();
97  virtual string get_checksum();
98  virtual void checksum_update(const void *data, unsigned long len);
99 
100  virtual void put_checksum();
101  virtual void put_count(int64_t count);
102 
103  virtual void put_byte(dods_byte val);
104  virtual void put_int8(dods_int8 val);
105 
106  virtual void put_int16(dods_int16 val);
107  virtual void put_int32(dods_int32 val);
108  // Added
109  virtual void put_int64(dods_int64 val);
110 
111  virtual void put_float32(dods_float32 val);
112  virtual void put_float64(dods_float64 val);
113 
114  virtual void put_uint16(dods_uint16 val);
115  virtual void put_uint32(dods_uint32 val);
116  // Added
117  virtual void put_uint64(dods_uint64 val);
118 
119  virtual void put_str(const string &val);
120  virtual void put_url(const string &val);
121 
122  virtual void put_opaque(char *, unsigned int) {
123  throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4; use put_opaque_dap4() instead.");
124  }
125 
126  virtual void put_opaque_dap4(const char *val, int64_t len);
127 
128  // Never use put_int() to send length information in DAP4.
129  virtual void put_int(int) {
130  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix.");
131  }
132 
133  virtual void put_vector(char *val, int64_t num_bytes);
134  virtual void put_vector(char *val, int64_t num_elem, int elem_size);
135  virtual void put_vector_float32(char *val, int64_t num_elem);
136  virtual void put_vector_float64(char *val, int64_t num_elem);
137 
138  virtual void put_vector(char *, int , Vector &) {
139  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix.");
140  }
141  virtual void put_vector(char *, int , int , Vector &) {
142  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix.");
143  }
144 
145  virtual void dump(std::ostream &strm) const;
146 };
147 
148 } // namespace libdap
149 
150 #endif // I_D4StreamMarshaller_h
virtual void put_opaque_dap4(const char *val, int64_t len)
virtual void put_float64(dods_float64 val)
virtual void put_int16(dods_int16 val)
uint8_t dods_byte
int64_t dods_int64
virtual void put_count(int64_t count)
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:80
virtual void put_vector(char *, int, int, Vector &)
Definition: crc.h:76
virtual void put_vector(char *, int, Vector &)
virtual void put_byte(dods_byte val)
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
uint16_t dods_uint16
virtual void put_uint16(dods_uint16 val)
uint64_t dods_uint64
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's receiv...
double dods_float64
uint32_t dods_uint32
virtual void put_opaque(char *, unsigned int)
virtual void put_uint32(dods_uint32 val)
virtual void put_int8(dods_int8 val)
virtual void checksum_update(const void *data, unsigned long len)
virtual void put_uint64(dods_uint64 val)
int16_t dods_int16
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:53
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_float32(dods_float32 val)
virtual void put_int32(dods_int32 val)
virtual void put_str(const string &val)
virtual void put_int64(dods_int64 val)
virtual void put_url(const string &val)
int32_t dods_int32