bes  Updated for version 3.20.6
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 #ifdef HAVE_PTHREAD_H
28 #include <pthread.h>
29 #endif
30 
31 #include <cassert>
32 
33 #include <iostream>
34 #include <sstream>
35 #include <iomanip>
36 
37 #include <Vector.h>
38 
39 #include "BESIndent.h"
40 #include "CacheMarshaller.h"
41 
42 using namespace std;
43 using namespace libdap;
44 
45 // Build this code so it does not use pthreads to write some kinds of
46 // data (see the put_vector() and put_vector_part() methods) in a child thread.
47 // #undef USE_POSIX_THREADS
48 
49 // namespace bes {
50 
51 void CacheMarshaller::put_byte(dods_byte val)
52 {
53  d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
54 }
55 
56 void CacheMarshaller::put_int16(dods_int16 val)
57 {
58  d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
59 }
60 
61 void CacheMarshaller::put_int32(dods_int32 val)
62 {
63  d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
64 }
65 
66 void CacheMarshaller::put_float32(dods_float32 val)
67 {
68  d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
69 }
70 
71 void CacheMarshaller::put_float64(dods_float64 val)
72 {
73  d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
74 }
75 
76 void CacheMarshaller::put_uint16(dods_uint16 val)
77 {
78  d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
79 }
80 
81 void CacheMarshaller::put_uint32(dods_uint32 val)
82 {
83  d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
84 }
85 
86 void CacheMarshaller::put_str(const string &val)
87 {
88  size_t len = val.length();
89  d_out.write(reinterpret_cast<const char*>(&len), sizeof(size_t));
90  d_out.write(val.data(), val.length());
91 }
92 
93 void CacheMarshaller::put_url(const string &val)
94 {
95  put_str(val);
96 }
97 
98 void CacheMarshaller::put_opaque(char *val, unsigned int len)
99 {
100  d_out.write(val, len);
101 }
102 
103 void CacheMarshaller::put_int(int val)
104 {
105  d_out.write(reinterpret_cast<char*>(&val), sizeof(val));
106 }
107 
108 void CacheMarshaller::put_vector(char *val, int num, int width, Vector &vec)
109 {
110  put_vector(val, num, width, vec.var()->type());
111 }
112 
113 
122 {
123  put_int(num);
124 }
125 
133 {
134 }
135 
136 // Start of parallel I/O support. jhrg 8/19/15
137 void CacheMarshaller::put_vector(char *val, int num, Vector &)
138 {
139  assert(val || num == 0);
140 
141  // write the number of array members being written, then set the position back to 0
142  put_int(num);
143 
144  if (num == 0)
145  return;
146 
147  d_out.write(val, num);
148 }
149 
150 // private
161 void CacheMarshaller::put_vector(char *val, unsigned int num, int width, Type)
162 {
163  assert(val || num == 0);
164 
165  // write the number of array members being written, then set the position back to 0
166  put_int(num);
167 
168  if (num == 0)
169  return;
170 
171  d_out.write(val, num * width);
172 }
173 
185 void CacheMarshaller::put_vector_part(char *val, unsigned int num, int width, Type )
186 {
187  d_out.write(val, num * width);
188 }
189 
190 void CacheMarshaller::dump(ostream &strm) const
191 {
192  strm << BESIndent::LMarg << "CacheMarshaller::dump - (" << (void *) this << ")" << endl;
193 }
194 
195 //} // namespace bes
196 
CacheMarshaller::put_vector_end
virtual void put_vector_end()
Definition: CacheMarshaller.cc:132
CacheMarshaller::put_vector_part
virtual void put_vector_part(char *val, unsigned int num, int width, libdap::Type)
Definition: CacheMarshaller.cc:185
Type
Type
Type of JSON value.
Definition: cmr_module/rapidjson/rapidjson.h:603
libdap
Definition: BESDapFunctionResponseCache.h:35
CacheMarshaller::put_vector_start
virtual void put_vector_start(int num)
Definition: CacheMarshaller.cc:121