Hazelcast C++ Client
PortableReader.h
1 /*
2  * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 //
17 // Created by sancar koyunlu on 8/10/13.
18 
19 
20 
21 
22 
23 #ifndef HAZELCAST_PortableReader
24 #define HAZELCAST_PortableReader
25 
26 #include "hazelcast/util/HazelcastDll.h"
27 #include "hazelcast/client/serialization/pimpl/DefaultPortableReader.h"
28 #include "hazelcast/client/serialization/pimpl/MorphingPortableReader.h"
29 #include <memory>
30 
31 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
32 #pragma warning(push)
33 #pragma warning(disable: 4251) //for dll export
34 #endif
35 
36 namespace hazelcast {
37  namespace client {
38  namespace serialization {
39  namespace pimpl {
40 
41  class PortableContext;
42 
43  class DataInput;
44  }
45 
46  class ClassDefinition;
47 
52  class HAZELCAST_API PortableReader {
53  public:
54 
58  PortableReader(pimpl::PortableContext& context, ObjectDataInput& dataInput,
59  boost::shared_ptr<ClassDefinition> cd, bool isDefaultReader);
60 
61  PortableReader(const PortableReader & reader);
62 
63  PortableReader &operator = (const PortableReader & reader);
64 
70  int32_t readInt(const char *fieldName);
71 
77  int64_t readLong(const char *fieldName);
78 
84  bool readBoolean(const char *fieldName);
85 
91  byte readByte(const char *fieldName);
92 
98  char readChar(const char *fieldName);
99 
105  double readDouble(const char *fieldName);
106 
112  float readFloat(const char *fieldName);
113 
119  int16_t readShort(const char *fieldName);
120 
126  std::auto_ptr<std::string> readUTF(const char *fieldName);
127 
133  std::auto_ptr<std::vector<byte> > readByteArray(const char *fieldName);
134 
140  std::auto_ptr<std::vector<bool> > readBooleanArray(const char *fieldName);
141 
147  std::auto_ptr<std::vector<char> > readCharArray(const char *fieldName);
148 
154  std::auto_ptr<std::vector<int32_t> > readIntArray(const char *fieldName);
155 
161  std::auto_ptr<std::vector<int64_t> > readLongArray(const char *fieldName);
162 
168  std::auto_ptr<std::vector<double> > readDoubleArray(const char *fieldName);
169 
175  std::auto_ptr<std::vector<float> > readFloatArray(const char *fieldName);
176 
182  std::auto_ptr<std::vector<int16_t> > readShortArray(const char *fieldName);
183 
190  template<typename T>
191  boost::shared_ptr<T> readPortable(const char *fieldName) {
192  if (isDefaultReader)
193  return defaultPortableReader->readPortable<T>(fieldName);
194  return morphingPortableReader->readPortable<T>(fieldName);
195  };
196 
203  template<typename T>
204  std::vector<T> readPortableArray(const char *fieldName) {
205  if (isDefaultReader)
206  return defaultPortableReader->readPortableArray<T>(fieldName);
207  return morphingPortableReader->readPortableArray<T>(fieldName);
208  };
209 
219  ObjectDataInput& getRawDataInput();
220 
224  void end();
225 
226  private:
227  bool isDefaultReader;
228  mutable std::auto_ptr<pimpl::DefaultPortableReader> defaultPortableReader;
229  mutable std::auto_ptr<pimpl::MorphingPortableReader> morphingPortableReader;
230 
231  };
232  }
233  }
234 }
235 
236 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
237 #pragma warning(pop)
238 #endif
239 
240 #endif //HAZELCAST_PortableReader
241 
std::vector< T > readPortableArray(const char *fieldName)
Definition: PortableReader.h:204
Provides a mean of reading portable fields from a binary in form of java primitives arrays of java pr...
Definition: PortableReader.h:52
boost::shared_ptr< T > readPortable(const char *fieldName)
Definition: PortableReader.h:191
Provides deserialization methods for primitives types, arrays of primitive types Portable, IdentifiedDataSerializable and custom serializable types.
Definition: ObjectDataInput.h:70
Definition: MapEntryView.h:32