Serialization API

User API for Serialization.

class ObjectDataOutput

Bases: object

ObjectDataOutput provides an interface to convert any of primitive types or arrays of them to series of bytes and write them on a stream.

write_from(buff, offset=None, length=None)

Writes the content of the buffer to this output stream.

Parameters:
  • buff – input buffer.
  • offset – (int), offset of the buffer where copy begin (optional).
  • length – (int), length of data to be copied from the offset into stream (optional).
write_boolean(val)

Writes a bool value to this output stream. Single byte value 1 represent True, 0 represent False

Parameters:val – (bool), the bool to be written.
write_byte(val)

Writes a byte value to this output stream.

Parameters:val – (byte), the byte value to be written.
write_short(val)

Writes a short value to this output stream.

Parameters:val – (short), the short value to be written.
write_char(val)

Writes a char value to this output stream.

Parameters:val – (char), the char value to be written.
write_int(val)

Writes a int value to this output stream.

Parameters:val – (int), the int value to be written.
write_long(val)

Writes a long value to this output stream.

Parameters:val – (long), the long value to be written.
write_float(val)

Writes a float value to this output stream.

Parameters:val – (float), the float value to be written.
write_double(val)

Writes a double value to this output stream.

Parameters:val – (double), the double value to be written.
write_bytes(string)

Writes a string to this output stream.

Parameters:val – (str), the string to be written.
write_chars(val)

Writes every character of string to this output stream.

Parameters:val – (str), the string to be written.
write_utf(val)

Writes 2 bytes of length information and UTF-8 string to this output stream.

Parameters:val – (UTF-8 str), the UTF-8 string to be written.
write_byte_array(val)

Writes a byte array to this output stream.

Parameters:val – (byte array), the byte array to be written.
write_boolean_array(val)

Writes a bool array to this output stream.

Parameters:val – (bool array), the bool array to be written.
write_char_array(val)

Writes a char array to this output stream.

Parameters:val – (char array), the char array to be written.
write_int_array(val)

Writes a int array to this output stream.

Parameters:val – (int array), the int array to be written.
write_long_array(val)

Writes a long array to this output stream.

Parameters:val – (long array), the long array to be written.
write_double_array(val)

Writes a double array to this output stream.

Parameters:val – (double array), the double array to be written.
write_float_array(val)

Writes a float array to this output stream.

Parameters:val – (float array), the float array to be written.
write_short_array(val)

Writes a short array to this output stream.

Parameters:val – (short array), the short array to be written.
write_utf_array(val)

Writes a UTF-8 String array to this output stream.

Parameters:val – (UTF-8 String array), the UTF-8 String array to be written.
write_object(val)

Writes an object to this output stream.

Parameters:val – (object), the object to be written.
write_data(val)

Writes a data to this output stream.

Parameters:val – (Data), the data to be written.
to_byte_array()

Returns a copy of internal byte array.

Returns:(byte array), the copy of internal byte array.
get_byte_order()

Returns the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.

Returns:the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.
class ObjectDataInput

Bases: object

ObjectDataInput provides an interface to read bytes from a stream and reconstruct it to any of primitive types or arrays of them.

read_into(buff, offset=None, length=None)

Reads the content of the buffer into an array of bytes.

Parameters:
  • buff – input buffer.
  • offset – (int), offset of the buffer where the read begin (optional).
  • length – (int), length of data to be read (optional).
Returns:

(byte array), the read data.

skip_bytes(count)

Skips over given number of bytes from input stream.

Parameters:count – (long), number of bytes to be skipped.
Returns:(long), the actual number of bytes skipped.
read_boolean()

Reads 1 byte from input stream and convert it to a bool value.

Returns:(bool), the bool value read.
read_byte()

Reads 1 byte from input stream and returns it.

Returns:(byte), the byte value read.
read_unsigned_byte()

Reads 1 byte from input stream, zero-extends it and returns.

Returns:(unsigned byte), the unsigned byte value read.
read_short()

