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);
193 boost::shared_ptr<SerializerBase> serializer = serializerHolder->serializerFor(type);
195 if (NULL == serializer.get()) {
196 const std::string message =
"No serializer found for serializerId :"+
197 util::IOUtil::to_string(type) +
", typename :" +
199 throw exception::HazelcastSerializationException(
"ObjectDataOutput::toData", message);
202 boost::shared_ptr<StreamSerializer> streamSerializer = boost::static_pointer_cast<
StreamSerializer>(
205 writeInternal<T>(object, streamSerializer);
209 pimpl::DataOutput *getDataOutput()
const;
212 pimpl::DataOutput *dataOutput;
213 pimpl::PortableContext *context;
214 pimpl::SerializerHolder *serializerHolder;
219 void position(
size_t newPos);
232 template <
typename T>
233 void writeInternal(
const T *
object,
234 boost::shared_ptr<StreamSerializer> &streamSerializer) {
235 int32_t typeId = streamSerializer->getHazelcastTypeId();
237 case serialization::pimpl::SerializationConstants::CONSTANT_TYPE_DATA: {
238 serialization::pimpl::DataSerializer *dataSerializer =
239 static_cast<serialization::pimpl::DataSerializer *
>(streamSerializer.get());
240 return dataSerializer->write(*
this,
object);
242 case serialization::pimpl::SerializationConstants::CONSTANT_TYPE_PORTABLE: {
243 serialization::pimpl::PortableSerializer *portableSerializer =
244 static_cast<serialization::pimpl::PortableSerializer *
>(streamSerializer.get());
246 return portableSerializer->write(*
this,
object);
249 streamSerializer->write(*
this,
object);
256 HAZELCAST_API
void ObjectDataOutput::writeInternal(
const std::vector<std::string> *
object,
257 boost::shared_ptr<StreamSerializer> &streamSerializer);
262 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
266 #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:64