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"
28 #include "hazelcast/client/serialization/TypeIDS.h"
29 #include "hazelcast/client/PartitionAware.h"
33 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
35 #pragma warning(disable: 4251) //for dll export
40 namespace serialization {
57 ObjectDataOutput(pimpl::DataOutput& dataOutput, pimpl::PortableContext& portableContext);
67 std::auto_ptr<std::vector<byte> > toByteArray();
73 void write(
const std::vector<byte>& bytes);
78 void writeBoolean(
bool value);
83 void writeByte(int32_t value);
89 void writeBytes(
const byte *bytes,
size_t len);
94 void writeShort(int32_t value);
99 void writeChar(int32_t value);
104 void writeInt(int32_t value);
109 void writeLong(int64_t value);
114 void writeFloat(
float value);
119 void writeDouble(
double value);
124 void writeUTF(
const std::string *value);
129 void writeByteArray(
const std::vector<byte> *value);
134 void writeCharArray(
const std::vector<char> *value);
139 void writeBooleanArray(
const std::vector<bool> *value);
144 void writeShortArray(
const std::vector<int16_t> *value);
149 void writeIntArray(
const std::vector<int32_t> *value);
154 void writeLongArray(
const std::vector<int64_t > *value);
159 void writeFloatArray(
const std::vector<float> *value);
164 void writeDoubleArray(
const std::vector<double> *value);
169 void writeUTFArray(
const std::vector<std::string *> *strings);
174 void writeData(
const pimpl::Data *value);
181 template <
typename T>
185 if (NULL ==
object) {
186 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
188 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_PORTABLE);
193 context->getSerializerHolder().getPortableSerializer().write(*this->dataOutput, *
object);
206 if (NULL ==
object) {
207 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
209 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_DATA);
210 context->getSerializerHolder().getDataSerializer().write(*
this, *
object);
219 template <
typename T>
223 if (NULL == serializable) {
224 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
226 const T *
object =
static_cast<const T *
>(serializable);
227 int32_t type = getHazelcastTypeId(
object);
230 boost::shared_ptr<SerializerBase> serializer = context->getSerializerHolder().serializerFor(type);
232 if (NULL == serializer.get()) {
233 const std::string message =
"No serializer found for serializerId :"+
234 util::IOUtil::to_string(type) +
", typename :" +
236 throw exception::HazelcastSerializationException(
"ObjectDataOutput::toData", message);
241 s->
write(*
this, *
object);
245 template <
typename T>
246 void writeObject(
const byte *
object) {
247 if (NULL ==
object) {
248 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
250 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_BYTE);
255 template <
typename T>
256 void writeObject(
const bool *
object) {
257 if (NULL ==
object) {
258 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
260 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_BOOLEAN);
261 writeBoolean(*
object);
265 template <
typename T>
266 void writeObject(
const char *
object) {
267 if (NULL ==
object) {
268 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
270 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_CHAR);
275 template <
typename T>
276 void writeObject(
const int16_t *
object) {
277 if (NULL ==
object) {
278 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
280 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_SHORT);
285 template <
typename T>
286 void writeObject(
const int32_t *
object) {
287 if (NULL ==
object) {
288 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
290 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_INTEGER);
295 template <
typename T>
296 void writeObject(
const int64_t *
object) {
297 if (NULL ==
object) {
298 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
300 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_LONG);
305 template <
typename T>
306 void writeObject(
const float *
object) {
307 if (NULL ==
object) {
308 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
310 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_FLOAT);
315 template <
typename T>
316 void writeObject(
const double *
object) {
317 if (NULL ==
object) {
318 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
320 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_DOUBLE);
321 writeDouble(*
object);
325 template <
typename T>
326 void writeObject(
const std::string *
object) {
327 if (NULL ==
object) {
328 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
330 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_STRING);
335 pimpl::DataOutput *dataOutput;
336 pimpl::PortableContext *context;
337 pimpl::SerializerHolder *serializerHolder;
342 void position(
size_t newPos);
344 ObjectDataOutput(
const ObjectDataOutput&);
346 void operator=(
const ObjectDataOutput&);
352 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
356 #endif //HAZELCAST_ObjectDataOutput
virtual int getClassId() const =0
Base class for custom serialization.
Definition: Serializer.h:110
void writeObject(const Portable *object)
Definition: ObjectDataOutput.h:182
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:52
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:220
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:203