Interface CompactReader


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

Read operations might throw HazelcastSerializationException 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 getFieldKind(String) 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.


 public Foo read(CompactReader reader) {
     int bar = reader.readInt32("bar");  // A field that is always present
     String baz;
     if (reader.getFieldKind("baz") == FieldKind.STRING) {
         baz = reader.readString("baz");
     } else {
         baz = ""; // Use a default value, if the field is not present
     }
     return new Foo(bar, baz);
 }
 
Since:
5.2
  • Method Details

    • getFieldKind

      @Nonnull FieldKind getFieldKind(@Nonnull String fieldName)
      Returns the kind of the field for the given field 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:
      fieldName - name of the field.
      Returns:
      kind of the field
    • readBoolean

      boolean readBoolean(@Nonnull String fieldName)
      Reads a boolean.

      This method can also read a nullable boolean, as long as it is not null. If a null value is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readInt8

      byte readInt8(@Nonnull String fieldName)
      Reads an 8-bit two's complement signed integer.

      This method can also read a nullable int8, as long as it is not null. If a null value is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readInt16

      short readInt16(@Nonnull String fieldName)
      Reads a 16-bit two's complement signed integer.

      This method can also read a nullable int16, as long as it is not null. If a null value is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readInt32

      int readInt32(@Nonnull String fieldName)
      Reads a 32-bit two's complement signed integer.

      This method can also read a nullable int32, as long as it is not null. If a null value is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readInt64

      long readInt64(@Nonnull String fieldName)
      Reads a 64-bit two's complement signed integer.

      This method can also read a nullable int64, as long as it is not null. If a null value is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readFloat32

      float readFloat32(@Nonnull String fieldName)
      Reads a 32-bit IEEE 754 floating point number.

      This method can also read a nullable float32, as long as it is not null. If a null value is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readFloat64

      double readFloat64(@Nonnull String fieldName)
      Reads a 64-bit IEEE 754 floating point number.

      This method can also read a nullable float64, as long as it is not null. If a null value is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readString

      @Nullable String readString(@Nonnull String fieldName)
      Reads an UTF-8 encoded string.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readDecimal

      @Nullable BigDecimal readDecimal(@Nonnull String fieldName)
      Reads an arbitrary precision and scale floating point number.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readTime

      @Nullable LocalTime readTime(@Nonnull String fieldName)
      Reads a time consisting of hour, minute, second, and nano seconds.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readDate

      @Nullable LocalDate readDate(@Nonnull String fieldName)
      Reads a date consisting of year, month, and day.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readTimestamp

      @Nullable LocalDateTime readTimestamp(@Nonnull String fieldName)
      Reads a timestamp consisting of date and time.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readTimestampWithTimezone

      @Nullable OffsetDateTime readTimestampWithTimezone(@Nonnull String fieldName)
      Reads a timestamp with timezone consisting of date, time and timezone offset.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readCompact

      @Nullable <T> T readCompact(@Nonnull String fieldName)
      Reads a compact object
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
      HazelcastException - if the object cannot be created.
    • readArrayOfBoolean

      @Nullable boolean[] readArrayOfBoolean(@Nonnull String fieldName)
      Reads an array of booleans.

      This method can also read an array of nullable booleans, as long as it does not contain null values. If a null array item is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfInt8

      @Nullable byte[] readArrayOfInt8(@Nonnull String fieldName)
      Reads an array of 8-bit two's complement signed integers.

      This method can also read an array of nullable int8s, as long as it does not contain null values. If a null array item is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfInt16

      @Nullable short[] readArrayOfInt16(@Nonnull String fieldName)
      Reads an array of 16-bit two's complement signed integers.

      This method can also read an array of nullable int16s, as long as it does not contain null values. If a null array item is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfInt32

      @Nullable int[] readArrayOfInt32(@Nonnull String fieldName)
      Reads an array of 32-bit two's complement signed integers.

      This method can also read an array of nullable int32s, as long as it does not contain null values. If a null array item is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfInt64

      @Nullable long[] readArrayOfInt64(@Nonnull String fieldName)
      Reads an array of 64-bit two's complement signed integers.

      This method can also read an array of nullable int64s, as long as it does not contain null values. If a null array item is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfFloat32

      @Nullable float[] readArrayOfFloat32(@Nonnull String fieldName)
      Reads an array of 32-bit IEEE 754 floating point numbers.

      This method can also read an array of nullable float32s, as long as it does not contain null values. If a null array item is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfFloat64

      @Nullable double[] readArrayOfFloat64(@Nonnull String fieldName)
      Reads an array of 64-bit IEEE 754 floating point numbers.

      This method can also read an array of nullable float64s, as long as it does not contain null values. If a null array item is read with this method, HazelcastSerializationException is thrown.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfString

      @Nullable String[] readArrayOfString(@Nonnull String fieldName)
      Reads an array of UTF-8 encoded strings.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfDecimal

      @Nullable BigDecimal[] readArrayOfDecimal(@Nonnull String fieldName)
      Reads an array of arbitrary precision and scale floating point numbers.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfTime

      @Nullable LocalTime[] readArrayOfTime(@Nonnull String fieldName)
      Reads an array of times consisting of hour, minute, second, and nanoseconds
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field. The items in the array cannot be null.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfDate

      @Nullable LocalDate[] readArrayOfDate(@Nonnull String fieldName)
      Reads an array of dates consisting of year, month, and day.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field. The items in the array cannot be null.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfTimestamp

      @Nullable LocalDateTime[] readArrayOfTimestamp(@Nonnull String fieldName)
      Reads an array of timestamps consisting of date and time.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field. The items in the array cannot be null.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfTimestampWithTimezone

      @Nullable OffsetDateTime[] readArrayOfTimestampWithTimezone(@Nonnull String fieldName)
      Reads an array of timestamps with timezone consisting of date, time and timezone offset.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field. The items in the array cannot be null.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfCompact

      @Nullable <T> T[] readArrayOfCompact(@Nonnull String fieldName, @Nullable Class<T> componentType)
      Reads an array of compact objects.
      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readNullableBoolean

      @Nullable Boolean readNullableBoolean(@Nonnull String fieldName)
      Reads a nullable boolean.

      This method can also read a non-nullable boolean.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readNullableInt8

      @Nullable Byte readNullableInt8(@Nonnull String fieldName)
      Reads a nullable 8-bit two's complement signed integer.

      This method can also read a non-nullable int8.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readNullableInt16

      @Nullable Short readNullableInt16(@Nonnull String fieldName)
      Reads a nullable 16-bit two's complement signed integer.

      This method can also read a non-nullable int16.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readNullableInt32

      @Nullable Integer readNullableInt32(@Nonnull String fieldName)
      Reads a nullable 32-bit two's complement signed integer.

      This method can also read a non-nullable int32.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readNullableInt64

      @Nullable Long readNullableInt64(@Nonnull String fieldName)
      Reads a nullable 64-bit two's complement signed integer.

      This method can also read a non-nullable int64.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readNullableFloat32

      @Nullable Float readNullableFloat32(@Nonnull String fieldName)
      Reads a nullable 32-bit IEEE 754 floating point number.

      This method can also read a non-nullable float32.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readNullableFloat64

      @Nullable Double readNullableFloat64(@Nonnull String fieldName)
      Reads a nullable 64-bit IEEE 754 floating point number.

      This method can also read a non-nullable float64.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfNullableBoolean

      @Nullable Boolean[] readArrayOfNullableBoolean(@Nonnull String fieldName)
      Reads a nullable array of nullable booleans.

      This method can also read array of non-nullable booleans.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfNullableInt8

      @Nullable Byte[] readArrayOfNullableInt8(@Nonnull String fieldName)
      Reads a nullable array of nullable 8-bit two's complement signed integers.

      This method can also read array of non-nullable int8s.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfNullableInt16

      @Nullable Short[] readArrayOfNullableInt16(@Nonnull String fieldName)
      Reads a nullable array of nullable 16-bit two's complement signed integers.

      This method can also read array of non-nullable int16s.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfNullableInt32

      @Nullable Integer[] readArrayOfNullableInt32(@Nonnull String fieldName)
      Reads a nullable array of nullable 32-bit two's complement signed integers.

      This method can also read array of non-nullable int32s.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfNullableInt64

      @Nullable Long[] readArrayOfNullableInt64(@Nonnull String fieldName)
      Reads a nullable array of nullable 64-bit two's complement signed integers.

      This method can also read array of non-nullable int64s.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfNullableFloat32

      @Nullable Float[] readArrayOfNullableFloat32(@Nonnull String fieldName)
      Reads a nullable array of nullable 32-bit IEEE 754 floating point numbers.

      This method can also read array of non-nullable float32s.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.
    • readArrayOfNullableFloat64

      @Nullable Double[] readArrayOfNullableFloat64(@Nonnull String fieldName)
      Reads a nullable array of nullable 64-bit IEEE 754 floating point numbers.

      This method can also read array of non-nullable float64s.

      Parameters:
      fieldName - name of the field.
      Returns:
      the value of the field.
      Throws:
      HazelcastSerializationException - 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.