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