Serialization

User API for Serialization.

class ObjectDataOutput[source]

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)[source]

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)[source]

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)[source]

Writes a byte value to this output stream.

Parameters

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

write_short(val)[source]

Writes a short value to this output stream.

Parameters

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

write_char(val)[source]

Writes a char value to this output stream.

Parameters

val (str) – The char value to be written.

write_int(val)[source]

Writes a int value to this output stream.

Parameters

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

write_long(val)[source]

Writes a long value to this output stream.

Parameters

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

write_float(val)[source]

Writes a float value to this output stream.

Parameters

val (float) – The float value to be written.

write_double(val)[source]

Writes a double value to this output stream.

Parameters

val (float) – The double value to be written.

write_bytes(val)[source]

Writes a string to this output stream.

Parameters

val (str) – The string to be written.

write_chars(val)[source]

Writes every character of string to this output stream.

Parameters

val (str) – The string to be written.

write_string(val)[source]

Writes UTF-8 string to this output stream.

Parameters

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

write_utf(val)[source]

Writes UTF-8 string to this output stream.

Deprecated since version 4.1: This method is deprecated and will be removed in the next major version. Use write_string() instead.

Parameters

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

write_byte_array(val)[source]

Writes a byte array to this output stream.

Parameters

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

write_boolean_array(val)[source]

Writes a bool array to this output stream.

Parameters

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

write_char_array(val)[source]

Writes a char array to this output stream.

Parameters

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

write_int_array(val)[source]

Writes a int array to this output stream.

Parameters

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

write_long_array(val)[source]

Writes a long array to this output stream.

Parameters

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

write_double_array(val)[source]

Writes a double array to this output stream.

Parameters

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

write_float_array(val)[source]

Writes a float array to this output stream.

Parameters

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

write_short_array(val)[source]

Writes a short array to this output stream.

Parameters

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

write_string_array(val)[source]

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

Parameters

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

write_utf_array(val)[source]

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

Deprecated since version 4.1: This method is deprecated and will be removed in the next major version. Use write_string_array() instead.

Parameters

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

write_object(val)[source]

Writes an object to this output stream.

Parameters

val – The object to be written.

to_byte_array()[source]

Returns a copy of internal byte array.

Returns

The copy of internal byte array

Return type

bytearray

get_byte_order()[source]

Returns the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.

Returns

Return type

str

class ObjectDataInput[source]

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)[source]

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)[source]

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()[source]

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

Returns

The bool value read.

Return type

bool

read_byte()[source]

Reads 1 byte from input stream and returns it.

Returns

The byte value read.

Return type

int

read_unsigned_byte()[source]

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

Returns

The unsigned byte value read.

Return type

int

read_short()[source]

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

Returns

The short value read.

Return type

int

read_unsigned_short()[source]

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

Returns

The unsigned short value read.

Return type

int

read_char()[source]

Reads 2 bytes from the input stream and returns a str value.

Returns

The char value read.

Return type

str

read_int()[source]

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

Returns

The int value read.

Return type

int

read_long()[source]

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

Returns

The int value read.

Return type

int

read_float()[source]

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

Returns

The float value read.

Return type

float

read_double()[source]

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

Returns

The double value read.

Return type

float

read_string()[source]

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

Returns

The UTF-8 string read.

Return type

str

read_utf()[source]

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

Deprecated since version 4.1: This method is deprecated and will be removed in the next major version. Use read_string() instead.

Returns

The UTF-8 string read.

Return type

str

read_byte_array()[source]

Reads a byte array from input stream and returns it.

Returns

The byte array read.

Return type

bytearray

read_boolean_array()[source]

Reads a bool array from input stream and returns it.

Returns

The bool array read.

Return type

list[bool]

read_char_array()[source]

Reads a char array from input stream and returns it.

Returns

The char array read.

Return type

list[str]

read_int_array()[source]

Reads a int array from input stream and returns it.

Returns

The int array read.

Return type

list[int]

read_long_array()[source]

Reads a long array from input stream and returns it.

Returns

The long array read.

Return type

list[int]

read_double_array()[source]

Reads a double array from input stream and returns it.

Returns

The double array read.

Return type

list[float]

read_float_array()[source]

Reads a float array from input stream and returns it.

Returns

The float array read.

Return type

list[float]

read_short_array()[source]

Reads a short array from input stream and returns it.

Returns

The short array read.

Return type

list[int]

read_string_array()[source]

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

Returns

The UTF-8 string array read.

Return type

list[str]

read_utf_array()[source]

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

Deprecated since version 4.1: This method is deprecated and will be removed in the next major version. Use read_string_array() instead.

Returns

The UTF-8 string array read.

Return type

list[str]

read_object()[source]

Reads a object from input stream and returns it.

Returns

The object read.

get_byte_order()[source]

Returns the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.

Returns

Return type

str

position()[source]

Returns current position in buffer.

Returns

Current position in buffer.

Return type

int

size()[source]

Returns size of buffer.

Returns

size of buffer.

Return type

int

class IdentifiedDataSerializable[source]

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)[source]

Writes object fields to output stream.

Parameters

object_data_output (hazelcast.serialization.api.ObjectDataOutput) – The output.

read_data(object_data_input)[source]

Reads fields from the input stream.

Parameters

