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: bytearray, offset: int = None, length: int = None) None[source]

Writes the content of the buffer to this output stream.

Parameters:
  • buff – Input buffer.

  • offset – Offset of the buffer where copy begin.

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

write_boolean(val: bool) None[source]

Writes a bool value to this output stream.

Single byte value 1 represent True, 0 represent False

Parameters:

val – The bool to be written.

write_byte(val: int) None[source]

Writes a byte value to this output stream.

Parameters:

val – The byte value to be written.

write_short(val: int) None[source]

Writes a short value to this output stream.

Parameters:

val – The short value to be written.

write_char(val: str) None[source]

Writes a char value to this output stream.

Parameters:

val – The char value to be written.

write_int(val: int) None[source]

Writes an int value to this output stream.

Parameters:

val – The int value to be written.

write_long(val: int) None[source]

Writes a long value to this output stream.

Parameters:

val – The long value to be written.

write_float(val: float) None[source]

Writes a float value to this output stream.

Parameters:

val – The float value to be written.

write_double(val: float) None[source]

Writes a double value to this output stream.

Parameters:

val – The double value to be written.

write_bytes(val: str) None[source]

Writes a string to this output stream.

Parameters:

val – The string to be written.

write_chars(val: str) None[source]

Writes every character of string to this output stream.

Parameters:

val – The string to be written.

write_string(val: str) None[source]

Writes UTF-8 string to this output stream.

Parameters:

val – The UTF-8 string to be written.

