libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4StreamUnMarshaller.h
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 "util.h"
55#include "debug.h"
56
57using std::istream;
58
59namespace libdap {
60
61class Vector;
62
66public:
67 const static unsigned int c_checksum_length = 4;
68
69private:
70 istream &d_in;
71 bool d_twiddle_bytes;
72
73#if USE_XDR_FOR_IEEE754_ENCODING
74 // These are used for reals that need to be converted from IEEE 754
75 XDR d_source;
76 char d_buf[sizeof(dods_float64)];
77#endif
78
81 D4StreamUnMarshaller & operator=(const D4StreamUnMarshaller &);
82#if USE_XDR_FOR_IEEE754_ENCODING
83 void m_deserialize_reals(char *val, int64_t num, int width, Type type);
84#endif
85 void m_twidle_vector_elements(char *vals, int64_t num, int width);
86
87public:
88 D4StreamUnMarshaller(istream &in, bool twiddle_bytes);
89 D4StreamUnMarshaller(istream &in);
90 virtual ~D4StreamUnMarshaller();
91
92 void set_twiddle_bytes(bool twiddle) { d_twiddle_bytes = twiddle; }
93
104 bool is_source_big_endian() const { return (is_host_big_endian() && !d_twiddle_bytes)
105 || (!is_host_big_endian() && d_twiddle_bytes); }
106
107 Crc32::checksum get_checksum();
108 string get_checksum_str();
109 int64_t get_count();
110
111 virtual void get_byte(dods_byte &val);
112 virtual void get_int8(dods_int8 &val);
113
114 virtual void get_int16(dods_int16 &val);
115 virtual void get_int32(dods_int32 &val);
116
117 virtual void get_int64(dods_int64 &val);
118
119 virtual void get_float32(dods_float32 &val);
120 virtual void get_float64(dods_float64 &val);
121
122 virtual void get_uint16(dods_uint16 &val);
123 virtual void get_uint32(dods_uint32 &val);
124
125 virtual void get_uint64(dods_uint64 &val);
126
127 virtual void get_str(string &val);
128 virtual void get_url(string &val);
129
130 virtual void get_opaque(char *, unsigned int) {
131 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4, use get_opaque_dap4() instead.");
132 }
133
134 virtual void get_opaque_dap4(char **val, int64_t &len);
135 virtual void get_opaque_dap4( vector<uint8_t> &val );
136
137 virtual void get_int(int &) {
138 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
139 }
140
141 // Note that DAP4 assumes clients know the size of arrays when they
142 // read the data; it's the 'varying' get methods that read & return the
143 // number of elements. These methods are here to appease the UnMarshaller
144 // 'interface' code
145 virtual void get_vector(char **, unsigned int &, Vector &) {
146 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
147 }
148
149 virtual void get_vector(char **, unsigned int &, int, Vector & ) {
150 throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
151 }
152
153 virtual void get_vector(char *val, int64_t num_bytes);
154 virtual void get_vector(char *val, int64_t num_elem, int elem_size);
155 virtual void get_vector_float32(char *val, int64_t num_elem);
156 virtual void get_vector_float64(char *val, int64_t num_elem);
157
158 virtual void dump(ostream &strm) const;
159};
160
161} // namespace libdap
162
163#endif // I_D4StreamUnMarshaller_h
164
Read data from the stream made by D4StreamMarshaller.
bool is_source_big_endian() const
Is the data source we are reading from a big-endian machine? We need this because the value of the CR...
virtual void get_opaque_dap4(char **val, int64_t &len)
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
A class for software fault reporting.
Definition: InternalErr.h:65
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:55
top level DAP object to house generic methods
Definition: AlarmHandler.h:36
Type
Identifies the data type.
Definition: Type.h:94
bool is_host_big_endian()
Does this host use big-endian byte order?
Definition: util.cc:94