Class SimpleVersionedSerialization
- java.lang.Object
-
- org.apache.flink.core.io.SimpleVersionedSerialization
-
@PublicEvolving public class SimpleVersionedSerialization extends Object
Simple serialization / deserialization methods for theSimpleVersionedSerializer
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
readVersionAndDeSerialize(SimpleVersionedSerializer<T> serializer, byte[] bytes)
Deserializes the version and datum from a byte array.static <T> T
readVersionAndDeSerialize(SimpleVersionedSerializer<T> serializer, DataInputView in)
Deserializes the version and datum from a stream.static <T> List<T>
readVersionAndDeserializeList(SimpleVersionedSerializer<T> serializer, DataInputView in)
Deserializes the version and data from a stream.static <T> byte[]
writeVersionAndSerialize(SimpleVersionedSerializer<T> serializer, T datum)
Serializes the version and datum into a byte array.static <T> void
writeVersionAndSerialize(SimpleVersionedSerializer<T> serializer, T datum, DataOutputView out)
Serializes the version and datum into a stream.static <T> void
writeVersionAndSerializeList(SimpleVersionedSerializer<T> serializer, List<T> data, DataOutputView out)
Serializes the version and data into a stream.
-
-
-
Method Detail
-
writeVersionAndSerialize
public static <T> void writeVersionAndSerialize(SimpleVersionedSerializer<T> serializer, T datum, DataOutputView out) throws IOException
Serializes the version and datum into a stream.Data serialized via this method can be deserialized via
readVersionAndDeSerialize(SimpleVersionedSerializer, DataInputView)
.The first four bytes will be occupied by the version, as returned by
SimpleVersionedSerializer.getVersion()
. The remaining bytes will be the serialized datum, as produced bySimpleVersionedSerializer.serialize(Object)
, plus its length. The resulting array will hence be eight bytes larger than the serialized datum.- Parameters:
serializer
- The serializer to serialize the datum with.datum
- The datum to serialize.out
- The stream to serialize to.- Throws:
IOException
-
writeVersionAndSerializeList
public static <T> void writeVersionAndSerializeList(SimpleVersionedSerializer<T> serializer, List<T> data, DataOutputView out) throws IOException
Serializes the version and data into a stream.Data serialized via this method can be deserialized via
readVersionAndDeserializeList(SimpleVersionedSerializer, DataInputView)
.The first eight bytes will be occupied by the version, as returned by
SimpleVersionedSerializer.getVersion()
and the length of the list. The remaining bytes will be the serialized data, as produced bySimpleVersionedSerializer.serialize(Object)
, plus its length.- Parameters:
serializer
- The serializer to serialize the datum with.data
- list of datum to serialize.out
- The stream to serialize to.- Throws:
IOException
-
readVersionAndDeSerialize
public static <T> T readVersionAndDeSerialize(SimpleVersionedSerializer<T> serializer, DataInputView in) throws IOException
Deserializes the version and datum from a stream.This method deserializes data serialized via
writeVersionAndSerialize(SimpleVersionedSerializer, Object, DataOutputView)
.The first four bytes will be interpreted as the version. The next four bytes will be interpreted as the length of the datum bytes, then length-many bytes will be read. Finally, the datum is deserialized via the
SimpleVersionedSerializer.deserialize(int, byte[])
method.- Parameters:
serializer
- The serializer to serialize the datum with.in
- The stream to deserialize from.- Throws:
IOException
-
readVersionAndDeserializeList
public static <T> List<T> readVersionAndDeserializeList(SimpleVersionedSerializer<T> serializer, DataInputView in) throws IOException
Deserializes the version and data from a stream.This method deserializes data serialized via
writeVersionAndSerializeList(SimpleVersionedSerializer, List, DataOutputView)
.The first four bytes will be interpreted as the version. The next four bytes will be interpreted as the length of the list, then length-many data will be read and deserialized via the
SimpleVersionedSerializer.deserialize(int, byte[])
method.- Parameters:
serializer
- The serializer to serialize the datum with.in
- The stream to deserialize from.- Throws:
IOException
-
writeVersionAndSerialize
public static <T> byte[] writeVersionAndSerialize(SimpleVersionedSerializer<T> serializer, T datum) throws IOException
Serializes the version and datum into a byte array. The first four bytes will be occupied by the version (as returned bySimpleVersionedSerializer.getVersion()
), written in big-endian encoding. The remaining bytes will be the serialized datum, as produced bySimpleVersionedSerializer.serialize(Object)
. The resulting array will hence be four bytes larger than the serialized datum.Data serialized via this method can be deserialized via
readVersionAndDeSerialize(SimpleVersionedSerializer, byte[])
.- Parameters:
serializer
- The serializer to serialize the datum with.datum
- The datum to serialize.- Returns:
- A byte array containing the serialized version and serialized datum.
- Throws:
IOException
- Exceptions from theSimpleVersionedSerializer.serialize(Object)
method are forwarded.
-
readVersionAndDeSerialize
public static <T> T readVersionAndDeSerialize(SimpleVersionedSerializer<T> serializer, byte[] bytes) throws IOException
Deserializes the version and datum from a byte array. The first four bytes will be read as the version, in big-endian encoding. The remaining bytes will be passed to the serializer for deserialization, viaSimpleVersionedSerializer.deserialize(int, byte[])
.- Parameters:
serializer
- The serializer to deserialize the datum with.bytes
- The bytes to deserialize from.- Returns:
- The deserialized datum.
- Throws:
IOException
- Exceptions from theSimpleVersionedSerializer.deserialize(int, byte[])
method are forwarded.
-
-