Package com.hazelcast.jet.protobuf
Class ProtobufSerializer<T extends com.google.protobuf.GeneratedMessageV3>
- java.lang.Object
-
- com.hazelcast.jet.protobuf.ProtobufSerializer<T>
-
- Type Parameters:
T
- the Protocol BuffersGeneratedMessageV3
type handled by thisStreamSerializer
.
- All Implemented Interfaces:
Serializer
,StreamSerializer<T>
public abstract class ProtobufSerializer<T extends com.google.protobuf.GeneratedMessageV3> extends java.lang.Object implements StreamSerializer<T>
Adapts a generated Google Protocol Buffers v3 serializer class to the HazelcastStreamSerializer
interface.To learn how to use this class, visit Jet's Serialization Guide. In brief, you should create a subclass that does nothing else but call this class's protected constructor, and then you can use it in two ways:
-
Register it as a Jet job serializer:
jobConfig.registerSerializer(MyType.class, MyTypeSerializer.class)
. - Register it with the Jet cluster through a matching implementation of ProtobufSerializerHook
- Since:
- Jet 4.1
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ProtobufSerializer(java.lang.Class<T> clazz, int typeId)
Called by the subclass to initialize this protobuf serializer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T extends com.google.protobuf.GeneratedMessageV3>
ProtobufSerializer<T>from(java.lang.Class<T> clazz, int typeId)
An utility method that creates an anonymousProtobufSerializer
.int
getTypeId()
Uniquely identifies given serializer.T
read(ObjectDataInput in)
Reads object from objectDataInputStreamvoid
write(ObjectDataOutput out, T object)
This method writes object to ObjectDataOutput-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.hazelcast.nio.serialization.Serializer
destroy
-
-
-
-
Constructor Detail
-
ProtobufSerializer
protected ProtobufSerializer(@Nonnull java.lang.Class<T> clazz, int typeId)
Called by the subclass to initialize this protobuf serializer.- Parameters:
clazz
-GeneratedMessageV3
type handled by this serializertypeId
- unique type ID of this serializer
-
-
Method Detail
-
getTypeId
public int getTypeId()
Description copied from interface:Serializer
Uniquely identifies given serializer.- Specified by:
getTypeId
in interfaceSerializer
- Returns:
- typeId of serializer
-
write
public void write(ObjectDataOutput out, T object) throws java.io.IOException
Description copied from interface:StreamSerializer
This method writes object to ObjectDataOutput- Specified by:
write
in interfaceStreamSerializer<T extends com.google.protobuf.GeneratedMessageV3>
- Parameters:
out
- ObjectDataOutput stream that object will be written toobject
- that will be written to out- Throws:
java.io.IOException
- in case of failure to write
-
read
public T read(ObjectDataInput in) throws java.io.IOException
Description copied from interface:StreamSerializer
Reads object from objectDataInputStream- Specified by:
read
in interfaceStreamSerializer<T extends com.google.protobuf.GeneratedMessageV3>
- Parameters:
in
- ObjectDataInput stream that object will read from- Returns:
- read object
- Throws:
java.io.IOException
- in case of failure to read
-
from
@Nonnull public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSerializer<T> from(@Nonnull java.lang.Class<T> clazz, int typeId)
An utility method that creates an anonymousProtobufSerializer
.- Type Parameters:
T
- the Protocol BuffersGeneratedMessageV3
type handled by createdStreamSerializer
- Parameters:
clazz
-GeneratedMessageV3
type of created serializertypeId
- unique type id of created serializer
-
-