bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
CacheMarshaller.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of Hyrax, A C++ implementation of the OPeNDAP Data
4// Access Protocol.
5
6// Copyright (c) 2016 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include "config.h"
26
27#include <cassert>
28
29#include <iostream>
30#include <sstream>
31
32#include <libdap/Vector.h>
33
34#include "BESIndent.h"
35#include "CacheMarshaller.h"
36
37using namespace std;
38using namespace libdap;
39
40// Build this code so it does not use pthreads to write some kinds of
41// data (see the put_vector() and put_vector_part() methods) in a child thread.
42// #undef USE_POSIX_THREADS
43
44// namespace bes {
45
46void CacheMarshaller::put_byte(dods_byte val)
47{
48 d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
49}
50
51void CacheMarshaller::put_int16(dods_int16 val)
52{
53 d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
54}
55
56void CacheMarshaller::put_int32(dods_int32 val)
57{
58 d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
59}
60
61void CacheMarshaller::put_float32(dods_float32 val)
62{
63 d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
64}
65
66void CacheMarshaller::put_float64(dods_float64 val)
67{
68 d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
69}
70
71void CacheMarshaller::put_uint16(dods_uint16 val)
72{
73 d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
74}
75
76void CacheMarshaller::put_uint32(dods_uint32 val)
77{
78 d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
79}
80
81void CacheMarshaller::put_str(const string &val)
82{
83 size_t len = val.size();
84 d_out.write(reinterpret_cast<const char*>(&len), sizeof(size_t));
85 d_out.write(val.data(), val.size());
86}
87
88void CacheMarshaller::put_url(const string &val)
89{
90 put_str(val);
91}
92
93void CacheMarshaller::put_opaque(char *val, unsigned int len)
94{
95 d_out.write(val, len);
96}
97
98void CacheMarshaller::put_int(int val)
99{
100 d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
101}
102
103void CacheMarshaller::put_vector(char *val, int num, int width, Vector &vec)
104{
105 put_vector(val, num, width, vec.var()->type());
106}
107
108
117{
118 put_int(num);
119}
120
130
131// Start of parallel I/O support. jhrg 8/19/15
132void CacheMarshaller::put_vector(char *val, int num, Vector &)
133{
134 assert(val || num == 0);
135
136 // write the number of array members being written, then set the position back to 0
137 put_int(num);
138
139 if (num == 0)
140 return;
141
142 d_out.write(val, num);
143}
144
145// private
156void CacheMarshaller::put_vector(char *val, unsigned int num, int width, Type)
157{
158 assert(val || num == 0);
159
160 // write the number of array members being written, then set the position back to 0
161 put_int(num);
162
163 if (num == 0)
164 return;
165
166 d_out.write(val, num * width);
167}
168
180void CacheMarshaller::put_vector_part(char *val, unsigned int num, int width, Type )
181{
182 d_out.write(val, num * width);
183}
184
185void CacheMarshaller::dump(ostream &strm) const
186{
187 strm << BESIndent::LMarg << "CacheMarshaller::dump - (" << (void *) this << ")" << endl;
188}
189
190//} // namespace bes
191
virtual void put_vector_part(char *val, unsigned int num, int width, libdap::Type)
virtual void put_vector_end()
virtual void put_vector_start(int num)
Type
Type of JSON value.
Definition rapidjson.h:664