From 99bc815e07e39354f51421b77f4012ffd35594d8 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 28 六月 2023 18:03:00 +0800
Subject: [PATCH] 2023年06月28日18:02:58

---
 HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java |  150 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 150 insertions(+), 0 deletions(-)

diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java
new file mode 100644
index 0000000..2f8e8d7
--- /dev/null
+++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/bean/LinkRequest.java
@@ -0,0 +1,150 @@
+package com.hdl.sdk.link.core.bean;
+
+import android.text.TextUtils;
+
+import com.hdl.sdk.link.common.utils.ByteUtils;
+
+
+/**
+ * Created by Tong on 2021/9/29.
+ */
+public class LinkRequest {
+    private String topic;
+    private String replyTopic;
+    protected byte []data;
+    private int length=0;
+
+    private boolean encrypt;
+
+    public String getCloudTopic() {
+        if(TextUtils.isEmpty(cloudTopic)){
+            return topic;
+        }
+        return cloudTopic;
+    }
+
+    /**
+     * 骞冲彴topic
+     * @param cloudTopic
+     */
+    public void setCloudTopic(String cloudTopic) {
+        this.cloudTopic = cloudTopic;
+    }
+
+    private String cloudTopic;
+
+
+    public LinkRequest(String topic,String replyTopic, String data, boolean encrypt) {
+        this.topic = topic;
+        this.replyTopic=replyTopic;
+        setData(data);
+        this.encrypt = encrypt;
+    }
+
+    public LinkRequest(String topic, String data, boolean encrypt) {
+        this(topic,null,data,encrypt);
+    }
+    public LinkRequest(String topic, byte []data, boolean encrypt) {
+        this.topic = topic;
+        setData(data);
+        this.encrypt = encrypt;
+    }
+
+    protected LinkRequest(){}
+
+    public String getTopic() {
+        return topic;
+    }
+
+    public void setTopic(String topic) {
+        this.topic = topic;
+    }
+
+    public byte[] getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        if (!TextUtils.isEmpty(data)) {
+            this.data = ByteUtils.stringToBytes(data);
+            setLength(this.data.length);
+        }
+    }
+
+    public void setData(byte []data) {
+        this.data = data;
+        if(data!=null){
+            setLength(data.length);
+        }
+    }
+
+    public int getLength() {
+        return length;
+    }
+
+    private void setLength(int length) {
+        this.length = length;
+    }
+
+    /**
+     * 鍔犲瘑鏍囪瘑
+     *
+     * @return
+     */
+    public boolean isEncrypt() {
+        return encrypt;
+    }
+
+    /**
+     * 鍔犲瘑鏍囪瘑
+     *
+     * @param encrypt
+     */
+    public void setEncrypt(boolean encrypt) {
+        this.encrypt = encrypt;
+    }
+
+    public String getReplyTopic() {
+        if(TextUtils.isEmpty(replyTopic)){
+            return topic+"_reply";
+        }
+        return replyTopic;
+    }
+
+    public void setReplyTopic(String replyTopic) {
+        this.replyTopic = replyTopic;
+    }
+
+    public byte [] getSendBytes() {
+        try {
+            String header = "Topic:" +
+                    getTopic() +
+                    "\r\n" +
+                    "Length:" +
+                    getLength() +
+                    "\r\n\r\n";
+            return ByteUtils.concatBytes(header.getBytes("utf-8"), getData());
+        } catch (Exception e) {
+            return new byte[]{};
+        }
+    }
+
+    public byte [] getCloudSendBytes() {
+        try {
+            //link閫忎紶鍛戒护锛屽唴瀹归渶瑕佸寘鍚富棰橈紝闀垮害
+            if(getCloudTopic().contains("/native/a/down/slaveoid/")){
+                return getSendBytes();
+            }else {
+                return getData();
+            }
+        } catch (Exception e) {
+            return new byte[]{};
+        }
+    }
+
+
+    private int getBytesLength(String str) {
+        return ByteUtils.stringToBytes(str).length;
+    }
+
+}

--
Gitblit v1.8.0