Class FrameCodec

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.codec.ByteToMessageCodec<Packet>
crow.game.codec.netty.FrameCodec
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class FrameCodec extends io.netty.handler.codec.ByteToMessageCodec<Packet>
The FrameCodec converts to and from ByteBuf streams into individual Packet objects. The first two bytes of a packet determine which type of packet it is (called the packet ID). Packets which are sized dynamically will have their lengths read and written here as well, so individual PacketHandler implementations do not need to worry about length.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Context
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)
     
    protected void
    encode(io.netty.channel.ChannelHandlerContext ctx, Packet msg, io.netty.buffer.ByteBuf out)
     
    void
    exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
     
    protected boolean
    packetRuleHasMoreData(io.netty.buffer.ByteBuf in, PacketRule pr)
     
    protected Optional<PacketRule>
    resolvePacketRule(Context ctx, int prefix, io.netty.buffer.ByteBuf in)
     

    Methods inherited from class io.netty.handler.codec.ByteToMessageCodec

    acceptOutboundMessage, channelInactive, channelRead, channelReadComplete, decodeLast, handlerAdded, handlerRemoved, write

    Methods inherited from class io.netty.channel.ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • context

      protected final Context context
  • Constructor Details

    • FrameCodec

      public FrameCodec(Context context)
  • Method Details

    • packetRuleHasMoreData

      protected boolean packetRuleHasMoreData(io.netty.buffer.ByteBuf in, PacketRule pr)
    • resolvePacketRule

      protected Optional<PacketRule> resolvePacketRule(Context ctx, int prefix, io.netty.buffer.ByteBuf in)
    • encode

      protected void encode(io.netty.channel.ChannelHandlerContext ctx, Packet msg, io.netty.buffer.ByteBuf out)
      Specified by:
      encode in class io.netty.handler.codec.ByteToMessageCodec<Packet>
    • decode

      protected void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)
      Specified by:
      decode in class io.netty.handler.codec.ByteToMessageCodec<Packet>
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception