REQ - Type of the requests of the protocol.RESP - Type of the responses of the protocol.public final class MessageSerializer<REQ extends MessageBody,RESP extends MessageBody> extends Object
NetworkClient and NetworkServer.
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 MessageType.
| Constructor and Description |
|---|
MessageSerializer(MessageDeserializer<REQ> requestDeser,
MessageDeserializer<RESP> responseDeser) |
| Modifier and Type | Method and Description |
|---|---|
static MessageType |
deserializeHeader(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the header and returns the
MessageType. |
REQ |
deserializeRequest(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the request sent to the
NetworkServer. |
static RequestFailure |
deserializeRequestFailure(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the
RequestFailure sent to the NetworkClient in case of
protocol related errors. |
RESP |
deserializeResponse(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the response sent to the
NetworkClient. |
static Throwable |
deserializeServerFailure(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the failure message sent to the
NetworkClient in case of server related
errors. |
static long |
getRequestId(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
De-serializes the header and returns the
MessageType. |
static <REQ extends MessageBody> |
serializeRequest(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBufAllocator alloc,
long requestId,
REQ request)
Serializes the request sent to the
NetworkServer. |
static org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf |
serializeRequestFailure(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBufAllocator alloc,
long requestId,
Throwable cause)
Serializes the exception containing the failure message sent to the
NetworkClient in
case of protocol related errors. |
static <RESP extends MessageBody> |
serializeResponse(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBufAllocator alloc,
long requestId,
RESP response)
Serializes the response sent to the
NetworkClient. |
static org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf |
serializeServerFailure(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBufAllocator alloc,
Throwable cause)
Serializes the failure message sent to the
NetworkClient in case of server related
errors. |
public MessageSerializer(MessageDeserializer<REQ> requestDeser, MessageDeserializer<RESP> responseDeser)
public static <REQ extends MessageBody> org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf serializeRequest(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBufAllocator alloc, long requestId, REQ request)
NetworkServer.alloc - The ByteBufAllocator used to allocate the buffer to serialize the
message into.requestId - The id of the request to which the message refers to.request - The request to be serialized.ByteBuf containing the serialized message.public static <RESP extends MessageBody> org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf serializeResponse(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBufAllocator alloc, long requestId, RESP response)
NetworkClient.alloc - The ByteBufAllocator used to allocate the buffer to serialize the
message into.requestId - The id of the request to which the message refers to.response - The response to be serialized.ByteBuf containing the serialized message.public static org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf serializeRequestFailure(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBufAllocator alloc,
long requestId,
Throwable cause)
throws IOException
NetworkClient in
case of protocol related errors.alloc - The ByteBufAllocator used to allocate the buffer to serialize the
message into.requestId - The id of the request to which the message refers to.cause - The exception thrown at the server.ByteBuf containing the serialized message.IOExceptionpublic static org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf serializeServerFailure(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBufAllocator alloc,
Throwable cause)
throws IOException
NetworkClient in case of server related
errors.alloc - The ByteBufAllocator used to allocate the buffer to serialize the
message into.cause - The exception thrown at the server.IOExceptionpublic static MessageType deserializeHeader(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
MessageType.
The buffer is expected to be at the header position.
buf - The ByteBuf containing the serialized header.IllegalStateException - If unexpected message version or message type.public static long getRequestId(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
MessageType.
The buffer is expected to be at the request id position.
buf - The ByteBuf containing the serialized request id.public REQ deserializeRequest(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
NetworkServer.
The buffer is expected to be at the request position.
buf - The ByteBuf containing the serialized request.public RESP deserializeResponse(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf)
NetworkClient.
The buffer is expected to be at the response position.
buf - The ByteBuf containing the serialized response.public static RequestFailure deserializeRequestFailure(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf) throws IOException, ClassNotFoundException
RequestFailure sent to the NetworkClient in case of
protocol related errors.
The buffer is expected to be at the correct position.
buf - The ByteBuf containing the serialized failure message.IOExceptionClassNotFoundExceptionpublic static Throwable deserializeServerFailure(org.apache.paimon.shade.netty4.io.netty.buffer.ByteBuf buf) throws IOException, ClassNotFoundException
NetworkClient in case of server related
errors.
The buffer is expected to be at the correct position.
buf - The ByteBuf containing the serialized failure message.IOExceptionClassNotFoundExceptionCopyright © 2023–2024 The Apache Software Foundation. All rights reserved.