tbel: added new version tbel and new test hexToBytes
This commit is contained in:
parent
8e7d70c5b3
commit
7fcb82cea9
@ -598,6 +598,11 @@ public class TbUtils {
|
||||
if (len % 2 > 0) {
|
||||
throw new IllegalArgumentException("Hex string must be even-length.");
|
||||
}
|
||||
int radix = isHexadecimal(value);
|
||||
if (radix != HEX_RADIX) {
|
||||
throw new NumberFormatException("Value: \"" + value + "\" is not numeric or hexDecimal format!");
|
||||
}
|
||||
|
||||
ExecutionArrayList<Byte> data = new ExecutionArrayList<>(ctx);
|
||||
for (int i = 0; i < hex.length(); i += 2) {
|
||||
// Extract two characters from the hex string
|
||||
|
||||
@ -668,6 +668,26 @@ public class TbUtilsTest {
|
||||
Assertions.assertEquals(expectedBe, actualBe);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hexToBytes_Test() {
|
||||
String input = "0x01752B0367FA000500010488FFFFFFFFFFFFFFFF33";
|
||||
byte[] expected = {1, 117, 43, 3, 103, -6, 0, 5, 0, 1, 4, -120, -1, -1, -1, -1, -1, -1, -1, -1, 51};
|
||||
List<Byte> actual = TbUtils.hexToBytes(ctx, input);
|
||||
Assertions.assertEquals(toList(expected), actual);
|
||||
try {
|
||||
input = "0x01752B0367FA000500010488FFFFFFFFFFFFFFFF3";
|
||||
actual = TbUtils.hexToBytes(ctx, input);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Assertions.assertTrue(e.getMessage().contains("Hex string must be even-length."));
|
||||
}
|
||||
try {
|
||||
input = "0x01752B0367KA000500010488FFFFFFFFFFFFFFFF33";
|
||||
actual = TbUtils.hexToBytes(ctx, input);
|
||||
} catch (NumberFormatException e) {
|
||||
Assertions.assertTrue(e.getMessage().contains("Value: \"" + input + "\" is not numeric or hexDecimal format!"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void floatToHex_Test() {
|
||||
Float value = 123456789.00f;
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -83,7 +83,7 @@
|
||||
<zookeeper.version>3.9.2</zookeeper.version>
|
||||
<protobuf.version>3.25.3</protobuf.version> <!-- A Major v4 does not support by the pubsub yet-->
|
||||
<grpc.version>1.63.0</grpc.version>
|
||||
<tbel.version>1.2.1</tbel.version>
|
||||
<tbel.version>1.2.2</tbel.version>
|
||||
<lombok.version>1.18.32</lombok.version>
|
||||
<paho.client.version>1.2.5</paho.client.version>
|
||||
<paho.mqttv5.client.version>1.2.5</paho.mqttv5.client.version>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user