write_utf(val: str) None[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 – The UTF-8 string to be written.

write_byte_array(val: bytearray) None[source]

Writes a byte array to this output stream.

Parameters:

val – The byte array to be written.

write_boolean_array(val: Sequence[bool]) None[source]

Writes a bool array to this output stream.

Parameters:

val – The bool array to be written.

write_char_array(val: Sequence[str]) None[source]

Writes a char array to this output stream.

Parameters:

val – The char array to be written.

write_int_array(val: Sequence[int]) None[source]

Writes a int array to this output stream.

Parameters:

val – The int array to be written.

write_long_array(val: Sequence[int]) None[source]

Writes a long array to this output stream.

Parameters:

val – The long array to be written.

write_double_array(val: Sequence[float]) None[source]

Writes a double array to this output stream.

Parameters:

val – The double array to be written.

write_float_array(val: Sequence[float]) None[source]

Writes a float array to this output stream.

Parameters:

val – The float array to be written.

write_short_array(val: Sequence[int]) None[source]

Writes a short array to this output stream.

Parameters:

val – The short array to be written.

write_string_array(val: Sequence[str]) None[source]

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

Parameters:

val – The UTF-8 String array to be written.

write_utf_array(val: Sequence[str]) None[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 – The UTF-8 String array to be written.

write_object(val: Any) None[source]

Writes an object to this output stream.

Parameters:

val – The object to be written.

to_byte_array() bytearray[source]

Returns a copy of internal byte array.

Returns:

The copy of internal byte array

get_byte_order() str[source]

Returns the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.

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: bytearray, offset: int = None, length: int = None) bytearray[source]

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

Parameters:
  • buff – Input buffer.

  • offset – Offset of the buffer where the read begin.

  • length – Length of data to be read.

Returns:

The read data.

skip_bytes(count: int) int[source]

Skips over given number of bytes from input stream.

Parameters:

count – Number of bytes to be skipped.

Returns:

The actual number of bytes skipped.

read_boolean() bool[source]

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

Returns:

The bool value read.

read_byte() int[source]

Reads 1 byte from input stream and returns it.

Returns:

The byte value read.

read_unsigned_byte() int[source]

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

Returns:

The unsigned byte value read.

read_short() int[source]

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

Returns:

The short value read.

read_unsigned_short() int[source]

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

Returns:

The unsigned short value read.

read_char() str[source]

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

Returns:

The char value read.

read_int() int[source]

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

Returns:

The int value read.

read_long() int[source]

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

Returns:

The int value read.

read_float() float[source]

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

Returns:

The float value read.

read_double() float[source]

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

Returns:

The double value read.

read_string() str[source]

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

Returns:

The UTF-8 string read.

read_utf() str[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.

read_byte_array() bytearray[source]

Reads a byte array from input stream and returns it.

Returns:

The byte array read.

read_boolean_array() List[bool][source]

Reads a bool array from input stream and returns it.

Returns:

The bool array read.

read_char_array() List[str][source]

Reads a char array from input stream and returns it.

Returns:

The char array read.

read_int_array() List[int][source]

Reads a int array from input stream and returns it.

Returns:

The int array read.

read_long_array() List[int][source]

Reads a long array from input stream and returns it.

Returns:

The long array read.

read_double_array() List[float][source]

Reads a double array from input stream and returns it.

Returns:

The double array read.

read_float_array() List[float][source]

Reads a float array from input stream and returns it.

Returns:

The float array read.

read_short_array() List[int][source]

Reads a short array from input stream and returns it.

Returns:

The short array read.

read_string_array() List[str][source]

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

Returns:

The UTF-8 string array read.

read_utf_array() List[str][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.

read_object() Any[source]

Reads an object from input stream and returns it.

Returns:

The object read.

get_byte_order() str[source]

Returns the order of bytes, as BIG_ENDIAN or LITTLE_ENDIAN.

position() int[source]

Returns current position in buffer.

Returns:

Current position in buffer.

size() int[source]

Returns size of buffer.

Returns:

Size of buffer.

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

Writes object fields to output stream.

Parameters:

object_data_output – The output.

read_data(object_data_input: ObjectDataInput) None[source]

Reads fields from the input stream.

Parameters:

object_data_input – The input.

get_factory_id() int[source]

Returns DataSerializableFactory factory id for this class.

Returns:

The factory id.

get_class_id() int[source]

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

Returns:

The type id.

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

Serialize this portable object using given PortableWriter.

Parameters:

writer – The PortableWriter.

read_portable(reader: PortableReader) None[source]

Read portable fields using PortableReader.

Parameters:

reader – The PortableReader.

get_factory_id() int[source]

Returns PortableFactory id for this portable class

Returns:

The factory id.

get_class_id() int[source]

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

Returns:

The class id.

class StreamSerializer[source]

Bases: object

A base class for custom serialization.

write(out: ObjectDataOutput, obj: Any) None[source]

Writes object to ObjectDataOutput

Parameters:
  • out – Stream that object will be written to.

  • obj – The object to be written.

read(inp: ObjectDataInput) Any[source]

Reads object from objectDataInputStream

Parameters:

inp – Stream that object will read from.

Returns:

The read object.

get_type_id() int[source]

Returns typeId of serializer.

Returns:

The type id of the serializer.

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

Returns the global version of portable classes.

Returns:

Global version of portable classes.

has_field(field_name: str) bool[source]

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

Parameters:

field_name – name of the field (does not support nested paths).

Returns:

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

get_field_names() Set[str][source]

Returns the set of field names on this portable class.

Returns:

Set of field names on this portable class.

get_field_type(field_name: str) FieldType[source]

Returns the field type of given field name.

Parameters:

field_name – Name of the field.

Returns:

The field type.

get_field_class_id(field_name: str) int[source]

Returns the class id of given field.

Parameters:

field_name – Name of the field.

Returns:

Class id of given field.

read_int(field_name: str) int[source]

Reads a primitive int.

Parameters:

field_name – Name of the field.

Returns:

The int value read.

read_long(field_name: str) int[source]

Reads a primitive long.

Parameters:

field_name – Name of the field.

Returns:

The long value read.

read_string(field_name: str) str[source]

Reads a UTF-8 String.

Parameters:

field_name – Name of the field.

Returns:

The UTF-8 String read.

read_utf(field_name: str) str[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 – Name of the field.

Returns:

The UTF-8 String read.

read_boolean(field_name: str) bool[source]

Reads a primitive bool.

Parameters:

field_name – Name of the field.

Returns:

The bool value read.

read_byte(field_name: str) int[source]

Reads a primitive byte.

Parameters:

field_name – Name of the field.

Returns:

The byte value read.

read_char(field_name: str) str[source]

Reads a primitive char.

Parameters:

field_name – Name of the field.

Returns:

The char value read.

read_double(field_name: str) float[source]

Reads a primitive double.

Parameters:

field_name – Name of the field.

Returns:

The double value read.

read_float(field_name: str) float[source]

Reads a primitive float.

Parameters:

field_name – Name of the field.

Returns:

The float value read.

read_short(field_name: str) int[source]

Reads a primitive short.

Parameters:

field_name – Name of the field.

Returns:

The short value read.

read_portable(field_name: str) Portable[source]

Reads a portable.

Parameters:

field_name – Name of the field.

Returns:

The portable read.

read_decimal(field_name: str) Decimal[source]

Reads a decimal.

Parameters:

field_name – Name of the field.

Returns:

The decimal read.

read_time(field_name: str) time[source]

Reads a time.

Parameters:

field_name – Name of the field.

Returns:

The time read.

read_date(field_name: str) date[source]

Reads a date.

Parameters:

field_name – Name of the field.

Returns:

The date read.

read_timestamp(field_name: str) datetime[source]

Reads a timestamp.

Parameters:

field_name – Name of the field.

Returns:

The timestamp read.

read_timestamp_with_timezone(field_name: str) datetime[source]

Reads a timestamp with timezone.

Parameters:

field_name – Name of the field.

Returns:

The timestamp with timezone read.

read_byte_array(field_name: str) bytearray[source]

Reads a primitive byte array.

Parameters:

field_name – Name of the field.

Returns:

The byte array read.

read_boolean_array(field_name: str) List[bool][source]

Reads a primitive bool array.

Parameters:

field_name – Name of the field.

Returns:

The bool array read.

read_char_array(field_name: str) List[str][source]

Reads a primitive char array.

Parameters:

field_name – Name of the field.

Returns:

The char array read.

read_int_array(field_name: str) List[int][source]

Reads a primitive int array.

Parameters:

field_name – Name of the field.

Returns:

The int array read.

read_long_array(field_name: str) List[int][source]

Reads a primitive long array.

Parameters:

field_name – Name of the field.

Returns:

The long array read.

read_double_array(field_name: str) List[float][source]

Reads a primitive double array.

Parameters:

field_name – Name of the field.

Returns:

The double array read.

read_float_array(field_name: str) List[float][source]

Reads a primitive float array.

Parameters:

field_name – Name of the field.

Returns:

The float array read.

read_short_array(field_name: str) List[int][source]

Reads a primitive short array.

Parameters:

field_name – Name of the field.

Returns:

The short array read.

read_string_array(field_name: str) List[str][source]

Reads a UTF-8 String array.

Parameters:

field_name – Name of the field.

Returns:

The UTF-8 String array read.

read_utf_array(field_name: str) List[str][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 – Name of the field.

Returns:

The UTF-8 String array read.

read_decimal_array(field_name: str) List[Decimal][source]

Reads a decimal array.

Parameters:

field_name – Name of the field.

Returns:

The decimal array read.

read_time_array(field_name: str) List[time][source]

Reads a time array.

Parameters:

field_name – Name of the field.

Returns:

The time array read.

read_date_array(field_name: str) List[date][source]

Reads a date array.

Parameters:

field_name – Name of the field.

Returns:

The date array read.

read_timestamp_array(field_name: str) List[datetime][source]

Reads a timestamp array.

Parameters:

field_name – Name of the field.

Returns:

The timestamp array read.

read_timestamp_with_timezone_array(field_name: str) List[datetime][source]

Reads a timestamp with timezone array.

Parameters:

field_name – Name of the field.

Returns:

The timestamp with timezone array read.

read_portable_array(field_name: str) List[Portable][source]

Reads a portable array.

Parameters:

field_name – Name of the field.

Returns:

The portable array read.

get_raw_data_input() ObjectDataInput[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.

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: str, value: int) None[source]

Writes a primitive int.

Parameters:
  • field_name – Name of the field.

  • value – Int value to be written.

write_long(field_name: str, value: int) None[source]

Writes a primitive long.

Parameters:
  • field_name – Name of the field.

  • value – Long value to be written.

write_string(field_name: str, value: str) None[source]

Writes an UTF string.

Parameters:
  • field_name – Name of the field.

  • value – UTF string value to be written.

write_utf(field_name: str, value: str) None[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 – Name of the field.

  • value – UTF string value to be written.

write_boolean(field_name: str, value: bool) None[source]

Writes a primitive bool.

Parameters:
  • field_name – Name of the field.

  • value – Bool value to be written.

write_byte(field_name: str, value: int) None[source]

Writes a primitive byte.

Parameters:
  • field_name – Name of the field.

  • value – Byte value to be written.

write_char(field_name: str, value: str) None[source]

Writes a primitive char.

Parameters:
  • field_name – Name of the field.

  • value – Char value to be written.

write_double(field_name: str, value: float) None[source]

Writes a primitive double.

Parameters:
  • field_name – Name of the field.

  • value – Double value to be written.

write_float(field_name: str, value: float) None[source]

Writes a primitive float.

Parameters:
  • field_name – Name of the field.

  • value – Float value to be written.

write_short(field_name: str, value: int) None[source]

Writes a primitive short.

Parameters:
  • field_name – Name of the field.

  • value – Short value to be written.

write_portable(field_name: str, portable: Portable) None[source]

Writes a Portable.

Parameters:
  • field_name – Name of the field.

  • portable – Portable to be written.

write_null_portable(field_name: str, factory_id: int, class_id: int) None[source]

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

Parameters:
  • field_name – Name of the field.

  • factory_id – Factory id of related portable class.

  • class_id – Class id of related portable class.

write_decimal(field_name: str, value: Decimal) None[source]

Writes a decimal.

Parameters:
  • field_name – Name of the field.

  • value – Decimal to be written.

write_time(field_name: str, value: time) None[source]

Writes a time.

Parameters:
  • field_name – Name of the field.

  • value – Time to be written.

write_date(field_name: str, value: date) None[source]

Writes a date.

Parameters:
  • field_name – Name of the field.

  • value – Date to be written.

write_timestamp(field_name: str, value: datetime) None[source]

Writes a timestamp.

Parameters:
  • field_name – Name of the field.

  • value – Timestamp to be written.

write_timestamp_with_timezone(field_name: str, value: datetime) None[source]

Writes a timestamp with timezone.

Parameters:
  • field_name – Name of the field.

  • value – Timestamp with timezone to be written.

write_byte_array(field_name: str, values: bytearray) None[source]

Writes a primitive byte array.

Parameters:
  • field_name – Name of the field.

  • values – Bytearray to be written.

write_boolean_array(field_name: str, values: Sequence[bool]) None[source]

Writes a primitive bool array.

Parameters:
  • field_name – Name of the field.

  • values – Bool array to be written.

write_char_array(field_name: str, values: Sequence[str]) None[source]

Writes a primitive char array.

Parameters:
  • field_name – Name of the field.

  • values – Char array to be written.

write_int_array(field_name: str, values: Sequence[int]) None[source]

Writes a primitive int array.

Parameters:
  • field_name – Name of the field.

  • values – Int array to be written.

write_long_array(field_name: str, values: Sequence[int]) None[source]

Writes a primitive long array.

Parameters:
  • field_name – Name of the field.

  • values – Long array to be written.

write_double_array(field_name: str, values: Sequence[float]) None[source]

Writes a primitive double array.

Parameters:
  • field_name – Name of the field.

  • values – Double array to be written.

write_float_array(field_name: str, values: Sequence[float]) None[source]

Writes a primitive float array.

Parameters:
  • field_name – Name of the field.

  • values – Float array to be written.

write_short_array(field_name: str, values: Sequence[int]) None[source]

Writes a primitive short array.

Parameters:
  • field_name – Name of the field.

  • values – Short array to be written.

write_string_array(field_name: str, values: Sequence[str]) None[source]

Writes a UTF-8 String array.

Parameters:
  • field_name – Name of the field.

  • values – UTF-8 String array to be written.

write_utf_array(field_name: str, values: Sequence[str]) None[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 – Name of the field.

  • values – UTF-8 String array to be written.

write_decimal_array(field_name: str, values: Sequence[Decimal]) None[source]

Writes a decimal array.

Parameters:
  • field_name – Name of the field.

  • values – Decimal array to be written.

write_time_array(field_name: str, values: Sequence[time]) None[source]

Writes a time array.

Parameters:
  • field_name – Name of the field.

  • values – Time array to be written.

write_date_array(field_name: str, values: Sequence[date]) None[source]

Writes a date array.

Parameters:
  • field_name – Name of the field.

  • values – Date array to be written.

write_timestamp_array(field_name: str, values: Sequence[datetime]) None[source]

Writes a timestamp array.

Parameters:
  • field_name – Name of the field.

  • values – Timestamp array to be written.

write_timestamp_with_timezone_array(field_name: str, values: Sequence[datetime]) None[source]

Writes a timestamp with timezone array.

Parameters:
  • field_name – Name of the field.

  • values – Timestamp with timezone array to be written.

write_portable_array(field_name: str, values: Sequence[Portable]) None[source]

Writes a portable array.

Parameters:
  • field_name – Name of the field.

  • values – Portable array to be written.

get_raw_data_output() ObjectDataOutput[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.

class CompactReader[source]

Bases: ABC

Provides means of reading Compact serialized fields from the binary data.

Read operations might throw hazelcast.errors.HazelcastSerializationError when a field with the given name is not found or there is a type mismatch.

The way to use CompactReader for class evolution is to check for the existence of a field with its name and kind, with the get_field_kind() method. One should read the field if it exists with the given name and kind, and use some other logic, like using a default value, if it does not exist.

def read(self, reader: CompactReader) -> Foo:
    bar = reader.read_int32("bar") # A field that is always present
    if reader.get_field_kind("baz") == FieldKind.STRING:
        baz = reader.read_string("baz")
    else:
        baz = "" # Use a default value, if the field is not present
    return Foo(bar, baz)
abstract get_field_kind(field_name: str) FieldKind[source]

Returns the kind of the field for the given name.

If the field with the given name does not exist, FieldKind.NOT_AVAILABLE is returned.

This method can be used to check the existence of a field, which can be useful when the class is evolved.

Parameters:

field_name – Name of the field.

Returns:

Kind of the field.

abstract read_boolean(field_name: str) bool[source]

Reads a boolean.

This method can also read a nullable boolean, as long as it is not None.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema, or a None nullable boolean value is read.

abstract read_nullable_boolean(field_name: str) bool | None[source]

Reads a nullable boolean.

This method can also read a non-nullable boolean.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_int8(field_name: str) int[source]

Reads an 8-bit two’s complement signed integer.

This method can also read a nullable int8, as long as it is not None.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema, or a None nullable int8 value is read.

abstract read_nullable_int8(field_name: str) int | None[source]

Reads a nullable 8-bit two’s complement signed integer.

This method can also read a non-nullable int8.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_int16(field_name: str) int[source]

Reads a 16-bit two’s complement signed integer.

This method can also read a nullable int16, as long as it is not None.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema, or a None nullable int16 value is read.

abstract read_nullable_int16(field_name: str) int | None[source]

Reads a nullable 16-bit two’s complement signed integer.

This method can also read a non-nullable int16.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_int32(field_name: str) int[source]

Reads a 32-bit two’s complement signed integer.

This method can also read a nullable int32, as long as it is not None.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema, or a None nullable int32 value is read.

abstract read_nullable_int32(field_name: str) int | None[source]

Reads a nullable 32-bit two’s complement signed integer.

This method can also read a non-nullable int32.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_int64(field_name: str) int[source]

Reads a 64-bit two’s complement signed integer.

This method can also read a nullable int64, as long as it is not None.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema, or a None nullable int64 value is read.

abstract read_nullable_int64(field_name: str) int | None[source]

Reads a nullable 64-bit two’s complement signed integer.

This method can also read a non-nullable int64.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_float32(field_name: str) float[source]

Reads a 32-bit IEEE 754 floating point number.

This method can also read a nullable float32, as long as it is not None.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema, or a None nullable float32 value is read.

abstract read_nullable_float32(field_name: str) float | None[source]

Reads a nullable 32-bit IEEE 754 floating point number.

This method can also read a non-nullable float32.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_float64(field_name: str) float[source]

Reads a 64-bit IEEE 754 floating point number.

This method can also read a nullable float64, as long as it is not None.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema, or a None nullable float64 value is read.

abstract read_nullable_float64(field_name: str) float | None[source]

Reads a nullable 64-bit IEEE 754 floating point number.

This method can also read a non-nullable float64.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_string(field_name: str) str | None[source]

Reads a UTF-8 encoded string.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_decimal(field_name: str) Decimal | None[source]

Reads an arbitrary precision and scale floating point number.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_time(field_name: str) time | None[source]

Reads a time consisting of hour, minute, second, and nanoseconds.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_date(field_name: str) date | None[source]

Reads a date consisting of year, month, and day.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_timestamp(field_name: str) datetime | None[source]

Reads a timestamp consisting of date and time.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_timestamp_with_timezone(field_name: str) datetime | None[source]

Reads a timestamp with timezone consisting of date, time and timezone offset.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_compact(field_name: str) Any | None[source]

Reads a compact object.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_boolean(field_name: str) List[bool] | None[source]

Reads an array of booleans.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_nullable_boolean(field_name: str) List[bool | None] | None[source]

Reads an array of nullable booleans.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_int8(field_name: str) List[int] | None[source]

Reads an array of 8-bit two’s complement signed integers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_nullable_int8(field_name: str) List[int | None] | None[source]

Reads an array of nullable 8-bit two’s complement signed integers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_int16(field_name: str) List[int] | None[source]

Reads an array of 16-bit two’s complement signed integers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_nullable_int16(field_name: str) List[int | None] | None[source]

Reads an array of nullable 16-bit two’s complement signed integers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_int32(field_name: str) List[int] | None[source]

Reads an array of 32-bit two’s complement signed integers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_nullable_int32(field_name: str) List[int | None] | None[source]

Reads an array of nullable 32-bit two’s complement signed integers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_int64(field_name: str) List[int] | None[source]

Reads an array of 64-bit two’s complement signed integers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_nullable_int64(field_name: str) List[int | None] | None[source]

Reads an array of nullable 64-bit two’s complement signed integers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_float32(field_name: str) List[float] | None[source]

Reads an array of 32-bit IEEE 754 floating point numbers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_nullable_float32(field_name: str) List[float | None] | None[source]

Reads an array of nullable 32-bit IEEE 754 floating point numbers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_float64(field_name: str) List[float] | None[source]

Reads an array of 64-bit IEEE 754 floating point numbers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_nullable_float64(field_name: str) List[float | None] | None[source]

Reads an array of nullable 64-bit IEEE 754 floating point numbers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_string(field_name: str) List[str | None] | None[source]

Reads an array of UTF-8 encoded strings.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_decimal(field_name: str) List[Decimal | None] | None[source]

Reads an array of arbitrary precision and scale floating point numbers.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_time(field_name: str) List[time | None] | None[source]

Reads an array of times consisting of hour, minute, second, and nanoseconds.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_date(field_name: str) List[date | None] | None[source]

Reads an array of dates consisting of year, month, and day.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_timestamp(field_name: str) List[datetime | None] | None[source]

Reads an array of timestamps consisting of date and time.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_timestamp_with_timezone(field_name: str) List[datetime | None] | None[source]

Reads an array of timestamp with timezones consisting of date, time and timezone offset.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

abstract read_array_of_compact(field_name: str) List[Any | None] | None[source]

Reads an array of compact objects.

Parameters:

field_name – Name of the field.

Returns:

The value of the field.

Raises:

HazelcastSerializationError – If the field does not exist in the schema or the type of the field does not match with the one defined in the schema.

class CompactWriter[source]

Bases: ABC

Provides means of writing compact serialized fields to the binary data.

abstract write_boolean(field_name: str, value: bool) None[source]

Writes a boolean.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_nullable_boolean(field_name: str, value: bool | None) None[source]

Writes a nullable boolean.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_int8(field_name: str, value: int) None[source]

Writes an 8-bit two’s complement signed integer.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_nullable_int8(field_name: str, value: int | None) None[source]

Writes a nullable 8-bit two’s complement signed integer.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_int16(field_name: str, value: int) None[source]

Writes a 16-bit two’s complement signed integer.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_nullable_int16(field_name: str, value: int | None) None[source]

Writes a nullable 16-bit two’s complement signed integer.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_int32(field_name: str, value: int) None[source]

Writes a 32-bit two’s complement signed integer.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_nullable_int32(field_name: str, value: int | None) None[source]

Writes a nullable 32-bit two’s complement signed integer.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_int64(field_name: str, value: int) None[source]

Writes a 64-bit two’s complement signed integer.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_nullable_int64(field_name: str, value: int | None) None[source]

Writes a nullable 64-bit two’s complement signed integer.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_float32(field_name: str, value: float) None[source]

Writes a 32-bit IEEE 754 floating point number.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_nullable_float32(field_name: str, value: float | None) None[source]

Writes a nullable 32-bit IEEE 754 floating point number.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_float64(field_name: str, value: float) None[source]

Writes a 64-bit IEEE 754 floating point number.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_nullable_float64(field_name: str, value: float | None) None[source]

Writes a nullable 64-bit IEEE 754 floating point number.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_string(field_name: str, value: str | None) None[source]

Writes an UTF-8 encoded string.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_decimal(field_name: str, value: Decimal | None) None[source]

Writes an arbitrary precision and scale floating point number.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_time(field_name: str, value: time | None) None[source]

Writes a time consisting of hour, minute, second, and nanoseconds.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_date(field_name: str, value: date | None) None[source]

Writes a date consisting of year, month, and day.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_timestamp(field_name: str, value: datetime | None) None[source]

Writes a timestamp consisting of date and time.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_timestamp_with_timezone(field_name: str, value: datetime | None) None[source]

Writes a timestamp with timezone consisting of date, time, and timezone offset.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_compact(field_name: str, value: Any | None) None[source]

Writes a nested compact object.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_boolean(field_name: str, value: List[bool] | None) None[source]

Writes an array of booleans.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_nullable_boolean(field_name: str, value: List[bool | None] | None) None[source]

Writes an array of nullable booleans.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_int8(field_name: str, value: List[int] | None) None[source]

Writes an array of 8-bit two’s complement signed integers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_nullable_int8(field_name: str, value: List[int | None] | None) None[source]

Writes an array of nullable 8-bit two’s complement signed integers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_int16(field_name: str, value: List[int] | None) None[source]

Writes an array of 16-bit two’s complement signed integers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_nullable_int16(field_name: str, value: List[int | None] | None) None[source]

Writes an array of nullable 16-bit two’s complement signed integers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_int32(field_name: str, value: List[int] | None) None[source]

Writes an array of 32-bit two’s complement signed integers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_nullable_int32(field_name: str, value: List[int | None] | None) None[source]

Writes an array of nullable 32-bit two’s complement signed integers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_int64(field_name: str, value: List[int] | None) None[source]

Writes an array of 64-bit two’s complement signed integers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_nullable_int64(field_name: str, value: List[int | None] | None) None[source]

Writes an array of nullable 64-bit two’s complement signed integers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_float32(field_name: str, value: List[float] | None) None[source]

Writes an array of 32-bit IEEE 754 floating point numbers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_nullable_float32(field_name: str, value: List[float | None] | None) None[source]

Writes an array of nullable 32-bit IEEE 754 floating point numbers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_float64(field_name: str, value: List[float] | None) None[source]

Writes an array of 64-bit IEEE 754 floating point numbers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_nullable_float64(field_name: str, value: List[float | None] | None) None[source]

Writes an array of nullable 64-bit IEEE 754 floating point numbers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_string(field_name: str, value: List[str | None] | None) None[source]

Writes an array of UTF-8 encoded strings.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_decimal(field_name: str, value: List[Decimal | None] | None) None[source]

Writes an array of arbitrary precision and scale floating point numbers.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_time(field_name: str, value: List[time | None] | None) None[source]

Writes an array of times consisting of hour, minute, second, and nanoseconds.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_date(field_name: str, value: List[date | None] | None) None[source]

Writes an array of dates consisting of year, month, and day.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_timestamp(field_name: str, value: List[datetime | None] | None) None[source]

Writes an array of timestamps consisting of date and time.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_timestamp_with_timezone(field_name: str, value: List[datetime | None] | None) None[source]

Writes an array of timestamps with timezone consisting of date, time, and timezone offset.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

abstract write_array_of_compact(field_name: str, value: List[Any | None] | None) None[source]

Writes an array of nested compact objects.

Parameters:
  • field_name – Name of the field.

  • value – Value to be written.

Raises:

hazelcast.errors.HazelcastSerializationError – If the list contains different item types.

class CompactSerializableType

Type of the Compact serializable classes.

alias of TypeVar(‘CompactSerializableType’)

class CompactSerializer[source]

Bases: Generic[CompactSerializableType], ABC

Defines the contract of the serializers used for Compact serialization.

After defining a serializer for the objects of the class CompactSerializableType, the serializer can be registered to the hazelcast.config.Config.compact_serializers.

write() and read() methods must be consistent with each other.

abstract read(reader: CompactReader) CompactSerializableType[source]

Deserializes the object from the reader.

Parameters:

reader – Reader to read fields of an object.

Returns:

The object read.

Raises:

hazelcast.errors.HazelcastSerializationError – In case of failure to read.

abstract write(writer: CompactWriter, obj: CompactSerializableType) None[source]

Serializes the object to writer.

Parameters:
  • writer – Writer to serialize the fields.

  • obj – Object to be serialized.

Raises:

hazelcast.errors.HazelcastSerializationError – In case of failure to write.

abstract get_class() Type[CompactSerializableType][source]

Returns the class that this serializer reads or writes.

Returns:

The class that this serializer reads or writes.

abstract get_type_name() str[source]

Returns the unique type name associated with :const`CompactSerializableType`.

If the class is ever evolved by adding or removing fields, the type name for the evolved serializers must be the same with the initial version.

Returns:

The type name.

class FieldKind(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Represents the types of the fields used in the Compact serialization.

NOT_AVAILABLE = 0

Represents fields that do not exist.

BOOLEAN = 1
ARRAY_OF_BOOLEAN = 2
INT8 = 3
ARRAY_OF_INT8 = 4
CHAR = 5
ARRAY_OF_CHAR = 6
INT16 = 7
ARRAY_OF_INT16 = 8
INT32 = 9
ARRAY_OF_INT32 = 10
INT64 = 11
ARRAY_OF_INT64 = 12
FLOAT32 = 13
ARRAY_OF_FLOAT32 = 14
FLOAT64 = 15
ARRAY_OF_FLOAT64 = 16
STRING = 17
ARRAY_OF_STRING = 18
DECIMAL = 19
ARRAY_OF_DECIMAL = 20
TIME = 21
ARRAY_OF_TIME = 22
DATE = 23
ARRAY_OF_DATE = 24
TIMESTAMP = 25
ARRAY_OF_TIMESTAMP = 26
TIMESTAMP_WITH_TIMEZONE = 27
ARRAY_OF_TIMESTAMP_WITH_TIMEZONE = 28
COMPACT = 29
ARRAY_OF_COMPACT = 30
PORTABLE = 31
ARRAY_OF_PORTABLE = 32
NULLABLE_BOOLEAN = 33
ARRAY_OF_NULLABLE_BOOLEAN = 34
NULLABLE_INT8 = 35
ARRAY_OF_NULLABLE_INT8 = 36
NULLABLE_INT16 = 37
ARRAY_OF_NULLABLE_INT16 = 38
NULLABLE_INT32 = 39
ARRAY_OF_NULLABLE_INT32 = 40
NULLABLE_INT64 = 41
ARRAY_OF_NULLABLE_INT64 = 42
NULLABLE_FLOAT32 = 43
ARRAY_OF_NULLABLE_FLOAT32 = 44
NULLABLE_FLOAT64 = 45
ARRAY_OF_NULLABLE_FLOAT64 = 46