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"
30 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
32 #pragma warning(disable: 4251) //for dll export
37 namespace serialization {
54 ObjectDataOutput(pimpl::DataOutput& dataOutput, pimpl::PortableContext& portableContext);
64 std::auto_ptr<std::vector<byte> > toByteArray();
70 void write(
const std::vector<byte>& bytes);
75 void writeBoolean(
bool value);
80 void writeByte(
int value);
85 void writeShort(
int value);
90 void writeChar(
int value);
95 void writeInt(
int value);
100 void writeLong(
long value);
105 void writeFloat(
float value);
110 void writeDouble(
double value);
115 void writeUTF(
const std::string *value);
120 void writeByteArray(
const std::vector<byte> *value);
125 void writeCharArray(
const std::vector<char> *value);
130 void writeBooleanArray(
const std::vector<bool> *value);
135 void writeShortArray(
const std::vector<short> *value);
140 void writeIntArray(
const std::vector<int> *value);
145 void writeLongArray(
const std::vector<long> *value);
150 void writeFloatArray(
const std::vector<float> *value);
155 void writeDoubleArray(
const std::vector<double> *value);
160 void writeUTFArray(
const std::vector<std::string *> *strings);
165 void writeData(
const pimpl::Data *value);
172 template <
typename T>
176 if (NULL ==
object) {
177 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
179 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_PORTABLE);
184 context->getSerializerHolder().getPortableSerializer().write(*this->dataOutput, *
object);
197 if (NULL ==
object) {
198 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
200 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_DATA);
201 context->getSerializerHolder().getDataSerializer().write(*
this, *
object);
210 template <
typename T>
214 if (NULL == serializable) {
215 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
217 const T *
object =
static_cast<const T *
>(serializable);
218 int type = getHazelcastTypeId(
object);
221 boost::shared_ptr<SerializerBase> serializer = context->getSerializerHolder().serializerFor(type);
223 if (NULL == serializer.get()) {
224 const std::string message =
"No serializer found for serializerId :"+
225 util::IOUtil::to_string(type) +
", typename :" +
232 s->
write(*
this, *
object);
236 template <
typename T>
237 void writeObject(
const byte *
object) {
238 if (NULL ==
object) {
239 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
241 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_BYTE);
246 template <
typename T>
247 void writeObject(
const bool *
object) {
248 if (NULL ==
object) {
249 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
251 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_BOOLEAN);
252 writeBoolean(*
object);
256 template <
typename T>
257 void writeObject(
const char *
object) {
258 if (NULL ==
object) {
259 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
261 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_CHAR);
266 template <
typename T>
267 void writeObject(
const short *
object) {
268 if (NULL ==
object) {
269 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
271 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_SHORT);
276 template <
typename T>
277 void writeObject(
const int *
object) {
278 if (NULL ==
object) {
279 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
281 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_INTEGER);
286 template <
typename T>
287 void writeObject(
const long *
object) {
288 if (NULL ==
object) {
289 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
291 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_LONG);
296 template <
typename T>
297 void writeObject(
const float *
object) {
298 if (NULL ==
object) {
299 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
301 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_FLOAT);
306 template <
typename T>
307 void writeObject(
const double *
object) {
308 if (NULL ==
object) {
309 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
311 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_DOUBLE);
312 writeDouble(*
object);
316 template <
typename T>
317 void writeObject(
const std::string *
object) {
318 if (NULL ==
object) {
319 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
321 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_STRING);
326 pimpl::DataOutput *dataOutput;
327 pimpl::PortableContext *context;
328 pimpl::SerializerHolder *serializerHolder;
333 void position(
size_t newPos);
335 ObjectDataOutput(
const ObjectDataOutput&);
337 void operator=(
const ObjectDataOutput&);
343 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
347 #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:108
void writeObject(const Portable *object)
Definition: ObjectDataOutput.h:173
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:49
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:211
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:194