libdap++  Updated for version 3.13.1
DAP4StreamMarshaller.h
Go to the documentation of this file.
1 // DAP4StreamMarshaller.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 //
26 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
27 
28 #ifndef I_DAP4StreamMarshaller_h
29 #define I_DAP4StreamMarshaller_h 1
30 
31 #include <iostream>
32 
33 #include <openssl/evp.h>
34 
35 using std::ostream;
36 using std::cout;
37 
38 #include "Marshaller.h"
39 #include "XDRUtils.h"
40 
41 namespace libdap {
42 
43 class Vector;
44 
60 public:
61  const static unsigned int c_md5_length = 16;
62 
63 private:
64  XDR d_scalar_sink;
65  char * d_ieee754_buf; // used to serialize a float or double
66 
67  ostream & d_out;
68 
69  EVP_MD_CTX * d_ctx; // jhrg 4/24/12
70  bool d_write_data; // jhrg 1/27/12
71  bool d_checksum_ctx_valid;
72  unsigned char d_md[c_md5_length];
73 
74  // These are private so they won't ever get used.
75 
76  DAP4StreamMarshaller() : d_out(cout) {
77  throw InternalErr( __FILE__, __LINE__, "not implemented." ) ;
78  }
79  DAP4StreamMarshaller(const DAP4StreamMarshaller &) : Marshaller(), d_out(cout) {
80  throw InternalErr( __FILE__, __LINE__, "not implemented." ) ;
81  }
82  DAP4StreamMarshaller & operator=(const DAP4StreamMarshaller &) {
83  throw InternalErr( __FILE__, __LINE__, "not implemented." ) ;
84  }
85 
86  void m_serialize_reals(char *val, unsigned int num, int width, Type type);
87  void m_compute_checksum();
88 
89 public:
90  DAP4StreamMarshaller(ostream &out, bool write_data = true);
91  virtual ~DAP4StreamMarshaller();
92 
93  // Added here
94  virtual bool checksums() const {
95  return d_ctx != 0;
96  }
97  virtual string get_endian() const;
98  virtual void reset_checksum();
99  virtual string get_checksum();
100  virtual void checksum_update(const void *data, unsigned long len);
101  void put_checksum();
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 *val, unsigned int len);
123 
124  // Never use put_int() to send length information in DAP4, use
125  // put_length_prefix() instead.
126  virtual void put_int(int) {
127  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix.");
128  }
129 
130  // Added; This method does not add its argument to the checksum;
131  // put_uint64() does.
132  //virtual void put_length_prefix( dods_uint32 val ) ;
133  virtual void put_length_prefix(dods_uint64 val);
134 
135  virtual void put_vector(char *val, unsigned int num);
136  virtual void put_vector(char *val, unsigned int num, int width, Type type);
137 
138  virtual void put_varying_vector(char *val, unsigned int num);
139  virtual void put_varying_vector(char *val, unsigned int num, int width, Type type);
140 
141  virtual void put_vector(char *, int , Vector &) {
142  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix.");
143  }
144  virtual void put_vector(char *, int , int , Vector &) {
145  throw InternalErr(__FILE__, __LINE__, "Not Implemented; use put_length_prefix.");
146  }
147 
148 
149  virtual void dump(ostream &strm) const;
150 };
151 
152 } // namespace libdap
153 
154 #endif // I_DAP4StreamMarshaller_h
virtual void put_uint16(dods_uint16 val)
uint8_t dods_byte
static const unsigned int c_md5_length
int64_t dods_int64
virtual bool checksums() const
virtual void put_vector(char *, int, int, Vector &)
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:78
virtual void put_varying_vector(char *val, unsigned int num)
virtual void put_float64(dods_float64 val)
virtual void put_float32(dods_float32 val)
virtual void put_vector(char *val, unsigned int num)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void put_opaque(char *val, unsigned int len)
Type
Identifies the data type.
Definition: BaseType.h:137
uint16_t dods_uint16
uint64_t dods_uint64
virtual string get_endian() const
A class for software fault reporting.
Definition: InternalErr.h:64
virtual void put_int32(dods_int32 val)
double dods_float64
virtual void checksum_update(const void *data, unsigned long len)
virtual void put_int16(dods_int16 val)
uint32_t dods_uint32
virtual void put_int8(dods_int8 val)
virtual void put_byte(dods_byte val)
virtual void put_url(const string &val)
virtual void put_uint64(dods_uint64 val)
int16_t dods_int16
virtual void put_uint32(dods_uint32 val)
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:53
virtual void put_vector(char *, int, Vector &)
virtual void put_str(const string &val)
virtual void put_int64(dods_int64 val)
Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4&#39;s receiv...
virtual void put_length_prefix(dods_uint64 val)
int32_t dods_int32