19 #ifndef HAZELCAST_ObjectDataOutput
20 #define HAZELCAST_ObjectDataOutput
22 #include "hazelcast/client/serialization/pimpl/SerializationConstants.h"
23 #include "hazelcast/client/exception/HazelcastSerializationException.h"
24 #include "hazelcast/client/serialization/pimpl/SerializerHolder.h"
25 #include "hazelcast/client/serialization/pimpl/PortableContext.h"
26 #include "hazelcast/client/serialization/Serializer.h"
27 #include "hazelcast/util/IOUtil.h"
29 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
31 #pragma warning(disable: 4251) //for dll export
36 namespace serialization {
53 ObjectDataOutput(pimpl::DataOutput& dataOutput, pimpl::PortableContext& portableContext);
63 std::auto_ptr<std::vector<byte> > toByteArray();
69 void write(
const std::vector<byte>& bytes);
74 void writeBoolean(
bool value);
79 void writeByte(
int value);
84 void writeShort(
int value);
89 void writeChar(
int value);
94 void writeInt(
int value);
99 void writeLong(
long value);
104 void writeFloat(
float value);
109 void writeDouble(
double value);
114 void writeUTF(
const std::string *value);
119 void writeByteArray(
const std::vector<byte> *value);
124 void writeCharArray(
const std::vector<char> *value);
129 void writeShortArray(
const std::vector<short> *value);
134 void writeIntArray(
const std::vector<int> *value);
139 void writeLongArray(
const std::vector<long> *value);
144 void writeFloatArray(
const std::vector<float> *value);
149 void writeDoubleArray(
const std::vector<double> *value);
154 void writeUTFArray(
const std::vector<std::string *> *strings);
159 void writeData(
const pimpl::Data *value);
166 template <
typename T>
170 if (NULL ==
object) {
171 writeInt(pimpl::SerializationConstants::getInstance()->CONSTANT_TYPE_NULL);
173 writeInt(pimpl::SerializationConstants::getInstance()->CONSTANT_TYPE_PORTABLE);
178 context->getSerializerHolder().getPortableSerializer().write(*this->dataOutput, *
object);
191 if (NULL ==
object) {
192 writeInt(pimpl::SerializationConstants::getInstance()->CONSTANT_TYPE_NULL);
194 writeInt(pimpl::SerializationConstants::getInstance()->CONSTANT_TYPE_DATA);
195 context->getSerializerHolder().getDataSerializer().write(*
this, *
object);
204 template <
typename T>
208 if (NULL == serializable) {
209 writeInt(pimpl::SerializationConstants::getInstance()->CONSTANT_TYPE_NULL);
211 const T *
object =
static_cast<const T *
>(serializable);
212 int type =
object->getTypeId();
215 boost::shared_ptr<SerializerBase> serializer = context->getSerializerHolder().serializerFor(type);
217 if (NULL == serializer.get()) {
218 const std::string message =
"No serializer found for serializerId :"+
219 util::IOUtil::to_string(type) +
", typename :" +
226 s->
write(*
this, *
object);
230 pimpl::DataOutput *dataOutput;
231 pimpl::PortableContext *context;
232 pimpl::SerializerHolder *serializerHolder;
237 void position(
size_t newPos);
247 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
251 #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:167
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:48
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:205
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:188