public final class KvStateRequestSerializer extends Object
KvStateClient
and KvStateServer
.
The binary messages have the following format:
<------ Frame -------------------------> +----------------------------------------+ | HEADER (8) | PAYLOAD (VAR) | +------------------+----------------------------------------+ | FRAME LENGTH (4) | VERSION (4) | TYPE (4) | CONTENT (VAR) | +------------------+----------------------------------------+
The concrete content of a message depends on the KvStateRequestType
.
Constructor and Description |
---|
KvStateRequestSerializer() |
Modifier and Type | Method and Description |
---|---|
static KvStateRequestType |
deserializeHeader(io.netty.buffer.ByteBuf buf)
Deserializes the header and returns the request type.
|
static <K,N> Tuple2<K,N> |
deserializeKeyAndNamespace(byte[] serializedKeyAndNamespace,
TypeSerializer<K> keySerializer,
TypeSerializer<N> namespaceSerializer)
Deserializes the key and namespace into a
Tuple2 . |
static KvStateRequest |
deserializeKvStateRequest(io.netty.buffer.ByteBuf buf)
Deserializes the KvState request message.
|
static KvStateRequestFailure |
deserializeKvStateRequestFailure(io.netty.buffer.ByteBuf buf)
Deserializes the KvState request failure.
|
static KvStateRequestResult |
deserializeKvStateRequestResult(io.netty.buffer.ByteBuf buf)
Deserializes the KvState request result.
|
static <T> List<T> |
deserializeList(byte[] serializedValue,
TypeSerializer<T> serializer)
Deserializes all values with the given serializer.
|
static Throwable |
deserializeServerFailure(io.netty.buffer.ByteBuf buf)
Deserializes the KvState request failure.
|
static <T> T |
deserializeValue(byte[] serializedValue,
TypeSerializer<T> serializer)
Deserializes the value with the given serializer.
|
static <K,N> byte[] |
serializeKeyAndNamespace(K key,
TypeSerializer<K> keySerializer,
N namespace,
TypeSerializer<N> namespaceSerializer)
Serializes the key and namespace into a
ByteBuffer . |
static io.netty.buffer.ByteBuf |
serializeKvStateRequest(io.netty.buffer.ByteBufAllocator alloc,
long requestId,
KvStateID kvStateId,
byte[] serializedKeyAndNamespace)
Allocates a buffer and serializes the KvState request into it.
|
static io.netty.buffer.ByteBuf |
serializeKvStateRequestFailure(io.netty.buffer.ByteBufAllocator alloc,
long requestId,
Throwable cause)
Allocates a buffer and serializes the KvState request failure into it.
|
static io.netty.buffer.ByteBuf |
serializeKvStateRequestResult(io.netty.buffer.ByteBufAllocator alloc,
long requestId,
byte[] serializedResult)
Allocates a buffer and serializes the KvState request result into it.
|
static io.netty.buffer.ByteBuf |
serializeServerFailure(io.netty.buffer.ByteBufAllocator alloc,
Throwable cause)
Allocates a buffer and serializes the server failure into it.
|
static <T> byte[] |
serializeValue(T value,
TypeSerializer<T> serializer)
Serializes the value with the given serializer.
|
public static io.netty.buffer.ByteBuf serializeKvStateRequest(io.netty.buffer.ByteBufAllocator alloc, long requestId, KvStateID kvStateId, byte[] serializedKeyAndNamespace)
alloc
- ByteBuf allocator for the buffer to
serialize message intorequestId
- ID for this requestkvStateId
- ID of the requested KvState instanceserializedKeyAndNamespace
- Serialized key and namespace to request
from the KvState instance.public static io.netty.buffer.ByteBuf serializeKvStateRequestResult(io.netty.buffer.ByteBufAllocator alloc, long requestId, byte[] serializedResult)
alloc
- ByteBuf allocator for the buffer to serialize message intorequestId
- ID for this requestserializedResult
- Serialized Resultpublic static io.netty.buffer.ByteBuf serializeKvStateRequestFailure(io.netty.buffer.ByteBufAllocator alloc, long requestId, Throwable cause) throws IOException
alloc
- ByteBuf allocator for the buffer to serialize message intorequestId
- ID of the request responding tocause
- Failure causeIOException
- Serialization failures are forwardedpublic static io.netty.buffer.ByteBuf serializeServerFailure(io.netty.buffer.ByteBufAllocator alloc, Throwable cause) throws IOException
The cause must not be or contain any user types as causes.
alloc
- ByteBuf allocator for the buffer to serialize message intocause
- Failure causeIOException
- Serialization failures are forwardedpublic static KvStateRequestType deserializeHeader(io.netty.buffer.ByteBuf buf)
buf
- Buffer to deserialize (expected to be at header position)IllegalArgumentException
- If unexpected message version or message typepublic static KvStateRequest deserializeKvStateRequest(io.netty.buffer.ByteBuf buf)
Important: the returned buffer is sliced from the incoming ByteBuf stream and retained. Therefore, it needs to be recycled by the consumer.
buf
- Buffer to deserialize (expected to be positioned after header)public static KvStateRequestResult deserializeKvStateRequestResult(io.netty.buffer.ByteBuf buf)
buf
- Buffer to deserialize (expected to be positioned after header)public static KvStateRequestFailure deserializeKvStateRequestFailure(io.netty.buffer.ByteBuf buf) throws IOException, ClassNotFoundException
buf
- Buffer to deserialize (expected to be positioned after header)IOException
ClassNotFoundException
public static Throwable deserializeServerFailure(io.netty.buffer.ByteBuf buf) throws IOException, ClassNotFoundException
buf
- Buffer to deserialize (expected to be positioned after header)IOException
- Serialization failure are forwardedClassNotFoundException
- If Exception type can not be loadedpublic static <K,N> byte[] serializeKeyAndNamespace(K key, TypeSerializer<K> keySerializer, N namespace, TypeSerializer<N> namespaceSerializer) throws IOException
ByteBuffer
.
The serialized format matches the RocksDB state backend key format, i.e. the key and namespace don't have to be deserialized for RocksDB lookups.
K
- Key typeN
- Namespace typekey
- Key to serializekeySerializer
- Serializer for the keynamespace
- Namespace to serializenamespaceSerializer
- Serializer for the namespaceIOException
- Serialization errors are forwardedpublic static <K,N> Tuple2<K,N> deserializeKeyAndNamespace(byte[] serializedKeyAndNamespace, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer) throws IOException
Tuple2
.K
- Key typeN
- NamespaceserializedKeyAndNamespace
- Serialized key and namespacekeySerializer
- Serializer for the keynamespaceSerializer
- Serializer for the namespaceIOException
- if the deserialization fails for any reasonpublic static <T> byte[] serializeValue(T value, TypeSerializer<T> serializer) throws IOException
T
- Type of the valuevalue
- Value of type T to serializeserializer
- Serializer for Tnull
if value null
IOException
- On failure during serializationpublic static <T> T deserializeValue(byte[] serializedValue, TypeSerializer<T> serializer) throws IOException
T
- Type of the valueserializedValue
- Serialized value of type Tserializer
- Serializer for Tnull
if the serialized value
is null
IOException
- On failure during deserializationpublic static <T> List<T> deserializeList(byte[] serializedValue, TypeSerializer<T> serializer) throws IOException
T
- Type of the valueserializedValue
- Serialized value of type Listserializer
- Serializer for Tnull
if the serialized value
is null
IOException
- On failure during deserializationCopyright © 2014–2017 The Apache Software Foundation. All rights reserved.