23 #ifndef HAZELCAST_ObjectDataOutput
24 #define HAZELCAST_ObjectDataOutput
27 #include "hazelcast/client/serialization/pimpl/SerializationConstants.h"
28 #include "hazelcast/client/exception/HazelcastSerializationException.h"
29 #include "hazelcast/client/serialization/pimpl/SerializerHolder.h"
30 #include "hazelcast/client/serialization/pimpl/PortableContext.h"
31 #include "hazelcast/client/serialization/Serializer.h"
32 #include "hazelcast/util/IOUtil.h"
34 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
36 #pragma warning(disable: 4251) //for dll export
41 namespace serialization {
58 ObjectDataOutput(pimpl::DataOutput& dataOutput, pimpl::PortableContext& portableContext);
68 std::auto_ptr<std::vector<byte> > toByteArray();
74 void write(
const std::vector<byte>& bytes);
79 void writeBoolean(
bool value);
84 void writeByte(
int value);
89 void writeShort(
int value);
94 void writeChar(
int value);
99 void writeInt(
int value);
104 void writeLong(
long value);
109 void writeFloat(
float value);
114 void writeDouble(
double value);
119 void writeUTF(
const std::string *value);
124 void writeByteArray(
const std::vector<byte> *value);
129 void writeCharArray(
const std::vector<char> *value);
134 void writeShortArray(
const std::vector<short> *value);
139 void writeIntArray(
const std::vector<int> *value);
144 void writeLongArray(
const std::vector<long> *value);
149 void writeFloatArray(
const std::vector<float> *value);
154 void writeDoubleArray(
const std::vector<double> *value);
159 void writeUTFArray(
const std::vector<std::string *> *strings);
164 void writeData(
const pimpl::Data *value);
171 template <
typename T>
175 if (NULL ==
object) {
176 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
178 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_PORTABLE);
183 context->getSerializerHolder().getPortableSerializer().write(*this->dataOutput, *
object);
196 if (NULL ==
object) {
197 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
199 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_DATA);
200 context->getSerializerHolder().getDataSerializer().write(*
this, *
object);
209 template <
typename T>
213 if (NULL == serializable) {
214 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
216 const T *
object =
static_cast<const T *
>(serializable);
217 int type =
object->getTypeId();
220 boost::shared_ptr<SerializerBase> serializer = context->getSerializerHolder().serializerFor(type);
222 if (NULL == serializer.get()) {
223 const std::string message =
"No serializer found for serializerId :"+
224 util::IOUtil::to_string(type) +
", typename :" +
231 s->
write(*
this, *
object);
235 pimpl::DataOutput *dataOutput;
236 pimpl::PortableContext *context;
237 pimpl::SerializerHolder *serializerHolder;
242 void position(
size_t newPos);
252 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
256 #endif //HAZELCAST_ObjectDataOutput
virtual int getClassId() const =0
Raised when an error occur during serialization or deserialization in Hazelcast.
Definition: HazelcastSerializationException.h:33
Base class for custom serialization.
Definition: Serializer.h:102
void writeObject(const Portable *object)
Definition: ObjectDataOutput.h:172
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:53
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:42
void writeObject(const void *serializable)
Definition: ObjectDataOutput.h:210
virtual void write(ObjectDataOutput &out, const Serializable &object)=0
This method writes object to ObjectDataOutput.
virtual int getFactoryId() const =0
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: Portable.h:52
void writeObject(const IdentifiedDataSerializable *object)
Definition: ObjectDataOutput.h:193