public class FrameCodec<B> extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
FrameCodec.CodecGroup
Intermediary class to pass request/response codecs to the frame codec.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
V3_ENCODED_HEADER_SIZE
The header size for protocol v3 and above.
|
| Constructor and Description |
|---|
FrameCodec(PrimitiveCodec<B> primitiveCodec,
Compressor<B> compressor,
FrameCodec.CodecGroup... codecGroups) |
| Modifier and Type | Method and Description |
|---|---|
Frame |
decode(B source)
Decodes the next frame from the given buffer.
|
int |
decodeBodySize(B source)
Decodes the size of the body of the next frame contained in the given buffer.
|
static <B> FrameCodec<B> |
defaultClient(PrimitiveCodec<B> primitiveCodec,
Compressor<B> compressor)
Builds a new instance with the default codecs for a client (encoding requests, decoding
responses).
|
static <B> FrameCodec<B> |
defaultServer(PrimitiveCodec<B> primitiveCodec,
Compressor<B> compressor)
Builds a new instance with the default codecs for a server (decoding requests, encoding
responses).
|
B |
encode(Frame frame)
Allocates a new buffer and encodes the given frame into it.
|
int |
encodedBodySize(Frame frame)
How many bytes are needed to encode the given frame's body (message + tracing id, custom
payload and/or warnings if relevant).
|
int |
encodedHeaderSize(Frame frame)
How many bytes are needed to encode the given frame's header.
|
void |
encodeInto(Frame frame,
int bodySize,
B dest)
Encodes the given frame into an existing buffer.
|
public static final int V3_ENCODED_HEADER_SIZE
If you have a reference to an instance of this class, encodedHeaderSize(Frame) is a
more future-proof way to get this information.
public FrameCodec(PrimitiveCodec<B> primitiveCodec, Compressor<B> compressor, FrameCodec.CodecGroup... codecGroups)
public static <B> FrameCodec<B> defaultClient(PrimitiveCodec<B> primitiveCodec, Compressor<B> compressor)
public static <B> FrameCodec<B> defaultServer(PrimitiveCodec<B> primitiveCodec, Compressor<B> compressor)
public void encodeInto(Frame frame, int bodySize, B dest)
Note that this method never compresses the frame body; it is intended for protocol v5+, where multiple frames are concatenated into a single buffer and compressed together, instead of individually.
The caller is responsible for ensuring that the buffer has enough space remaining, that is:
encodedHeaderSize(Frame) + encodedBodySize(Frame) bytes.
bodySize - the body size to use in the header, if available. This is just an optimization
because the caller may already know it if it has performed the size check above. If not,
pass a negative value, and it will be recomputed.public int encodedHeaderSize(Frame frame)
public int encodedBodySize(Frame frame)
public int decodeBodySize(B source)
The buffer must contain at least the frame's header. This method performs a relative read, it will not consume any data from the buffer.
Copyright © 2017–2022. All rights reserved.