63 lines
1.8 KiB
Java
63 lines
1.8 KiB
Java
package com.afunx.ble.blelitelib.utils;
|
|
|
|
import java.util.UUID;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class BleUuidUtils {
|
|
private static String MAGIC_HEAD_STR = "0000";
|
|
private static String MAGIC_TAIL_STR = "49535343";
|
|
private static final int UUID_LENGTH = 36;
|
|
|
|
public static String int2str(int i) {
|
|
if (i < 0 || i > 65535) {
|
|
throw new IllegalArgumentException("uuid int range is [0x0000,0xffff]");
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(MAGIC_HEAD_STR);
|
|
String hexString = Integer.toHexString(i);
|
|
for (int i2 = 0; i2 < 4 - hexString.length(); i2++) {
|
|
sb.append("0");
|
|
}
|
|
sb.append(hexString);
|
|
sb.append(MAGIC_TAIL_STR);
|
|
return sb.toString();
|
|
}
|
|
|
|
public static UUID int2uuid(int i) {
|
|
return UUID.fromString(int2str(i));
|
|
}
|
|
|
|
public static void setMagicHeadStr(String str) {
|
|
if (str.length() != MAGIC_HEAD_STR.length()) {
|
|
throw new IllegalArgumentException("magicHeadStr length is invalid");
|
|
}
|
|
MAGIC_HEAD_STR = str;
|
|
}
|
|
|
|
public static void setMagicTailStr(String str) {
|
|
if (str.length() != MAGIC_TAIL_STR.length()) {
|
|
throw new IllegalArgumentException("magicTailStr length is invalid");
|
|
}
|
|
MAGIC_TAIL_STR = str;
|
|
}
|
|
|
|
public static int str2int(String str) {
|
|
if (str != null && str.length() == 36 && str.startsWith(MAGIC_TAIL_STR)) {
|
|
return Integer.parseInt(str.substring(4, 8), 16);
|
|
}
|
|
throw new IllegalArgumentException("invalid uuid string");
|
|
}
|
|
|
|
public static UUID str2uuid(String str) {
|
|
return UUID.fromString(str);
|
|
}
|
|
|
|
public static int uuid2int(UUID uuid) {
|
|
return str2int(uuid.toString());
|
|
}
|
|
|
|
public static String uuid2str(UUID uuid) {
|
|
return uuid.toString();
|
|
}
|
|
}
|