提交 0a39a6c7 编写于 作者: 如梦技术's avatar 如梦技术 🐛

完成 mqtt5 协议.

上级 03d7b3fd
......@@ -13,9 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
......
......@@ -17,11 +17,9 @@
package net.dreamlu.iot.mqtt.codec;
import org.tio.core.ChannelContext;
import org.tio.utils.hutool.FastByteBuffer;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -557,7 +555,6 @@ public final class MqttEncoder {
writeBuffer.writeVarLengthInt(propertiesBytes.length);
writeBuffer.writeBytes(propertiesBytes);
return writeBuffer.toArray();
// return writeBuffer.toArray();
}
private static int getFixedHeaderByte1(MqttFixedHeader header) {
......@@ -584,11 +581,6 @@ public final class MqttEncoder {
} while (num > 0);
}
private static void writeEagerUTF8String(WriteBuffer buf, String s) {
final int utf8Length = buf.writeUtf8(s);
buf.writeShort((short) utf8Length);
}
private static int getVariableLengthInt(int num) {
int count = 0;
do {
......@@ -598,6 +590,16 @@ public final class MqttEncoder {
return count;
}
private static void writeEagerUTF8String(WriteBuffer buf, String s) {
if (s == null) {
buf.writeShort((short) 0);
} else {
byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
buf.writeShort((short) bytes.length);
buf.writeBytes(bytes);
}
}
private static byte[] encodeStringUtf8(String s) {
return s.getBytes(StandardCharsets.UTF_8);
}
......
......@@ -16,7 +16,6 @@
package net.dreamlu.iot.mqtt.codec;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......
......@@ -45,16 +45,15 @@ public class MqttBrokerProcessorImpl implements MqttServerProcessor {
// 3. 设置 clientId
context.setBsId(clientId);
// 4. 返回 ack
// MqttProperties mqttProperties = new MqttProperties();
//
// MqttProperties.UserProperties userProperty = new MqttProperties.UserProperties();
// userProperty.add("xxxxxxxxxx", "xxxx");
// mqttProperties.add(userProperty);
MqttProperties mqttProperties = new MqttProperties();
MqttProperties.UserProperties userProperty = new MqttProperties.UserProperties();
userProperty.add("xxxxxxxxxx", "xxxx");
mqttProperties.add(userProperty);
MqttMessage message = MqttMessageBuilders.connAck()
.returnCode(MqttConnectReturnCode.CONNECTION_ACCEPTED)
.sessionPresent(false)
// .properties(mqttProperties)
.properties(mqttProperties)
.build();
Tio.send(context, message);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册