Reads 2 bytes from input stream and returns a short value.

Returns:(short), the short value read.
read_unsigned_short()

Reads 2 bytes from input stream and returns an int value.

Returns:(unsigned short), the unsigned short value read.
read_int()

Reads 4 bytes from input stream and returns an int value.

Returns:(int), the int value read.
read_long()

Reads 8 bytes from input stream and returns a long value.

Returns:(long), the int value read.
read_float()

Reads 4 bytes from input stream and returns a float value.

Returns:(float), the float value read.
read_double()

Reads 8 bytes from input stream and returns a double value.

Returns:(long), the double value read.
read_utf()

Reads a UTF-8 string from input stream and returns it.

Returns:(UTF-8 str), the UTF-8 string read.
read_byte_array()

Reads a byte array from input stream and returns it.

Returns:(byte array), the byte array read.
read_boolean_array()

Reads a bool array from input stream and returns it.

Returns:(bool array), the bool array read.
read_char_array()

Reads a char array from input stream and returns it.

Returns:(char array), the char array read.
read_int_array()

Reads a int array from input stream and returns it.

Returns:(int array), the int array read.
read_long_array()

Reads a long array from input stream and returns it.

Returns:(long array), the long array read.
read_double_array()

Reads a double array from input stream and returns it.

Returns:(double array), the double array read.
read_float_array()

Reads a float array from input stream and returns it.

Returns:(float array), the float array read.
read_short_array()

Reads a short array from input stream and returns it.

Returns:(short array), the short array read.
read_utf_array()

Reads a UTF-8 String array from input stream and returns it.

Returns:(UTF-8 String array), the UTF-8 String array read.
read_object()

Reads a object from input stream and returns it.

Returns:(object), the object read.
read_data()

Reads a data from input stream and returns it.

Returns:(Data), the data read.
get_byte_order()

Returns the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.

Returns:the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.
position()

Returns current position in buffer.

Returns:current position in buffer.
size()

Returns size of buffer.

Returns:size of buffer.
class IdentifiedDataSerializable

Bases: object

IdentifiedDataSerializable is an alternative serialization method to Python pickle, which also avoids reflection during de-serialization. Each IdentifiedDataSerializable is created by a registered DataSerializableFactory.

write_data(object_data_output)

Writes object fields to output stream.

Parameters:object_data_output – (hazelcast.serialization.api.ObjectDataOutput), the output.
read_data(object_data_input)

Reads fields from the input stream.

Parameters:object_data_input – (hazelcast.serialization.api.ObjectDataInput), the input.
get_factory_id()

Returns DataSerializableFactory factory id for this class.

Returns:(int), the factory id.
get_class_id()

Returns type identifier for this class. Id should be unique per DataSerializableFactory.

Returns:(int), the type id.
class Portable

Bases: object

Portable provides an alternative serialization method. Instead of relying on reflection, each Portable is created by a registered PortableFactory. Portable serialization has the following advantages:

  • Support multiversion of the same object type.
  • Fetching individual fields without having to rely on reflection.
  • Querying and indexing support without de-serialization and/or reflection.
write_portable(writer)

Serialize this portable object using given PortableWriter.

Parameters:writerhazelcast.serialization.api.PortableWriter, the PortableWriter.
read_portable(reader)

Read portable fields using PortableReader.

Parameters:readerhazelcast.serialization.api.PortableReader, the PortableReader.
get_factory_id()

Returns PortableFactory id for this portable class

Returns:(int), the factory id.
get_class_id()

Returns class identifier for this portable class. Class id should be unique per PortableFactory.

Returns:(int), the class id.
class StreamSerializer

Bases: object

A base class for custom serialization. User can register custom serializer like following:
>>> class CustomSerializer(StreamSerializer):
>>>     def __init__(self):
>>>         super(CustomSerializer, self).__init__()
>>>
>>>     def read(self, inp):
>>>         pass
>>>
>>>     def write(self, out, obj):
>>>         pass
>>>
>>>     def get_type_id(self):
>>>         pass
>>>
>>>     def destroy(self):
>>>         pass
write(out, obj)

