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"
32 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
34 #pragma warning(disable: 4251) //for dll export
39 namespace serialization {
56 ObjectDataOutput(pimpl::DataOutput& dataOutput, pimpl::PortableContext& portableContext);
66 std::auto_ptr<std::vector<byte> > toByteArray();
72 void write(
const std::vector<byte>& bytes);
77 void writeBoolean(
bool value);
82 void writeByte(int32_t value);
88 void writeBytes(
const byte *bytes,
size_t len);
93 void writeShort(int32_t value);
98 void writeChar(int32_t value);
103 void writeInt(int32_t value);
108 void writeLong(int64_t value);
113 void writeFloat(
float value);
118 void writeDouble(
double value);
123 void writeUTF(
const std::string *value);
128 void writeByteArray(
const std::vector<byte> *value);
133 void writeCharArray(
const std::vector<char> *value);
138 void writeBooleanArray(
const std::vector<bool> *value);
143 void writeShortArray(
const std::vector<int16_t> *value);
148 void writeIntArray(
const std::vector<int32_t> *value);
153 void writeLongArray(
const std::vector<int64_t > *value);
158 void writeFloatArray(
const std::vector<float> *value);
163 void writeDoubleArray(
const std::vector<double> *value);
168 void writeUTFArray(
const std::vector<std::string *> *strings);
173 void writeData(
const pimpl::Data *value);
180 template <
typename T>
184 if (NULL ==
object) {
185 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
187 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_PORTABLE);
192 context->getSerializerHolder().getPortableSerializer().write(*this->dataOutput, *
object);
205 if (NULL ==
object) {
206 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
208 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_DATA);
209 context->getSerializerHolder().getDataSerializer().write(*
this, *
object);
218 template <
typename T>
222 if (NULL == serializable) {
223 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
225 const T *
object =
static_cast<const T *
>(serializable);
226 int32_t type = getHazelcastTypeId(
object);
229 boost::shared_ptr<SerializerBase> serializer = context->getSerializerHolder().serializerFor(type);
231 if (NULL == serializer.get()) {
232 const std::string message =
"No serializer found for serializerId :"+
233 util::IOUtil::to_string(type) +
", typename :" +
235 throw exception::HazelcastSerializationException(
"ObjectDataOutput::toData", message);
240 s->
write(*
this, *
object);
244 template <
typename T>
245 void writeObject(
const byte *
object) {
246 if (NULL ==
object) {
247 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
249 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_BYTE);
254 template <
typename T>
255 void writeObject(
const bool *
object) {
256 if (NULL ==
object) {
257 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
259 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_BOOLEAN);
260 writeBoolean(*
object);
264 template <
typename T>
265 void writeObject(
const char *
object) {
266 if (NULL ==
object) {
267 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
269 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_CHAR);
274 template <
typename T>
275 void writeObject(
const int16_t *
object) {
276 if (NULL ==
object) {
277 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
279 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_SHORT);
284 template <
typename T>
285 void writeObject(
const int32_t *
object) {
286 if (NULL ==
object) {
287 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
289 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_INTEGER);
294 template <
typename T>
295 void writeObject(
const int64_t *
object) {
296 if (NULL ==
object) {
297 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
299 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_LONG);
304 template <
typename T>
305 void writeObject(
const float *
object) {
306 if (NULL ==
object) {
307 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
309 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_FLOAT);
314 template <
typename T>
315 void writeObject(
const double *
object) {
316 if (NULL ==
object) {
317 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
319 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_DOUBLE);
320 writeDouble(*
object);
324 template <
typename T>
325 void writeObject(
const std::string *
object) {
326 if (NULL ==
object) {
327 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_NULL);
329 writeInt(pimpl::SerializationConstants::CONSTANT_TYPE_STRING);
334 pimpl::DataOutput *dataOutput;
335 pimpl::PortableContext *context;
336 pimpl::SerializerHolder *serializerHolder;
341 void position(
size_t newPos);
343 ObjectDataOutput(
const ObjectDataOutput&);
345 void operator=(
const ObjectDataOutput&);
351 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
355 #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:181
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:51
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:219
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:202