提交 8fd112a5 编写于 作者: T tywo45

修正一处错误,原来的写法在粘包时会有问题

上级 84edc862
......@@ -46,9 +46,9 @@ public final class MqttDecoder {
this.maxBytesInMessage = maxBytesInMessage;
}
public MqttMessage decode(ChannelContext ctx, ByteBuffer buffer) {
public MqttMessage decode(ChannelContext ctx, ByteBuffer buffer, int limit, int position, int readableLength) {
// 1. 首先判断缓存中协议头是否读完(MQTT协议头为2字节)
if (buffer.limit() < MQTT_PROTOCOL_LENGTH) {
if (readableLength < MQTT_PROTOCOL_LENGTH) {
return null;
}
// 2. 解析 FixedHeader
......
......@@ -52,7 +52,7 @@ public class MqttClientAioHandler implements ClientAioHandler {
@Override
public Packet decode(ByteBuffer buffer, int limit, int position, int readableLength, ChannelContext channelContext) throws AioDecodeException {
return mqttDecoder.decode(channelContext, buffer);
return mqttDecoder.decode(channelContext, buffer, limit, position, readableLength);
}
@Override
......
......@@ -59,7 +59,7 @@ public class MqttServerAioHandler implements ServerAioHandler {
*/
@Override
public Packet decode(ByteBuffer buffer, int limit, int position, int readableLength, ChannelContext context) throws AioDecodeException {
return mqttDecoder.decode(context, buffer);
return mqttDecoder.decode(context, buffer, limit, position, readableLength);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册