File: D4StreamUnMarshaller.h

package info (click to toggle)
libdap 3.18.2-2%2Bdeb9u1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 18,808 kB
  • sloc: sh: 54,436; cpp: 46,087; ansic: 16,793; xml: 2,730; yacc: 2,452; exp: 1,544; makefile: 1,001; lex: 305; perl: 52; fortran: 8
file content (164 lines) | stat: -rw-r--r-- 5,220 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// D4StreamUnMarshaller.h

// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2012 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

#ifndef I_D4StreamUnMarshaller_h
#define I_D4StreamUnMarshaller_h 1

#include <iostream>

// See comment in D4StreamMarshaller
#define USE_XDR_FOR_IEEE754_ENCODING 0

#if USE_XDR_FOR_IEEE754_ENCODING
#ifdef WIN32
#include <rpc.h>
#include <winsock2.h>
#include <xdr.h>
#else
#include <rpc/types.h>
#include <netinet/in.h>
#include <rpc/xdr.h>
#endif
#endif

#include <crc.h>

// #include "Type.h"
#include "dods-datatypes.h"
#include "UnMarshaller.h"
#include "InternalErr.h"

#include "util.h"
#include "debug.h"

using std::istream;

namespace libdap {

class Vector;

/** @brief Read data from the stream made by D4StreamMarshaller.
 */
class D4StreamUnMarshaller: public UnMarshaller {
public:
    const static unsigned int c_checksum_length = 4;

private:
    istream &d_in;
    bool d_twiddle_bytes;

#if USE_XDR_FOR_IEEE754_ENCODING
    // These are used for reals that need to be converted from IEEE 754
    XDR d_source;
    char d_buf[sizeof(dods_float64)];
#endif

    D4StreamUnMarshaller();
    D4StreamUnMarshaller(const D4StreamUnMarshaller &);
    D4StreamUnMarshaller & operator=(const D4StreamUnMarshaller &);
#if USE_XDR_FOR_IEEE754_ENCODING
    void m_deserialize_reals(char *val, int64_t num, int width, Type type);
#endif
    void m_twidle_vector_elements(char *vals, int64_t num, int width);

public:
    D4StreamUnMarshaller(istream &in, bool twiddle_bytes);
    D4StreamUnMarshaller(istream &in);
    virtual ~D4StreamUnMarshaller();

    void set_twiddle_bytes(bool twiddle) { d_twiddle_bytes = twiddle; }

    /**
     * @brief Is the data source we are reading from a big-endian machine?
     * We need this because the value of the CRC32 checksum is dependent on
     * byte order.
     *
     * @note This is somewhat tortured logic, but if this host is big-endian and
     * twiddle_bytes is not true, then the remote host must be big-endian. Similarly,
     * if this host is not big-endian and twiddle_bytes is true, then the remote
     * host must be big-endian
     */
    bool is_source_big_endian() const { return (is_host_big_endian() && !d_twiddle_bytes)
                                               || (!is_host_big_endian() && d_twiddle_bytes); }

    Crc32::checksum get_checksum();
    string get_checksum_str();
    int64_t get_count();

    virtual void get_byte(dods_byte &val);
    virtual void get_int8(dods_int8 &val);

    virtual void get_int16(dods_int16 &val);
    virtual void get_int32(dods_int32 &val);

    virtual void get_int64(dods_int64 &val);

    virtual void get_float32(dods_float32 &val);
    virtual void get_float64(dods_float64 &val);

    virtual void get_uint16(dods_uint16 &val);
    virtual void get_uint32(dods_uint32 &val);

    virtual void get_uint64(dods_uint64 &val);

    virtual void get_str(string &val);
    virtual void get_url(string &val);

    virtual void get_opaque(char *, unsigned int) {
    	throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4, use get_opaque_dap4() instead.");
    }

    virtual void get_opaque_dap4(char **val, int64_t &len);
    virtual void get_opaque_dap4( vector<uint8_t> &val );

    virtual void get_int(int &) {
        throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
    }

    // Note that DAP4 assumes clients know the size of arrays when they
    // read the data; it's the 'varying' get methods that read & return the
    // number of elements. These methods are here to appease the UnMarshaller
    // 'interface' code
    virtual void get_vector(char **, unsigned int &, Vector &) {
        throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
    }

    virtual void get_vector(char **, unsigned int &, int, Vector & ) {
        throw InternalErr(__FILE__, __LINE__, "Not implemented for DAP4");
    }

    virtual void get_vector(char *val, int64_t num_bytes);
    virtual void get_vector(char *val, int64_t num_elem, int elem_size);
    virtual void get_vector_float32(char *val, int64_t num_elem);
    virtual void get_vector_float64(char *val, int64_t num_elem);

    virtual void dump(ostream &strm) const;
};

} // namespace libdap

#endif // I_D4StreamUnMarshaller_h