object_data_input (hazelcast.serialization.api.ObjectDataInput) – The input.

get_factory_id()[source]

Returns DataSerializableFactory factory id for this class.

Returns

The factory id.

Return type

int

get_class_id()[source]

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

Returns

The type id.

Return type

int

class Portable[source]

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)[source]

Serialize this portable object using given PortableWriter.

Parameters

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

read_portable(reader)[source]

Read portable fields using PortableReader.

Parameters

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

get_factory_id()[source]

Returns PortableFactory id for this portable class

Returns

The factory id.

Return type

int

get_class_id()[source]

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

Returns

The class id.

Return type

int

class StreamSerializer[source]

Bases: object

A base class for custom serialization.

write(out, obj)[source]

Writes object to ObjectDataOutput

Parameters
read(inp)[source]

Reads object from objectDataInputStream

Parameters

inp (hazelcast.serialization.api.ObjectDataInput) – Stream that object will read from.

Returns

The read object.

get_type_id()[source]

Returns typeId of serializer.

Returns

The type id of the serializer.

Return type

int

destroy()[source]

Called when instance is shutting down.

It can be used to clear used resources.

class PortableReader[source]

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()[source]

Returns the global version of portable classes.

Returns

Global version of portable classes.

Return type

int

has_field(field_name)[source]

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()[source]

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)[source]

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)[source]

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)[source]

Reads a primitive int.

Parameters

field_name (str) – Name of the field.

Returns

The int value read.

Return type

int

read_long(field_name)[source]

Reads a primitive long.

Parameters

field_name (str) – Name of the field.

Returns

The long value read.

Return type

int

read_string(field_name)[source]

Reads a UTF-8 String.

Parameters

field_name (str) – Name of the field.

Returns

The UTF-8 String read.

Return type

str

read_utf(field_name)[source]

Reads a UTF-8 String.

Deprecated since version 4.1: This method is deprecated and will be removed in the next major version. Use read_string() instead.

Parameters

field_name (str) – Name of the field.

Returns

The UTF-8 String read.

Return type

str

read_boolean(field_name)[source]

Reads a primitive bool.

Parameters

field_name (str) – Name of the field.

Returns

The bool value read.

Return type

bool

read_byte(field_name)[source]

Reads a primitive byte.

Parameters

field_name (str) – Name of the field.

Returns

The byte value read.

Return type

int

read_char(field_name)[source]

Reads a primitive char.

Parameters

field_name (str) – Name of the field.

Returns

The char value read.

Return type

str

read_double(field_name)[source]

Reads a primitive double.

Parameters

field_name (str) – Name of the field.

Returns

The double value read.

Return type

float

read_float(field_name)[source]

Reads a primitive float.

Parameters

field_name (str) – Name of the field.

Returns

The float value read.

Return type

float

read_short(field_name)[source]

Reads a primitive short.

Parameters

field_name (str) – Name of the field.

Returns

The short value read.

Return type

int

read_portable(field_name)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

Reads a primitive short array.

Parameters

field_name (str) – Name of the field.

Returns

The short array read.

Return type

list[int]

read_string_array(field_name)[source]

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_utf_array(field_name)[source]

Reads a UTF-8 String array.

Deprecated since version 4.1: This method is deprecated and will be removed in the next major version. Use read_string_array() instead.

Parameters

field_name (str) – Name of the field.

Returns

The UTF-8 String array read.

Return type

str

read_portable_array(field_name)[source]

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()[source]

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[source]

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)[source]

Writes a primitive int.

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

  • value (int) – Int value to be written.

write_long(field_name, value)[source]

Writes a primitive long.

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

  • value (int) – Long value to be written.

write_string(field_name, value)[source]

Writes an UTF string.

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

  • value (str) – UTF string value to be written.

write_utf(field_name, value)[source]

Writes an UTF string.

Deprecated since version 4.1: This method is deprecated and will be removed in the next major version. Use write_string() instead.

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

  • value (str) – UTF string value to be written.

write_boolean(field_name, value)[source]

Writes a primitive bool.

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

  • value (bool) – Bool value to be written.

write_byte(field_name, value)[source]

Writes a primitive byte.

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

  • value (int) – Byte value to be written.

write_char(field_name, value)[source]

Writes a primitive char.

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

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

write_double(field_name, value)[source]

Writes a primitive double.

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

  • value (float) – Double value to be written.

write_float(field_name, value)[source]

Writes a primitive float.

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

  • value (float) – Float value to be written.

write_short(field_name, value)[source]

Writes a primitive short.

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

  • value (int) – Short value to be written.

write_portable(field_name, portable)[source]

Writes a Portable.

Parameters
write_null_portable(field_name, factory_id, class_id)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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)[source]

Writes a primitive short array.

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

  • values – (list[int]): Short array to be written.

write_string_array(field_name, values)[source]

Writes a UTF-8 String array.

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

  • values – (str): UTF-8 String array to be written.

write_utf_array(field_name, values)[source]

Writes a UTF-8 String array.

Deprecated since version 4.1: This method is deprecated and will be removed in the next major version. Use write_string_array() instead.

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

  • values – (str): UTF-8 String array to be written.

write_portable_array(field_name, values)[source]

Writes a portable array.

Parameters
get_raw_data_output()[source]

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