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 extendsByteToByteCodec
{@Override
public void decode(ChannelHandlerContext
ctx,ByteBuf
in,ByteBuf
out) throwsException
{ if (in.readableBytes() < 4) { return; } int value = in.readInt(); out.writeInt(value * value); }@Overrride
public void encode(ChannelHandlerContext
ctx,ByteBuf
in,ByteBuf
out) throwsException
{ 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 |
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, sendFile
channelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregistered, userEventTriggered
exceptionCaught, handlerAdded, handlerRemoved
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
channelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregistered, userEventTriggered
public io.netty.buffer.ByteBuf newInboundBuffer(io.netty.channel.ChannelHandlerContext ctx) throws Exception
newInboundBuffer
in interface io.netty.channel.ChannelInboundByteHandler
Exception
public void inboundBufferUpdated(io.netty.channel.ChannelHandlerContext ctx) throws Exception
inboundBufferUpdated
in interface io.netty.channel.ChannelStateHandler
Exception
public io.netty.buffer.ByteBuf newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) throws Exception
newOutboundBuffer
in interface io.netty.channel.ChannelOutboundByteHandler
Exception
public void flush(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
flush
in interface io.netty.channel.ChannelOperationHandler
Exception
public void discardInboundReadBytes(io.netty.channel.ChannelHandlerContext ctx) throws Exception
discardInboundReadBytes
in interface io.netty.channel.ChannelInboundByteHandler
Exception
public void discardOutboundReadBytes(io.netty.channel.ChannelHandlerContext ctx) throws Exception
discardOutboundReadBytes
in interface io.netty.channel.ChannelOutboundByteHandler
Exception
protected abstract void encode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, io.netty.buffer.ByteBuf out) throws Exception
Exception
ByteToByteEncoder#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
Exception
ByteToByteDecoder#decode(ChannelHandlerContext, ByteBuf, ByteBuf)}
Copyright © 2008-2013 The Netty Project. All Rights Reserved.