Writes object to ObjectDataOutput

Parameters:
read(inp)

Reads object from objectDataInputStream

Parameters:inp – (hazelcast.serialization.api.ObjectDataInput) stream that object will read from.
Returns:(object), the read object.
get_type_id()

Returns typeId of serializer. :return: (int), typeId of serializer.

destroy()

Called when instance is shutting down. It can be used to clear used resources.

class PortableReader

Bases: object

Provides a mean of reading portable fields from binary in form of Python primitives and arrays of these primitives, nested portable fields and array of portable fields.

get_version()

Returns the global version of portable classes.

Returns:(int), global version of portable classes.
has_field(field_name)

Determine whether the field name exists in this portable class or not.

Parameters:field_name – (str), name of the field (does not support nested paths).
Returns:(bool), true if the field name exists in class, false otherwise.
get_field_names()

Returns the set of field names on this portable class.

Returns:(Set), set of field names on this portable class.
get_field_type(field_name)

Returns the field type of given field name.

Parameters:field_name – (str), name of the field.
Returns:the field type.
get_field_class_id(field_name)

Returns the class id of given field.

Parameters:field_name – (str), name of the field.
Returns:(int), class id of given field.
read_int(field_name)

Reads a primitive int.

Parameters:field_name – (str), name of the field.
Returns:(int), the int value read.
read_long(field_name)

Reads a primitive long.

Parameters:field_name – (str), name of the field.
Returns:(long), the long value read.
read_utf(field_name)

Reads a UTF-8 String.

Parameters:field_name – (str), name of the field.
Returns:(UTF-8 str), the UTF-8 String read.
read_boolean(field_name)

Reads a primitive bool.

Parameters:field_name – (str), name of the field.
Returns:(bool), the bool value read.
read_byte(field_name)

Reads a primitive byte.

Parameters:field_name – (str), name of the field.
Returns:(byte), the byte value read.
read_char(field_name)

Reads a primitive char.

Parameters:field_name – (str), name of the field.
Returns:(char), the char value read.
read_double(field_name)

Reads a primitive double.

Parameters:field_name – (str), name of the field.
Returns:(double), the double value read.
read_float(field_name)

Reads a primitive float.

Parameters:field_name – (str), name of the field.
Returns:(float), the float value read.
read_short(field_name)

Reads a primitive short.

Parameters:field_name – (str), name of the field.
Returns:(short), the short value read.
read_portable(field_name)

Reads a portable.

