libdap++  Updated for version 3.14.0
D4StreamUnMarshaller.h
Go to the documentation of this file.
1 // D4StreamUnMarshaller.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) 2012 OPeNDAP, Inc.
9 // Author: James Gallagher <jgallagher@opendap.org>
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 //
25 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26 
27 #ifndef I_D4StreamUnMarshaller_h
28 #define I_D4StreamUnMarshaller_h 1
29 
30 #include <iostream>
31 
32 // See comment in D4StreamMarshaller
33 #define USE_XDR_FOR_IEEE754_ENCODING 0
34 
35 #if USE_XDR_FOR_IEEE754_ENCODING
36 #ifdef WIN32
37 #include <rpc.h>
38 #include <winsock2.h>
39 #include <xdr.h>
40 #else
41 #include <rpc/types.h>
42 #include <netinet/in.h>
43 #include <rpc/xdr.h>
44 #endif
45 #endif
46 
47 #include <crc.h>
48 
49 // #include "Type.h"
50 #include "dods-datatypes.h"
51 #include "UnMarshaller.h"
52 #include "InternalErr.h"
53 
54 #include "debug.h"
55 
56 using std::istream;
57 
58 namespace libdap {
59 
60 class Vector;
61 
65 public:
66  const static unsigned int c_checksum_length = 4;
67 
68 private:
69  istream &d_in;
70  bool d_twiddle_bytes;
71 
72 #if USE_XDR_FOR_IEEE754_ENCODING
73  // These are used for reals that need to be converted from IEEE 754
74  XDR d_source;
75  char d_buf[sizeof(dods_float64)];
76 #endif
77 
80  D4StreamUnMarshaller & operator=(const D4StreamUnMarshaller &);
81 #if USE_XDR_FOR_IEEE754_ENCODING
82  void m_deserialize_reals(char *val, int64_t num, int width, Type type);
83 #endif
84  void m_twidle_vector_elements(char *vals, int64_t num, int width);
85 
86 public:
87  D4StreamUnMarshaller(istream &in, bool twiddle_bytes);
88  D4StreamUnMarshaller(istream &in);
89  virtual ~D4StreamUnMarshaller();
90 
91  void set_twiddle_bytes(bool twiddle) { d_twiddle_bytes = twiddle; }
92 
94  string get_checksum_str();
95  int64_t get_count();
96 
97  virtual void get_byte(dods_byte &val);
98  virtual void get_int8(dods_int8 &val);
99 
100  virtual void get_int16(dods_int16 &val);
101  virtual void get_int32(dods_int32 &val);
102 
103  virtual void get_int64(dods_int64 &val);
104 
105  virtual void get_float32(dods_float32 &val);
106  virtual void get_float64(dods_float64 &val);
107 
108  virtual void get_uint16(dods_uint16 &val);
109  virtual void get_uint32(dods_uint32 &val);
110 
111  virtual void get_uint64(dods_uint64 &val);
112 
113  virtual void get_str(string &val);
114  virtual void get_url(string &val);
115 
116  virtual void get_opaque(char *, unsigned int) {
117  throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4, use get_opaque_dap4() instead.");
118  }
119 
120  virtual void get_opaque_dap4(char **val, int64_t &len);
121  virtual void get_opaque_dap4( vector<uint8_t> &val );
122 
123  virtual void get_int(int &) {
124  throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
125  }
126 
127  // Note that DAP4 assumes clients know the size of arrays when they
128  // read the data; it's the 'varying' get methods that read & return the
129  // number of elements. These methods are here to appease the UnMarshaller
130  // 'interface' code
131  virtual void get_vector(char **, unsigned int &, Vector &) {
132  throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
133  }
134 
135  virtual void get_vector(char **, unsigned int &, int, Vector & ) {
136  throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
137  }
138 
139  virtual void get_vector(char *val, int64_t num_bytes);
140  virtual void get_vector(char *val, int64_t num_elem, int elem_size);
141  virtual void get_vector_float32(char *val, int64_t num_elem);
142  virtual void get_vector_float64(char *val, int64_t num_elem);
143 
144  virtual void dump(ostream &strm) const;
145 };
146 
147 } // namespace libdap
148 
149 #endif // I_D4StreamUnMarshaller_h
150 
virtual void get_vector(char **, unsigned int &, int, Vector &)
virtual void get_float32(dods_float32 &val)
void set_twiddle_bytes(bool twiddle)
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:54
uint8_t dods_byte
int64_t dods_int64
virtual void get_int32(dods_int32 &val)
Holds a one-dimensional collection of DAP2 data types.
Definition: Vector.h:80
virtual void get_vector_float32(char *val, int64_t num_elem)
virtual void get_uint64(dods_uint64 &val)
virtual void get_int8(dods_int8 &val)
virtual void get_byte(dods_byte &val)
Read data from the stream made by D4StreamMarshaller.
virtual void get_int64(dods_int64 &val)
virtual void get_opaque(char *, unsigned int)
virtual void get_str(string &val)
Type
Identifies the data type.
Definition: Type.h:94
uint16_t dods_uint16
uint32_t checksum
Definition: crc.h:79
uint64_t dods_uint64
virtual void get_opaque_dap4(char **val, int64_t &len)
A class for software fault reporting.
Definition: InternalErr.h:64
double dods_float64
virtual void get_uint16(dods_uint16 &val)
uint32_t dods_uint32
static const unsigned int c_checksum_length
virtual void get_int16(dods_int16 &val)
virtual void get_vector_float64(char *val, int64_t num_elem)
int16_t dods_int16
virtual void get_uint32(dods_uint32 &val)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void get_url(string &val)
virtual void get_float64(dods_float64 &val)
virtual void get_vector(char **, unsigned int &, Vector &)
int32_t dods_int32