diff --git a/src/main/java/io/github/yezhihao/netmc/codec/MessageDecoderWrapper.java b/src/main/java/io/github/yezhihao/netmc/codec/MessageDecoderWrapper.java index c41915c..2afa06b 100644 --- a/src/main/java/io/github/yezhihao/netmc/codec/MessageDecoderWrapper.java +++ b/src/main/java/io/github/yezhihao/netmc/codec/MessageDecoderWrapper.java @@ -2,13 +2,10 @@ package io.github.yezhihao.netmc.codec; import io.github.yezhihao.netmc.session.Session; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.codec.DecoderException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * 基础消息解码 @@ -18,8 +15,6 @@ import org.slf4j.LoggerFactory; @ChannelHandler.Sharable public class MessageDecoderWrapper extends ChannelInboundHandlerAdapter { - private static final Logger log = LoggerFactory.getLogger(MessageDecoderWrapper.class.getSimpleName()); - private MessageDecoder decoder; public MessageDecoderWrapper(MessageDecoder decoder) { @@ -31,14 +26,6 @@ public class MessageDecoderWrapper extends ChannelInboundHandlerAdapter { if (msg instanceof ByteBuf) { ByteBuf buf = (ByteBuf) msg; try { - if (log.isInfoEnabled()) { - String hex; - if (buf.readableBytes() < 1048) - hex = ByteBufUtil.hexDump(buf); - else - hex = ByteBufUtil.hexDump(buf.slice(0, 32)) + "..." + ByteBufUtil.hexDump(buf.slice(buf.readableBytes() - 32, 32)); - log.info("<<<<<[ip={}],payload={}", ctx.channel().remoteAddress(), hex); - } Object message = decoder.decode(buf, ctx.channel().attr(Session.KEY).get()); if (message != null) ctx.fireChannelRead(message); diff --git a/src/main/java/io/github/yezhihao/netmc/codec/MessageEncoder.java b/src/main/java/io/github/yezhihao/netmc/codec/MessageEncoder.java index 01caa2c..646450a 100644 --- a/src/main/java/io/github/yezhihao/netmc/codec/MessageEncoder.java +++ b/src/main/java/io/github/yezhihao/netmc/codec/MessageEncoder.java @@ -1,5 +1,6 @@ package io.github.yezhihao.netmc.codec; +import io.github.yezhihao.netmc.session.Session; import io.netty.buffer.ByteBuf; /** @@ -11,4 +12,6 @@ public interface MessageEncoder { ByteBuf encode(T message); + ByteBuf encode(T message, Session session); + } \ No newline at end of file diff --git a/src/main/java/io/github/yezhihao/netmc/codec/MessageEncoderWrapper.java b/src/main/java/io/github/yezhihao/netmc/codec/MessageEncoderWrapper.java index e549817..28614f9 100644 --- a/src/main/java/io/github/yezhihao/netmc/codec/MessageEncoderWrapper.java +++ b/src/main/java/io/github/yezhihao/netmc/codec/MessageEncoderWrapper.java @@ -1,15 +1,13 @@ package io.github.yezhihao.netmc.codec; +import io.github.yezhihao.netmc.session.Session; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; import io.netty.handler.codec.EncoderException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * 基础消息编码 @@ -19,8 +17,6 @@ import org.slf4j.LoggerFactory; @ChannelHandler.Sharable public class MessageEncoderWrapper extends ChannelOutboundHandlerAdapter { - private static final Logger log = LoggerFactory.getLogger(MessageEncoderWrapper.class.getSimpleName()); - private MessageEncoder encoder; public MessageEncoderWrapper(MessageEncoder encoder) { @@ -34,9 +30,7 @@ public class MessageEncoderWrapper extends ChannelOutboundHandlerAdapter { if (msg instanceof ByteBuf) buf = (ByteBuf) msg; else - buf = encoder.encode(msg); - if (log.isInfoEnabled()) - log.info(">>>>>[ip={}],payload={}", ctx.channel().remoteAddress(), ByteBufUtil.hexDump(buf)); + buf = encoder.encode(msg, ctx.channel().attr(Session.KEY).get()); if (buf.isReadable()) { ctx.write(buf, promise);