Serialization

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 (bytearray) – Input buffer.

  • offset (int) – Offset of the buffer where copy begin.

  • length (int) – Length of data to be copied from the offset into stream.

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 (int) – The byte value to be written.

write_short(val)

Writes a short value to this output stream.

Parameters

val (int) – The short value to be written.

write_char(val)

Writes a char value to this output stream.

Parameters

val (str) – 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 (int) – 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 (float) – The double value to be written.

write_bytes(val)

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 UTF-8 string to this output stream.

Parameters

val (str) – The UTF-8 string to be written.

write_byte_array(val)

Writes a byte array to this output stream.

Parameters

val (bytearray) – The byte array to be written.

write_boolean_array(val)

Writes a bool array to this output stream.

Parameters

val (list[bool]) – The bool array to be written.

write_char_array(val)

Writes a char array to this output stream.

Parameters

val (list[str]) – The char array to be written.

write_int_array(val)

Writes a int array to this output stream.

Parameters

val (list[int]) – The int array to be written.

write_long_array(val)

Writes a long array to this output stream.

Parameters

val (list[int]) – The long array to be written.

write_double_array(val)

Writes a double array to this output stream.

Parameters

val (list[float]) – The double array to be written.

write_float_array(val)

Writes a float array to this output stream.

Parameters

val (list[float]) – The float array to be written.

write_short_array(val)

Writes a short array to this output stream.

Parameters

val (list[int]) – The short array to be written.

write_utf_array(val)

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

Parameters

val (list[str]) – The UTF-8 String array to be written.

write_object(val)

Writes an object to this output stream.

Parameters

val – The object to be written.

to_byte_array()

Returns a copy of internal byte array.

Returns

The copy of internal byte array

Return type

bytearray

get_byte_order()

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 (bytearray) – Input buffer.

  • offset (int) – Offset of the buffer where the read begin.

  • length (int) – Length of data to be read.

Returns

The read data.

Return type

bytearray

skip_bytes(count)

Skips over given number of bytes from input stream.

Parameters

count (int) – Number of bytes to be skipped.

Returns

The actual number of bytes skipped.

Return type

int

read_boolean()

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

Returns

The bool value read.

Return type

bool

read_byte()

Reads 1 byte from input stream and returns it.

Returns

The byte value read.

Return type

int

read_unsigned_byte()

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

Returns

The unsigned byte value read.

Return type

int

read_short()

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

Returns

The short value read.

Return type

int

read_unsigned_short()

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

Returns

The unsigned short value read.

Return type

int

read_int()

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

Returns

The int value read.

Return type

int

read_long()

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

Returns

The int value read.

Return type

int

read_float()

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

Returns

The float value read.

Return type

float

read_double()

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

Returns

The double value read.

Return type

float

read_utf()

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

Returns

The UTF-8 string read.

Return type

str

read_byte_array()

Reads a byte array from input stream and returns it.

Returns

The byte array read.

Return type

bytearray

read_boolean_array()

Reads a bool array from input stream and returns it.

Returns

The bool array read.

Return type

list[bool]

read_char_array()

Reads a char array from input stream and returns it.

Returns

The char array read.

Return type

list[str]

read_int_array()

Reads a int array from input stream and returns it.

Returns

The int array read.

Return type

list[int]

read_long_array()

Reads a long array from input stream and returns it.

Returns

The long array read.

Return type

list[int]

read_double_array()

Reads a double array from input stream and returns it.

Returns

The double array read.

Return type

list[float]

read_float_array()

Reads a float array from input stream and returns it.

Returns

The float array read.

Return type

list[float]

read_short_array()

Reads a short array from input stream and returns it.

Returns

The short array read.

Return type

list[int]

read_utf_array()

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

Returns

The UTF-8 string array read.

Return type

list[str]

read_object()

Reads a object from input stream and returns it.

Returns

The object read.

get_byte_order()

Returns the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.

position()

Returns current position in buffer.

Returns

Current position in buffer.

Return type

int

size()

Returns size of buffer.

Returns

size of buffer.

Return type

int

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

The factory id.

Return type

int

get_class_id()

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

Returns

The type id.

Return type

int

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

writer (hazelcast.serialization.api.PortableWriter) – The PortableWriter.

read_portable(reader)

Read portable fields using PortableReader.

Parameters

reader (hazelcast.serialization.api.PortableReader) – The PortableReader.

get_factory_id()

Returns PortableFactory id for this portable class

Returns

The factory id.

Return type

int

get_class_id()

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

Returns

The class id.

Return type

int

class StreamSerializer

Bases: object

A base class for custom serialization.

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

The read object.

get_type_id()

Returns typeId of serializer.

Returns

The type id of the serializer.

Return type

int

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

Global version of portable classes.

