Hazelcast C++ Client
PortableWriter.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 #ifndef HAZELCAST_PortableWriter
20 #define HAZELCAST_PortableWriter
21 
22 #include "hazelcast/client/serialization/pimpl/DefaultPortableWriter.h"
23 #include "hazelcast/client/serialization/pimpl/ClassDefinitionWriter.h"
24 
25 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
26 #pragma warning(push)
27 #pragma warning(disable: 4251) //for dll export
28 #endif
29 
30 namespace hazelcast {
31  namespace client {
32  namespace serialization {
33 
38  class HAZELCAST_API PortableWriter {
39  public:
43  PortableWriter(pimpl::DefaultPortableWriter *defaultPortableWriter);
44 
48  PortableWriter(pimpl::ClassDefinitionWriter *classDefinitionWriter);
49 
55  void writeInt(const char *fieldName, int32_t value);
56 
62  void writeLong(const char *fieldName, int64_t value);
63 
69  void writeBoolean(const char *fieldName, bool value);
70 
76  void writeByte(const char *fieldName, byte value);
77 
83  void writeChar(const char *fieldName, int32_t value);
84 
90  void writeDouble(const char *fieldName, double value);
91 
97  void writeFloat(const char *fieldName, float value);
98 
104  void writeShort(const char *fieldName, int16_t value);
105 
111  void writeUTF(const char *fieldName, const std::string *value);
112 
118  void writeByteArray(const char *fieldName, const std::vector<byte> *values);
119 
125  void writeBooleanArray(const char *fieldName, const std::vector<bool> *values);
126 
132  void writeCharArray(const char *fieldName, const std::vector<char> *values);
133 
139  void writeShortArray(const char *fieldName, const std::vector<int16_t> *values);
140 
146  void writeIntArray(const char *fieldName, const std::vector<int32_t> *values);
147 
153  void writeLongArray(const char *fieldName, const std::vector<int64_t> *values);
154 
160  void writeFloatArray(const char *fieldName, const std::vector<float> *values);
161 
167  void writeDoubleArray(const char *fieldName, const std::vector<double> *values);
168 
172  void end();
173 
182  template<typename T>
183  void writeNullPortable(const char *fieldName) {
184  if (isDefaultWriter)
185  return defaultPortableWriter->writeNullPortable<T>(fieldName);
186  return classDefinitionWriter->writeNullPortable<T>(fieldName);
187  }
188 
195  template<typename T>
196  void writePortable(const char *fieldName, const T *portable) {
197  if (isDefaultWriter)
198  return defaultPortableWriter->writePortable(fieldName, portable);
199  return classDefinitionWriter->writePortable(fieldName, portable);
200 
201  };
202 
209  template<typename T>
210  void writePortableArray(const char *fieldName, const std::vector<T> *values) {
211  if (isDefaultWriter)
212  return defaultPortableWriter->writePortableArray(fieldName, values);
213  return classDefinitionWriter->writePortableArray(fieldName, values);
214  };
215 
224  ObjectDataOutput &getRawDataOutput();
225 
226  private:
227  pimpl::DefaultPortableWriter *defaultPortableWriter;
228  pimpl::ClassDefinitionWriter *classDefinitionWriter;
229  bool isDefaultWriter;
230  };
231  }
232  }
233 }
234 
235 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
236 #pragma warning(pop)
237 #endif
238 
239 #endif //HAZELCAST_PortableWriter
240 
void writePortableArray(const char *fieldName, const std::vector< T > *values)
Definition: PortableWriter.h:210
void writePortable(const char *fieldName, const T *portable)
Definition: PortableWriter.h:196
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:54
void writeNullPortable(const char *fieldName)
To write a null portable value.
Definition: PortableWriter.h:183
Definition: MapEntryView.h:32
Provides a mean of writing portable fields to a binary in form of java primitives arrays of java prim...
Definition: PortableWriter.h:38