Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
PortableWriter.h
1 /*
2  * Copyright (c) 2008-2015, 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_PortableWriter
24 #define HAZELCAST_PortableWriter
25 
26 #include "hazelcast/client/serialization/pimpl/DefaultPortableWriter.h"
27 #include "hazelcast/client/serialization/pimpl/ClassDefinitionWriter.h"
28 
29 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
30 #pragma warning(push)
31 #pragma warning(disable: 4251) //for dll export
32 #endif
33 
34 namespace hazelcast {
35  namespace client {
36  namespace serialization {
37 
42  class HAZELCAST_API PortableWriter {
43  public:
47  PortableWriter(pimpl::DefaultPortableWriter *defaultPortableWriter);
48 
52  PortableWriter(pimpl::ClassDefinitionWriter *classDefinitionWriter);
53 
59  void writeInt(const char *fieldName, int value);
60 
66  void writeLong(const char *fieldName, long value);
67 
73  void writeBoolean(const char *fieldName, bool value);
74 
80  void writeByte(const char *fieldName, byte value);
81 
87  void writeChar(const char *fieldName, int value);
88 
94  void writeDouble(const char *fieldName, double value);
95 
101  void writeFloat(const char *fieldName, float value);
102 
108  void writeShort(const char *fieldName, short value);
109 
115  void writeUTF(const char *fieldName, const std::string *value);
116 
122  void writeByteArray(const char *fieldName, const std::vector<byte> *values);
123 
129  void writeCharArray(const char *fieldName, const std::vector<char> *values);
130 
136  void writeShortArray(const char *fieldName, const std::vector<short> *values);
137 
143  void writeIntArray(const char *fieldName, const std::vector<int> *values);
144 
150  void writeLongArray(const char *fieldName, const std::vector<long> *values);
151 
157  void writeFloatArray(const char *fieldName, const std::vector<float> *values);
158 
164  void writeDoubleArray(const char *fieldName, const std::vector<double> *values);
165 
169  void end();
170 
179  template<typename T>
180  void writeNullPortable(const char *fieldName) {
181  if (isDefaultWriter)
182  return defaultPortableWriter->writeNullPortable<T>(fieldName);
183  return classDefinitionWriter->writeNullPortable<T>(fieldName);
184  }
185 
192  template<typename T>
193  void writePortable(const char *fieldName, const T *portable) {
194  if (isDefaultWriter)
195  return defaultPortableWriter->writePortable(fieldName, portable);
196  return classDefinitionWriter->writePortable(fieldName, portable);
197 
198  };
199 
206  template<typename T>
207  void writePortableArray(const char *fieldName, const std::vector<T> *values) {
208  if (isDefaultWriter)
209  return defaultPortableWriter->writePortableArray(fieldName, values);
210  return classDefinitionWriter->writePortableArray(fieldName, values);
211  };
212 
221  ObjectDataOutput &getRawDataOutput();
222 
223  private:
224  pimpl::DefaultPortableWriter *defaultPortableWriter;
225  pimpl::ClassDefinitionWriter *classDefinitionWriter;
226  bool isDefaultWriter;
227  };
228  }
229  }
230 }
231 
232 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
233 #pragma warning(pop)
234 #endif
235 
236 #endif //HAZELCAST_PortableWriter
237 
void writePortableArray(const char *fieldName, const std::vector< T > *values)
Definition: PortableWriter.h:207
void writePortable(const char *fieldName, const T *portable)
Definition: PortableWriter.h:193
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:53
void writeNullPortable(const char *fieldName)
To write a null portable value.
Definition: PortableWriter.h:180
Provides a mean of writing portable fields to a binary in form of java primitives arrays of java prim...
Definition: PortableWriter.h:42