Add ByteToMessageCodec.isEncodable()
This commit is contained in:
parent
dd6b7969b7
commit
aa69d628f1
@ -27,24 +27,25 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
|
||||
extends ChannelHandlerAdapter
|
||||
implements ChannelInboundByteHandler, ChannelOutboundMessageHandler<OUTBOUND_IN> {
|
||||
|
||||
private final MessageToByteEncoder<OUTBOUND_IN> encoder =
|
||||
new MessageToByteEncoder<OUTBOUND_IN>() {
|
||||
private final MessageToByteEncoder<OUTBOUND_IN> encoder;
|
||||
private final ByteToMessageDecoder<INBOUND_OUT> decoder;
|
||||
|
||||
protected ByteToMessageCodec(Class<?>... encodableMessageTypes) {
|
||||
encoder = new MessageToByteEncoder<OUTBOUND_IN>(encodableMessageTypes) {
|
||||
@Override
|
||||
public void encode(
|
||||
ChannelHandlerContext ctx,
|
||||
OUTBOUND_IN msg, ByteBuf out) throws Exception {
|
||||
protected void encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, ByteBuf out) throws Exception {
|
||||
ByteToMessageCodec.this.encode(ctx, msg, out);
|
||||
}
|
||||
};
|
||||
|
||||
private final ByteToMessageDecoder<INBOUND_OUT> decoder =
|
||||
new ByteToMessageDecoder<INBOUND_OUT>() {
|
||||
decoder = new ByteToMessageDecoder<INBOUND_OUT>() {
|
||||
@Override
|
||||
public INBOUND_OUT decode(
|
||||
ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
return ByteToMessageCodec.this.decode(ctx, in);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf newInboundBuffer(
|
||||
@ -79,10 +80,10 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
|
||||
encoder.freeOutboundBuffer(ctx);
|
||||
}
|
||||
|
||||
protected abstract void encode(
|
||||
ChannelHandlerContext ctx,
|
||||
OUTBOUND_IN msg, ByteBuf out) throws Exception;
|
||||
|
||||
protected abstract INBOUND_OUT decode(
|
||||
ChannelHandlerContext ctx, ByteBuf in) throws Exception;
|
||||
protected boolean isEncodable(Object msg) throws Exception {
|
||||
return encoder.isEncodable(msg);
|
||||
}
|
||||
|
||||
protected abstract void encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, ByteBuf out) throws Exception;
|
||||
protected abstract INBOUND_OUT decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user