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 thegetFieldKind(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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description FieldKind
getFieldKind(java.lang.String fieldName)
Returns the kind of the field for the given field name.boolean[]
readArrayOfBoolean(java.lang.String fieldName)
Reads an array of booleans.<T> T[]
readArrayOfCompact(java.lang.String fieldName, java.lang.Class<T> componentType)
Reads an array of compact objects.java.time.LocalDate[]
readArrayOfDate(java.lang.String fieldName)
Reads an array of dates consisting of year, month, and day.java.math.BigDecimal[]
readArrayOfDecimal(java.lang.String fieldName)
Reads an array of arbitrary precision and scale floating point numbers.float[]
readArrayOfFloat32(java.lang.String fieldName)
Reads an array of 32-bit IEEE 754 floating point numbers.double[]
readArrayOfFloat64(java.lang.String fieldName)
Reads an array of 64-bit IEEE 754 floating point numbers.short[]
readArrayOfInt16(java.lang.String fieldName)
Reads an array of 16-bit two's complement signed integers.int[]
readArrayOfInt32(java.lang.String fieldName)
Reads an array of 32-bit two's complement signed integers.long[]
readArrayOfInt64(java.lang.String fieldName)
Reads an array of 64-bit two's complement signed integers.byte[]
readArrayOfInt8(java.lang.String fieldName)
Reads an array of 8-bit two's complement signed integers.java.lang.Boolean[]
readArrayOfNullableBoolean(java.lang.String fieldName)
Reads a nullable array of nullable booleans.java.lang.Float[]
readArrayOfNullableFloat32(java.lang.String fieldName)
Reads a nullable array of nullable 32-bit IEEE 754 floating point numbers.java.lang.Double[]
readArrayOfNullableFloat64(java.lang.String fieldName)
Reads a nullable array of nullable 64-bit IEEE 754 floating point numbers.java.lang.Short[]
readArrayOfNullableInt16(java.lang.String fieldName)
Reads a nullable array of nullable 16-bit two's complement signed integers.java.lang.Integer[]
readArrayOfNullableInt32(java.lang.String fieldName)
Reads a nullable array of nullable 32-bit two's complement signed integers.java.lang.Long[]
readArrayOfNullableInt64(java.lang.String fieldName)
Reads a nullable array of nullable 64-bit two's complement signed integers.java.lang.Byte[]
readArrayOfNullableInt8(java.lang.String fieldName)
Reads a nullable array of nullable 8-bit two's complement signed integers.java.lang.String[]
readArrayOfString(java.lang.String fieldName)
Reads an array of UTF-8 encoded strings.java.time.LocalTime[]
readArrayOfTime(java.lang.String fieldName)
Reads an array of times consisting of hour, minute, second, and nanosecondsjava.time.LocalDateTime[]
readArrayOfTimestamp(java.lang.String fieldName)
Reads an array of timestamps consisting of date and time.java.time.OffsetDateTime[]
readArrayOfTimestampWithTimezone(java.lang.String fieldName)
Reads an array of timestamps with timezone consisting of date, time and timezone offset.boolean
readBoolean(java.lang.String fieldName)
Reads a boolean.<T> T
readCompact(java.lang.String fieldName)
Reads a compact objectjava.time.LocalDate
readDate(java.lang.String fieldName)
Reads a date consisting of year, month, and day.java.math.BigDecimal
readDecimal(java.lang.String fieldName)
Reads an arbitrary precision and scale floating point number.float
readFloat32(java.lang.String fieldName)
Reads a 32-bit IEEE 754 floating point number.double
readFloat64(java.lang.String fieldName)
Reads a 64-bit IEEE 754 floating point number.short
readInt16(java.lang.String fieldName)
Reads a 16-bit two's complement signed integer.int
readInt32(java.lang.String fieldName)
Reads a 32-bit two's complement signed integer.long
readInt64(java.lang.String fieldName)
Reads a 64-bit two's complement signed integer.byte
readInt8(java.lang.String fieldName)
Reads an 8-bit two's complement signed integer.java.lang.Boolean
readNullableBoolean(java.lang.String fieldName)
Reads a nullable boolean.java.lang.Float
readNullableFloat32(java.lang.String fieldName)
Reads a nullable 32-bit IEEE 754 floating point number.java.lang.Double
readNullableFloat64(java.lang.String fieldName)
Reads a nullable 64-bit IEEE 754 floating point number.java.lang.Short
readNullableInt16(java.lang.String fieldName)
Reads a nullable 16-bit two's complement signed integer.java.lang.Integer
readNullableInt32(java.lang.String fieldName)
Reads a nullable 32-bit two's complement signed integer.java.lang.Long
readNullableInt64(java.lang.String fieldName)
Reads a nullable 64-bit two's complement signed integer.java.lang.Byte
readNullableInt8(java.lang.String fieldName)
Reads a nullable 8-bit two's complement signed integer.java.lang.String
readString(java.lang.String fieldName)
Reads an UTF-8 encoded string.java.time.LocalTime
readTime(java.lang.String fieldName)
Reads a time consisting of hour, minute, second, and nano seconds.java.time.LocalDateTime
readTimestamp(java.lang.String fieldName)
Reads a timestamp consisting of date and time.java.time.OffsetDateTime
readTimestampWithTimezone(java.lang.String fieldName)
Reads a timestamp with timezone consisting of date, time and timezone offset.
-
-
-
Method Detail
-
getFieldKind
@Nonnull FieldKind getFieldKind(@Nonnull java.lang.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 java.lang.String fieldName)
Reads a boolean.This method can also read a nullable boolean, as long as it is not
null
. If anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.String readString(@Nonnull java.lang.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 java.math.BigDecimal readDecimal(@Nonnull java.lang.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 java.time.LocalTime readTime(@Nonnull java.lang.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 java.time.LocalDate readDate(@Nonnull java.lang.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 java.time.LocalDateTime readTimestamp(@Nonnull java.lang.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 java.time.OffsetDateTime readTimestampWithTimezone(@Nonnull java.lang.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 java.lang.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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.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 anull
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 java.lang.String[] readArrayOfString(@Nonnull java.lang.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 java.math.BigDecimal[] readArrayOfDecimal(@Nonnull java.lang.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 java.time.LocalTime[] readArrayOfTime(@Nonnull java.lang.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 java.time.LocalDate[] readArrayOfDate(@Nonnull java.lang.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 java.time.LocalDateTime[] readArrayOfTimestamp(@Nonnull java.lang.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 java.time.OffsetDateTime[] readArrayOfTimestampWithTimezone(@Nonnull java.lang.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 java.lang.String fieldName, @Nullable java.lang.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 java.lang.Boolean readNullableBoolean(@Nonnull java.lang.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 java.lang.Byte readNullableInt8(@Nonnull java.lang.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 java.lang.Short readNullableInt16(@Nonnull java.lang.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 java.lang.Integer readNullableInt32(@Nonnull java.lang.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 java.lang.Long readNullableInt64(@Nonnull java.lang.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 java.lang.Float readNullableFloat32(@Nonnull java.lang.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 java.lang.Double readNullableFloat64(@Nonnull java.lang.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 java.lang.Boolean[] readArrayOfNullableBoolean(@Nonnull java.lang.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 java.lang.Byte[] readArrayOfNullableInt8(@Nonnull java.lang.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 java.lang.Short[] readArrayOfNullableInt16(@Nonnull java.lang.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 java.lang.Integer[] readArrayOfNullableInt32(@Nonnull java.lang.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 java.lang.Long[] readArrayOfNullableInt64(@Nonnull java.lang.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 java.lang.Float[] readArrayOfNullableFloat32(@Nonnull java.lang.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 java.lang.Double[] readArrayOfNullableFloat64(@Nonnull java.lang.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.
-
-