Parameters:field_name – (str), name of the field.
Returns:(hazelcast.serialization.api.Portable, the portable read.
read_byte_array(field_name)

Reads a primitive byte array.

Parameters:field_name – (str), name of the field.
Returns:(byte array), the byte array read.
read_boolean_array(field_name)

Reads a primitive bool array.

Parameters:field_name – (str), name of the field.
Returns:(bool array), the bool array read.
read_char_array(field_name)

Reads a primitive char array.

Parameters:field_name – (str), name of the field.
Returns:(char array), the char array read.
read_int_array(field_name)

Reads a primitive int array.

Parameters:field_name – (str), name of the field.
Returns:(int array), the int array read.
read_long_array(field_name)

Reads a primitive long array.

Parameters:field_name – (str), name of the field.
Returns:(long array), the long array read.
read_double_array(field_name)

Reads a primitive double array.

Parameters:field_name – (str), name of the field.
Returns:(double array), the double array read.
read_float_array(field_name)

Reads a primitive float array.

Parameters:field_name – (str), name of the field.
Returns:(float array), the float array read.
read_short_array(field_name)

Reads a primitive short array.

Parameters:field_name – (str), name of the field.
Returns:(short array), the short array read.
read_utf_array(field_name)

Reads a UTF-8 String array.

Parameters:field_name – (str), name of the field.
Returns:(UTF-8 String array), the UTF-8 String array read.
read_portable_array(field_name)

Reads a portable array.

Parameters:field_name – (str), name of the field.
Returns:(Portable array), the portable array read.
get_raw_data_input()

After reading portable fields, one can read remaining fields in old fashioned way consecutively from the end of stream. After get_raw_data_input() called, no data can be read.

Returns:(hazelcast.serialization.api.ObjectDataInput), the input.
class PortableWriter

Bases: object

Provides a mean of writing portable fields to a binary in form of Python primitives and arrays of these primitives, nested portable fields and array of portable fields.

write_int(field_name, value)

Writes a primitive int.

Parameters:
  • field_name – (str), name of the field.
  • value – (int), int value to be written.
write_long(field_name, value)

Writes a primitive long.

Parameters:
  • field_name – (str), name of the field.
  • value – (long), long value to be written.
write_utf(field_name, value)

Writes an UTF string.

Parameters:
  • field_name – (str), name of the field.
  • value – (UTF str), UTF string value to be written.
write_boolean(field_name, value)

Writes a primitive bool.

Parameters:
  • field_name – (str), name of the field.
  • value – (bool), bool value to be written.
write_byte(field_name, value)

Writes a primitive byte.

Parameters:
  • field_name – (str), name of the field.
  • value – (byte), byte value to be written.
write_char(field_name, value)

Writes a primitive char.

Parameters:
  • field_name – (str), name of the field.
  • value – (char), char value to be written.
write_double(field_name, value)

Writes a primitive double.

Parameters:
  • field_name – (str), name of the field.
  • value – (Dobule), double value to be written.
write_float(field_name, value)

Writes a primitive float.

Parameters:
  • field_name – (str), name of the field.
  • value – (float), float value to be written.
write_short(field_name, value)

Writes a primitive short.

Parameters:
  • field_name – (str), name of the field.
  • value – (short), short value to be written.
write_portable(field_name, portable)

Writes a Portabl

Parameters:
write_null_portable(field_name, factory_id, class_id)

To write a null portable value, user needs to provide class and factoryIds of related class.

Parameters:
  • field_name – (str), name of the field.
  • factory_id – (int), factory id of related portable class.
  • class_id – (int), class id of related portable class.
write_byte_array(field_name, values)

Writes a primitive byte array.

Parameters:
  • field_name – (str), name of the field.
  • values – (byte array), byte array to be written.
write_boolean_array(field_name, values)

Writes a primitive bool array.

Parameters:
  • field_name – (str), name of the field.
  • values – (bool array), bool array to be written.
write_char_array(field_name, values)

Writes a primitive char array.

Parameters:
  • field_name – (str), name of the field.
  • values – (char array), char array to be written.
write_int_array(field_name, values)

Writes a primitive int array.

Parameters:
  • field_name – (str), name of the field.
  • values – (int array), int array to be written.
write_long_array(field_name, values)

Writes a primitive long array.

Parameters:
  • field_name – (str), name of the field.
  • values – (long array), long array to be written.
write_double_array(field_name, values)

Writes a primitive double array.

Parameters:
  • field_name – (str), name of the field.
  • values – (double array), double array to be written.
write_float_array(field_name, values)

Writes a primitive float array.

Parameters:
  • field_name – (str), name of the field.
  • values – (float array), float array to be written.
write_short_array(field_name, values)

Writes a primitive short array.

Parameters:
  • field_name – (str), name of the field.
  • values – (short array), short array to be written.
write_utf_array(field_name, values)

Writes a UTF-8 String array.

Parameters:
  • field_name – (str), name of the field.
  • values – (UTF-8 String array), UTF-8 String array to be written.
write_portable_array(field_name, values)

Writes a portable array.

Parameters:
  • field_name – (str), name of the field.
  • values – (Portable array), portable array to be written.
get_raw_data_output()

After writing portable fields, one can write remaining fields in old fashioned way consecutively at the end of stream. After get_raw_data_output() called, no data can be written.

Returns:(hazelcast.serialization.api.ObjectDataOutput), the output.