com.github.linshenkx.rpcnettycommon.codec.decode.RemotingTransporterDecoder Maven / Gradle / Ivy
package com.github.linshenkx.rpcnettycommon.codec.decode;
import com.github.linshenkx.rpcnettycommon.bean.BodyContent;
import com.github.linshenkx.rpcnettycommon.bean.RpcRequest;
import com.github.linshenkx.rpcnettycommon.bean.RpcResponse;
import com.github.linshenkx.rpcnettycommon.exception.remoting.RemotingContextException;
import com.github.linshenkx.rpcnettycommon.protocal.xuan.RemotingTransporter;
import com.github.linshenkx.rpcnettycommon.serialization.SerializeTypeEnum;
import com.github.linshenkx.rpcnettycommon.serialization.SerializerEngine;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import lombok.extern.log4j.Log4j2;
import java.util.List;
/**
* @version V1.0
* @author: lin_shen
* @date: 18-11-12
* @Description: TODO
*/
@Log4j2
public class RemotingTransporterDecoder extends ReplayingDecoder {
private static final int MAX_BODY_SIZE = 1024 * 1024 * 5;
/**
* 用于暂存解码RemotingTransporter信息,一个就够了
*/
private static RemotingTransporter remotingTransporter=RemotingTransporter.builder().build();
/**
* 用于ReplayingDecoder的状态管理
*/
enum State {
HEADER_MAGIC, HEADER_FLAG, HEADER_INVOKE_ID, HEADER_BODY_LENGTH, BODY
}
public RemotingTransporterDecoder( ){
//设置 state() 的初始值,以便进入switch
super(State.HEADER_MAGIC);
}
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List