Hazelcast C++ Client
Serializer.h
1 /*
2  * Copyright (c) 2008-2019, 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 
51  virtual int32_t getHazelcastTypeId() const = 0;
52 
56  virtual void destroy();
57  };
58 
71  class HAZELCAST_API StreamSerializer : public SerializerBase {
72  public:
79  virtual void write(ObjectDataOutput &out, const void *object) = 0;
80 
89  virtual void *read(ObjectDataInput &in) = 0;
90  };
91 
95  template <typename T>
96  class Serializer : public StreamSerializer {
97  public:
98 
105  virtual void write(ObjectDataOutput &out, const T &object) = 0;
106 
113  virtual void read(ObjectDataInput &in, T &object) = 0;
114 
120  virtual void *read(ObjectDataInput &in) {
121  std::auto_ptr<T> object(new T);
122  read(in, *object);
123  return object.release();
124  }
125 
126  virtual void write(ObjectDataOutput &out, const void *object) {
127  write(out, *(static_cast<const T *>(object)));
128  }
129  };
130 
131  }
132  }
133 }
134 
135 
136 #endif //HAZELCAST_TYPE_SERIALIZER
137 
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:126
virtual void * read(ObjectDataInput &in)
This is an internal method for backward compatibility.
Definition: Serializer.h:120
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:53
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:71
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
Implement this interface and register to the SerializationConfig.
Definition: Serializer.h:71