public abstract class ByteToByteCodec
extends io.netty.channel.ChannelDuplexHandler
implements io.netty.channel.ChannelInboundByteHandler, io.netty.channel.ChannelOutboundByteHandler
ByteToByteDecoder and ByteToByteEncoder.
Here is an example of a ByteToByteCodec which just square Integer read from a ByteBuf.
public class SquareCodec extends ByteToByteCodec {
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out)
throws Exception {
if (in.readableBytes() < 4) {
return;
}
int value = in.readInt();
out.writeInt(value * value);
}
@Overrride
public void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out)
throws Exception {
if (in.readableBytes() < 4) {
return;
}
int value = in.readInt();
out.writeInt(value / value);
}
}
| Constructor and Description |
|---|
ByteToByteCodec() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.ByteBuf out) |
protected void |
decodeLast(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.ByteBuf out) |
void |
discardInboundReadBytes(io.netty.channel.ChannelHandlerContext ctx) |
void |
discardOutboundReadBytes(io.netty.channel.ChannelHandlerContext ctx) |
protected abstract void |
encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.ByteBuf out) |
void |
flush(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
freeInboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
void |
freeOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
void |
inboundBufferUpdated(io.netty.channel.ChannelHandlerContext ctx) |
io.netty.buffer.ByteBuf |
newInboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
io.netty.buffer.ByteBuf |
newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
bind, close, connect, deregister, disconnect, read, sendFilechannelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregistered, userEventTriggeredafterAdd, afterRemove, beforeAdd, beforeRemove, exceptionCaughtclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitchannelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregistered, userEventTriggeredpublic io.netty.buffer.ByteBuf newInboundBuffer(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
newInboundBuffer in interface io.netty.channel.ChannelInboundByteHandlerExceptionpublic void inboundBufferUpdated(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
inboundBufferUpdated in interface io.netty.channel.ChannelStateHandlerExceptionpublic io.netty.buffer.ByteBuf newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
newOutboundBuffer in interface io.netty.channel.ChannelOutboundByteHandlerExceptionpublic void flush(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise)
throws Exception
flush in interface io.netty.channel.ChannelOperationHandlerExceptionpublic void discardInboundReadBytes(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
discardInboundReadBytes in interface io.netty.channel.ChannelInboundByteHandlerExceptionpublic void discardOutboundReadBytes(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
discardOutboundReadBytes in interface io.netty.channel.ChannelOutboundByteHandlerExceptionpublic void freeInboundBuffer(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
Exceptionpublic void freeOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
Exceptionprotected abstract void encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.ByteBuf out)
throws Exception
ExceptionByteToByteEncoder#encode(ChannelHandlerContext, ByteBuf, ByteBuf)}protected abstract void decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
io.netty.buffer.ByteBuf out)
throws Exception
ExceptionByteToByteDecoder#decode(ChannelHandlerContext, ByteBuf, ByteBuf)}Copyright © 2008-2013 The Netty Project. All Rights Reserved.