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/pimpl/DataSerializer.h"
27 #include "hazelcast/client/serialization/pimpl/PortableSerializer.h"
28 #include "hazelcast/client/serialization/Serializer.h"
29 #include "hazelcast/util/IOUtil.h"
30 #include "hazelcast/client/serialization/TypeIDS.h"
31 #include "hazelcast/client/PartitionAware.h"
35 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
37 #pragma warning(disable: 4251) //for dll export
42 namespace serialization {
59 ObjectDataOutput(pimpl::DataOutput& dataOutput, pimpl::SerializerHolder *serializerHolder);
69 std::auto_ptr<std::vector<byte> > toByteArray();
75 void write(
const std::vector<byte>& bytes);
80 void writeBoolean(
bool value);
85 void writeByte(int32_t value);
91 void writeBytes(
const byte *bytes,
size_t len);
96 void writeShort(int32_t value);
101 void writeChar(int32_t value);
106 void writeInt(int32_t value);
111 void writeLong(int64_t value);
116 void writeFloat(
float value);
121 void writeDouble(
double value);
126 void writeUTF(
const std::string *value);
131 void writeByteArray(
const std::vector<byte> *value);
136 void writeCharArray(
const std::vector<char> *value);
141 void writeBooleanArray(
const std::vector<bool> *value);
146 void writeShortArray(
const std::vector<int16_t> *value);
151 void writeIntArray(
const std::vector<int32_t> *value);
156 void writeLongArray(
const std::vector<int64_t > *value);
161 void writeFloatArray(
const std::vector<float> *value);
166 void writeDoubleArray(
const std::vector<double> *value);
171 void writeUTFArray(
const std::vector<std::string *> *strings);
176 void writeData(
const pimpl::Data *value);
183 template <
typename T>
187 if (NULL ==
object) {
188 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
190 int32_t type = getHazelcastTypeId(
object);
192 boost::shared_ptr<SerializerBase> serializer = serializerHolder->serializerFor(type);
194 if (NULL == serializer.get()) {
195 const std::string message =
"No serializer found for serializerId :"+
196 util::IOUtil::to_string(type) +
", typename :" +
198 throw exception::HazelcastSerializationException(
"ObjectDataOutput::toData", message);
201 boost::shared_ptr<StreamSerializer> streamSerializer = boost::static_pointer_cast<
StreamSerializer>(
204 writeInt(streamSerializer->getHazelcastTypeId());
206 writeInternal<T>(object, streamSerializer);
210 pimpl::DataOutput *getDataOutput()
const;
213 pimpl::DataOutput *dataOutput;
214 pimpl::PortableContext *context;
215 pimpl::SerializerHolder *serializerHolder;
220 void position(
size_t newPos);
233 template <
typename T>
234 void writeInternal(
const T *
object,
235 boost::shared_ptr<StreamSerializer> &streamSerializer) {
236 int32_t typeId = streamSerializer->getHazelcastTypeId();
238 case serialization::pimpl::SerializationConstants::CONSTANT_TYPE_DATA: {
239 serialization::pimpl::DataSerializer *dataSerializer =
240 static_cast<serialization::pimpl::DataSerializer *
>(streamSerializer.get());
241 return dataSerializer->write(*
this,
object);
243 case serialization::pimpl::SerializationConstants::CONSTANT_TYPE_PORTABLE: {
244 serialization::pimpl::PortableSerializer *portableSerializer =
245 static_cast<serialization::pimpl::PortableSerializer *
>(streamSerializer.get());
247 return portableSerializer->write(*
this,
object);
250 streamSerializer->write(*
this,
object);
257 HAZELCAST_API
void ObjectDataOutput::writeInternal(
const std::vector<std::string> *
object,
258 boost::shared_ptr<StreamSerializer> &streamSerializer);
263 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
267 #endif //HAZELCAST_ObjectDataOutput
void writeObject(const T *object)
Definition: ObjectDataOutput.h:184
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:54
Definition: MapEntryView.h:32
Implement this interface and register to the SerializationConfig.
Definition: Serializer.h:71