Return type

int

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

True if the field name exists in class, False otherwise.

Return type

bool

get_field_names()

Returns the set of field names on this portable class.

Returns

Set of field names on this portable class.

Return type

set

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.

Return type

hazelcast.serialization.portable.classdef.FieldType

get_field_class_id(field_name)

Returns the class id of given field.

Parameters

field_name (str) – Name of the field.

Returns

class id of given field.

Return type

int

read_int(field_name)

Reads a primitive int.

Parameters

field_name (str) – Name of the field.

Returns

The int value read.

Return type

int

read_long(field_name)

Reads a primitive long.

Parameters

field_name (str) – Name of the field.

Returns

The long value read.

Return type

int

read_utf(field_name)

Reads a UTF-8 String.

Parameters

field_name (str) – Name of the field.

Returns

The UTF-8 String read.

Return type

str

read_boolean(field_name)

Reads a primitive bool.

Parameters

field_name (str) – Name of the field.

Returns

The bool value read.

Return type

bool

read_byte(field_name)

Reads a primitive byte.

Parameters

field_name (str) – Name of the field.

Returns

The byte value read.

Return type

int

read_char(field_name)

Reads a primitive char.

Parameters

field_name (str) – Name of the field.

Returns

The char value read.

Return type

str

read_double(field_name)

Reads a primitive double.

Parameters

field_name (str) – Name of the field.

Returns

The double value read.

Return type

float

read_float(field_name)

Reads a primitive float.

Parameters

field_name (str) – Name of the field.

Returns

The float value read.

Return type

float

read_short(field_name)

Reads a primitive short.

Parameters

field_name (str) – Name of the field.

Returns

The short value read.

Return type

int

read_portable(field_name)

Reads a portable.

Parameters

field_name (str) – Name of the field.

Returns

The portable read.

Return type

hazelcast.serialization.api.Portable

read_byte_array(field_name)

Reads a primitive byte array.

Parameters

field_name (str) – Name of the field.

Returns

The byte array read.

Return type

bytearray

read_boolean_array(field_name)

Reads a primitive bool array.

Parameters

field_name (str) – Name of the field.

Returns

The bool array read.

Return type

list[bool])

read_char_array(field_name)

Reads a primitive char array.

Parameters

field_name (str) – Name of the field.

Returns

The char array read.

Return type

list[str])

read_int_array(field_name)

Reads a primitive int array.

Parameters

field_name (str) – Name of the field.

Returns

The int array read.

Return type

list[int]

read_long_array(field_name)

Reads a primitive long array.

Parameters

field_name (str) – Name of the field.

Returns

The long array read.

Return type

list[int]

read_double_array(field_name)

Reads a primitive double array.

Parameters

field_name (str) – Name of the field.

Returns

The double array read.

Return type

list[float]

read_float_array(field_name)

Reads a primitive float array.

Parameters

field_name (str) – Name of the field.

Returns

The float array read.

Return type

list[float]

read_short_array(field_name)

Reads a primitive short array.

Parameters

field_name (str) – Name of the field.

Returns

The short array read.

Return type

list[int]

read_utf_array(field_name)

Reads a UTF-8 String array.

Parameters

field_name (str) – Name of the field.

Returns

The UTF-8 String array read.

Return type

str

read_portable_array(field_name)

Reads a portable array.

Parameters

field_name (str) – Name of the field.

Returns

The portable array read.

Return type

list[hazelcast.serialization.api.Portable]

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

The input.

Return type

hazelcast.serialization.api.ObjectDataInput

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 (int) – Long value to be written.

write_utf(field_name, value)

Writes an UTF string.

Parameters
  • field_name (str) – Name of the field.

  • value (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 (int) – Byte value to be written.

write_char(field_name, value)

Writes a primitive char.

Parameters
  • field_name (str) – Name of the field.

  • value (str) – Char value to be written.

write_double(field_name, value)

Writes a primitive double.

Parameters
  • field_name (str) – Name of the field.

  • value (float) – 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 (int) – Short value to be written.

write_portable(field_name, portable)

Writes a Portable.

Parameters
write_null_portable(field_name, factory_id, class_id)

To write a null portable value, user needs to provide class and factory ids 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 (bytearray) – Bytearray to be written.

write_boolean_array(field_name, values)

Writes a primitive bool array.

Parameters
  • field_name (str) – Name of the field.

  • values (list[bool]) – 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 (list[str]) – 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 (list[int]) – 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 (list[int]) – 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 (list[float]) – 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 (list[float]) – 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 – (list[int]): 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 – (str): UTF-8 String array to be written.

write_portable_array(field_name, values)

Writes a portable array.

Parameters
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

The output.

Return type

hazelcast.serialization.api.ObjectDataOutput