Skip to content

Commit 5a5fc0b

Browse files
author
Peng Hu
committed
change file name
1 parent e917034 commit 5a5fc0b

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/main/java/info/xiaomo/gengine/network/NetworkServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected void initChannel(Channel ch) {
148148
pip.addLast(new WebSocketServerProtocolHandler("/"));
149149
pip.addLast(new WebSocketDecoder());
150150
pip.addLast(new WebSocketEncoder());
151-
pip.addLast(new DefaultProtobufDecoder(builder.getMessagePool()));
151+
pip.addLast(new MessageDecoder(builder.getMessagePool()));
152152
pip.addLast(
153153
new MessageExecutor(
154154
builder.getConsumer(),
@@ -176,9 +176,9 @@ protected void initChannel(Channel ch) {
176176
int lengthFieldLength = 4;
177177
int ignoreLength = 0;
178178
pip.addLast(new LengthFieldBasedFrameDecoder(maxLength, offset, lengthFieldLength, ignoreLength, lengthFieldLength));
179-
pip.addLast(new DefaultProtobufDecoder(builder.getMessagePool()));
179+
pip.addLast(new MessageDecoder(builder.getMessagePool()));
180180
pip.addLast(new LengthFieldPrepender(4));
181-
pip.addLast(new DefaultProtobufEncoder(builder.getMessagePool()));
181+
pip.addLast(new MessageEncoder(builder.getMessagePool()));
182182
pip.addLast(
183183
new MessageExecutor(
184184
builder.getConsumer(),

src/main/java/info/xiaomo/gengine/network/client/Client.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import java.util.concurrent.*;
99
import info.xiaomo.gengine.network.client.listener.ChannelConnectListener;
1010
import info.xiaomo.gengine.network.client.listener.ChannelDisconnectedListener;
11-
import info.xiaomo.gengine.network.handler.DefaultProtobufDecoder;
12-
import info.xiaomo.gengine.network.handler.DefaultProtobufEncoder;
11+
import info.xiaomo.gengine.network.handler.MessageDecoder;
12+
import info.xiaomo.gengine.network.handler.MessageEncoder;
1313
import io.netty.bootstrap.Bootstrap;
1414
import io.netty.channel.*;
1515
import io.netty.channel.nio.NioEventLoopGroup;
@@ -91,9 +91,9 @@ protected void initChannel(SocketChannel ch) {
9191
"Idle", new IdleStateHandler(builder.getMaxIdleTime(), 0, 0));
9292
}
9393
pip.addLast(new LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
94-
pip.addLast(new DefaultProtobufDecoder(builder.getMsgPool()));
94+
pip.addLast(new MessageDecoder(builder.getMsgPool()));
9595
pip.addLast(new LengthFieldPrepender(4));
96-
pip.addLast(new DefaultProtobufEncoder(builder.getMsgPool()));
96+
pip.addLast(new MessageEncoder(builder.getMsgPool()));
9797
pip.addLast(
9898
"NettyMessageExecutor",
9999
new ClientMessageExecutor(

src/main/java/info/xiaomo/gengine/network/handler/DefaultProtobufDecoder.java renamed to src/main/java/info/xiaomo/gengine/network/handler/MessageDecoder.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
package info.xiaomo.gengine.network.handler;
22

33
import com.google.protobuf.Message;
4+
45
import java.util.List;
56
import java.util.Objects;
7+
68
import info.xiaomo.gengine.network.IMessagePool;
79
import io.netty.buffer.ByteBuf;
810
import io.netty.channel.ChannelHandlerContext;
911
import io.netty.handler.codec.ByteToMessageDecoder;
1012
import lombok.extern.slf4j.Slf4j;
1113

1214
@Slf4j
13-
public class DefaultProtobufDecoder extends ByteToMessageDecoder {
15+
public class MessageDecoder extends ByteToMessageDecoder {
1416

15-
private IMessagePool pool;
17+
private final IMessagePool pool;
1618

17-
public DefaultProtobufDecoder(IMessagePool pool) {
19+
public MessageDecoder(IMessagePool pool) {
1820
this.pool = pool;
1921
}
2022

2123
@Override
2224
protected void decode(
23-
ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list)
25+
ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> out)
2426
throws Exception {
2527
int msgId = byteBuf.readInt();
2628
byte[] bytes = new byte[byteBuf.readableBytes()];
@@ -30,7 +32,8 @@ protected void decode(
3032

3133
if (message == null) {
3234
log.error("解码到未注册的消息id:{}", msgId);
35+
return;
3336
}
34-
list.add(Objects.requireNonNull(message).getParserForType().parseFrom(bytes));
37+
out.add(message.getParserForType().parseFrom(bytes));
3538
}
3639
}

src/main/java/info/xiaomo/gengine/network/handler/DefaultProtobufEncoder.java renamed to src/main/java/info/xiaomo/gengine/network/handler/MessageEncoder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import lombok.extern.slf4j.Slf4j;
99

1010
@Slf4j
11-
public class DefaultProtobufEncoder extends MessageToByteEncoder<Message> {
11+
public class MessageEncoder extends MessageToByteEncoder<Message> {
1212

13-
private IMessagePool pool;
13+
private final IMessagePool pool;
1414

15-
public DefaultProtobufEncoder(IMessagePool pool) {
15+
public MessageEncoder(IMessagePool pool) {
1616
this.pool = pool;
1717
}
1818

@@ -31,6 +31,7 @@ protected void encode(
3131
boolean writable = byteBuf.isWritable(length);
3232
if (!writable) {
3333
log.error("消息过大,编码失败:{}:{}", msgId, length);
34+
return;
3435
}
3536

3637
byteBuf.writeInt(msgId);

0 commit comments

Comments
 (0)