com.alipay.remoting.codec
Class ProtocolCodeBasedDecoder

java.lang.Object
  extended by io.netty.channel.ChannelHandlerAdapter
      extended by io.netty.channel.ChannelInboundHandlerAdapter
          extended by com.alipay.remoting.codec.AbstractBatchDecoder
              extended by com.alipay.remoting.codec.ProtocolCodeBasedDecoder
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler
Direct Known Subclasses:
RpcProtocolDecoder

public class ProtocolCodeBasedDecoder
extends AbstractBatchDecoder

Protocol code based decoder, the main decoder for a certain protocol, which is lead by one or multi bytes (magic code). Notice: this is not stateless, can not be noted as ChannelHandler.Sharable


Nested Class Summary
 
Nested classes/interfaces inherited from class com.alipay.remoting.codec.AbstractBatchDecoder
AbstractBatchDecoder.Cumulator
 
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
 
Field Summary
static int DEFAULT_ILLEGAL_PROTOCOL_VERSION_LENGTH
          protocol version should be a positive number, we use -1 to represent illegal
static int DEFAULT_PROTOCOL_VERSION_LENGTH
          by default, suggest design a single byte for protocol version.
protected  int protocolCodeLength
          the length of protocol code
 
Fields inherited from class com.alipay.remoting.codec.AbstractBatchDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR
 
Constructor Summary
ProtocolCodeBasedDecoder(int protocolCodeLength)
           
 
Method Summary
protected  void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)
          Decode the from one ByteBuf to an other.
protected  ProtocolCode decodeProtocolCode(io.netty.buffer.ByteBuf in)
          decode the protocol code
protected  byte decodeProtocolVersion(io.netty.buffer.ByteBuf in)
          decode the protocol version
 
Methods inherited from class com.alipay.remoting.codec.AbstractBatchDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode
 
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
 
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded
 

Field Detail

DEFAULT_PROTOCOL_VERSION_LENGTH

public static final int DEFAULT_PROTOCOL_VERSION_LENGTH
by default, suggest design a single byte for protocol version.

See Also:
Constant Field Values

DEFAULT_ILLEGAL_PROTOCOL_VERSION_LENGTH

public static final int DEFAULT_ILLEGAL_PROTOCOL_VERSION_LENGTH
protocol version should be a positive number, we use -1 to represent illegal

See Also:
Constant Field Values

protocolCodeLength

protected int protocolCodeLength
the length of protocol code

Constructor Detail

ProtocolCodeBasedDecoder

public ProtocolCodeBasedDecoder(int protocolCodeLength)
Method Detail

decodeProtocolCode

protected ProtocolCode decodeProtocolCode(io.netty.buffer.ByteBuf in)
decode the protocol code

Parameters:
in -
Returns:
an instance of ProtocolCode

decodeProtocolVersion

protected byte decodeProtocolVersion(io.netty.buffer.ByteBuf in)
decode the protocol version

Parameters:
in -
Returns:
a byte to represent protocol version

decode

protected void decode(io.netty.channel.ChannelHandlerContext ctx,
                      io.netty.buffer.ByteBuf in,
                      List<Object> out)
               throws Exception
Description copied from class: AbstractBatchDecoder
Decode the from one ByteBuf to an other. This method will be called till either the input ByteBuf has nothing to read when return from this method or till nothing was read from the input ByteBuf.

Specified by:
decode in class AbstractBatchDecoder
Parameters:
ctx - the ChannelHandlerContext which this ByteToMessageDecoder belongs to
in - the ByteBuf from which to read data
out - the List to which decoded messages should be added
Throws:
Exception - is thrown if an error accour


Copyright © 2018. All rights reserved.