邵洋 пре 1 година
родитељ
комит
49b011fae3

+ 98 - 0
pole-service/src/main/java/com/zksy/pole/MQTTServer/request/MqttRequest.java

@@ -0,0 +1,98 @@
+package com.zksy.pole.MQTTServer.request;
+
+
+/**
+ * @author: shaoyang
+ * @date: 2024-03-13 15:58
+ * @description: 请求消息体
+ **/
+public class MqttRequest {
+    private boolean mutable = true;
+    private byte[] payload;
+    private MqttQoS qos = MqttQoS.AT_LEAST_ONCE;
+    private boolean retained = false;
+    private boolean dup = false;
+    private int messageId;
+
+    public MqttRequest() {
+        this.setPayload(new byte[0]);
+    }
+
+    public MqttRequest(byte[] payload) {
+        this.setPayload(payload);
+    }
+    public MqttRequest(byte[] payload, MqttQoS qos) {
+        this.setPayload(payload);
+        this.setQos(qos);
+    }
+
+    public byte[] getPayload() {
+        return this.payload;
+    }
+
+    public void clearPayload() {
+        this.checkMutable();
+        this.payload = new byte[0];
+    }
+
+    public void setPayload(byte[] payload) {
+        this.checkMutable();
+        if (payload == null) {
+            throw new NullPointerException();
+        } else {
+            this.payload = payload;
+        }
+    }
+
+    public boolean isRetained() {
+        return this.retained;
+    }
+
+    public void setRetained(boolean retained) {
+        this.checkMutable();
+        this.retained = retained;
+    }
+
+    public MqttQoS getQos() {
+        return qos;
+    }
+
+    public void setQos(MqttQoS qos) {
+        this.qos = qos;
+    }
+
+    public boolean isMutable() {
+        return mutable;
+    }
+
+    public void setMutable(boolean mutable) {
+        this.mutable = mutable;
+    }
+
+    protected void checkMutable() throws IllegalStateException {
+        if (!this.mutable) {
+            throw new IllegalStateException();
+        }
+    }
+
+    public boolean isDup() {
+        return dup;
+    }
+
+    public void setDup(boolean dup) {
+        this.dup = dup;
+    }
+
+    public int getMessageId() {
+        return messageId;
+    }
+
+    public void setMessageId(int messageId) {
+        this.messageId = messageId;
+    }
+
+    @Override
+    public String toString() {
+        return new String(this.payload);
+    }
+}