|
|
@ -43,37 +43,33 @@ public class NettyDecoder extends ByteToMessageDecoder { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception { |
|
|
|
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (byteBuf.readableBytes() < RpcProtocolConstants.HEADER_LENGTH) { |
|
|
|
if (byteBuf.readableBytes() < RpcProtocolConstants.HEADER_LENGTH) { |
|
|
|
System.out.println("llllll 长度不够"); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
byteBuf.markReaderIndex(); |
|
|
|
byteBuf.markReaderIndex(); |
|
|
|
|
|
|
|
|
|
|
|
short magic = byteBuf.readShort(); |
|
|
|
short magic = byteBuf.readShort(); |
|
|
|
|
|
|
|
|
|
|
|
if (RpcProtocolConstants.MAGIC != magic) { |
|
|
|
if (RpcProtocolConstants.MAGIC != magic) { |
|
|
|
throw new IllegalArgumentException("magic number is illegal, " + magic); |
|
|
|
throw new IllegalArgumentException("magic number is illegal, " + magic); |
|
|
|
} |
|
|
|
} |
|
|
|
byte eventType = byteBuf.readByte(); |
|
|
|
byte eventType = byteBuf.readByte(); |
|
|
|
byte version = byteBuf.readByte(); |
|
|
|
byte version = byteBuf.readByte(); |
|
|
|
byte serialization = byteBuf.readByte(); |
|
|
|
byte serialization = byteBuf.readByte(); |
|
|
|
|
|
|
|
|
|
|
|
byte state = byteBuf.readByte(); |
|
|
|
|
|
|
|
long requestId = byteBuf.readLong(); |
|
|
|
long requestId = byteBuf.readLong(); |
|
|
|
int dataLength = byteBuf.readInt(); |
|
|
|
int dataLength = byteBuf.readInt(); |
|
|
|
|
|
|
|
|
|
|
|
byte[] data = new byte[dataLength]; |
|
|
|
byte[] data = new byte[dataLength]; |
|
|
|
byteBuf.readBytes(data); |
|
|
|
|
|
|
|
RpcProtocol rpcProtocol = new RpcProtocol(); |
|
|
|
RpcProtocol rpcProtocol = new RpcProtocol(); |
|
|
|
MessageHeader header=new MessageHeader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MessageHeader header = new MessageHeader(); |
|
|
|
header.setVersion(version); |
|
|
|
header.setVersion(version); |
|
|
|
header.setSerialization(serialization); |
|
|
|
header.setSerialization(serialization); |
|
|
|
header.setStatus(state); |
|
|
|
|
|
|
|
header.setRequestId(requestId); |
|
|
|
header.setRequestId(requestId); |
|
|
|
header.setEventType(eventType); |
|
|
|
header.setEventType(eventType); |
|
|
|
header.setMsgLength(dataLength); |
|
|
|
header.setMsgLength(dataLength); |
|
|
|
|
|
|
|
byteBuf.readBytes(data); |
|
|
|
rpcProtocol.setMsgHeader(header); |
|
|
|
rpcProtocol.setMsgHeader(header); |
|
|
|
if (eventType != EventType.HEARTBEAT.getType()) { |
|
|
|
if (eventType != EventType.HEARTBEAT.getType()) { |
|
|
|
Serializer serializer = RpcSerializer.getSerializerByType(serialization); |
|
|
|
Serializer serializer = RpcSerializer.getSerializerByType(serialization); |
|
|
@ -83,5 +79,4 @@ public class NettyDecoder extends ByteToMessageDecoder { |
|
|
|
list.add(rpcProtocol); |
|
|
|
list.add(rpcProtocol); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|