From 14de918a79943e4961b09fa01ed320c6cad41f2e Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 28 六月 2023 17:14:51 +0800 Subject: [PATCH] Revert "Revert "Merge branch 'hxb' into wjc"" --- HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java | 74 +++++++++++++++++++++++++++++++++++++ 1 files changed, 74 insertions(+), 0 deletions(-) diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java new file mode 100644 index 0000000..92a611b --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/ProtocolParse.java @@ -0,0 +1,74 @@ +package com.hdl.sdk.link.core.utils; + +import android.text.TextUtils; + +/** + * Created by Tong on 2021/9/22. + * 瑙f瀽Link鍗忚 + */ +public class ProtocolParse { + + private String topic; + private int length; + private int dataIndex; + + public ProtocolParse(byte[] bytes) { + parse(bytes); + } + + private void parse(byte[] bytes) { + try { + String[] split = new String(bytes, "utf-8").split("\r\n"); + setTopic(parseTopic(split)); + setLength(parseLength(split)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static String parseTopic(String[] bytes) { + try { + for (String s : bytes) { + if (s.startsWith("Topic:")) { + return s.replace("Topic:", ""); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static int parseLength(String[] bytes) { + try { + for (String s : bytes) { + if (!TextUtils.isEmpty(s) && s.startsWith("Length:")) { + return Integer.parseInt(s.replace("Length:", "")); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return -1; + } + + + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + + +} -- Gitblit v1.8.0