Hazelcast C++ Client
Serializer.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 6/7/13.
18 
19 #ifndef HAZELCAST_TYPE_SERIALIZER
20 #define HAZELCAST_TYPE_SERIALIZER
21 
22 #include <stdint.h>
23 #include <memory>
24 
25 #include "hazelcast/util/HazelcastDll.h"
26 
27 namespace hazelcast {
28  namespace client {
29  namespace serialization {
30  class ObjectDataOutput;
31 
32  class ObjectDataInput;
33 
37  class HAZELCAST_API SerializerBase {
38  public:
39  virtual ~SerializerBase();
40 
50  virtual int32_t getHazelcastTypeId() const = 0;
51  };
52 
64  class HAZELCAST_API StreamSerializer : public SerializerBase {
65  public:
72  virtual void write(ObjectDataOutput &out, const void *object) = 0;
73 
82  virtual void *read(ObjectDataInput &in) = 0;
83  };
84 
88  template <typename T>
89  class Serializer : public StreamSerializer {
90  public:
91 
98  virtual void write(ObjectDataOutput &out, const T &object) = 0;
99 
106  virtual void read(ObjectDataInput &in, T &object) = 0;
107 
113  virtual void *read(ObjectDataInput &in) {
114  std::auto_ptr<T> object(new T);
115  read(in, *object);
116  return object.release();
117  }
118 
119  virtual void write(ObjectDataOutput &out, const void *object) {
120  write(out, *(static_cast<const T *>(object)));
121  }
122  };
123 
124  }
125  }
126 }
127 
128 
129 #endif //HAZELCAST_TYPE_SERIALIZER
130 
This is an internal class !!!! Do not use.
Definition: Serializer.h:37
virtual void write(ObjectDataOutput &out, const void *object)
This method writes object to ObjectDataOutput.
Definition: Serializer.h:119
virtual void * read(ObjectDataInput &in)
This is an internal method for backward compatibility.
Definition: Serializer.h:113
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:54
virtual void read(ObjectDataInput &in, T &object)=0
Reads object from objectDataInputStream.
virtual void write(ObjectDataOutput &out, const T &object)=0
This method writes object to ObjectDataOutput.
Provides deserialization methods for primitives types, arrays of primitive types Portable, IdentifiedDataSerializable and custom serializable types.
Definition: ObjectDataInput.h:70
Definition: MapEntryView.h:32
Implement this interface and register to the SerializationConfig.
Definition: Serializer.h:64