Skip to content

Commit 05d58b9

Browse files
committed
fix(codec): use K/Native-compatible hex encoding in toHexDump
1 parent d3c0a02 commit 05d58b9

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

  • library/src/commonMain/kotlin/org/meshtastic/mqtt/packet

library/src/commonMain/kotlin/org/meshtastic/mqtt/packet/MqttDecoder.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,16 @@ private fun decodePropertiesSection(
548548
return props to (lengthResult.bytesConsumed + propsLength)
549549
}
550550

551-
private fun ByteArray.toHexDump(): String =
552-
if (size <= 64) joinToString("") { "%02x".format(it) }
553-
else take(64).joinToString("") { "%02x".format(it) } + "...(${size} total)"
551+
private fun ByteArray.toHexDump(): String {
552+
fun Byte.hex(): String {
553+
val i = toInt() and 0xFF
554+
val hi = "0123456789abcdef"[i ushr 4]
555+
val lo = "0123456789abcdef"[i and 0x0F]
556+
return "$hi$lo"
557+
}
558+
return if (size <= 64) joinToString("") { it.hex() }
559+
else take(64).joinToString("") { it.hex() } + "...(${size} total)"
560+
}
554561

555562
/**
556563
* Map an MQTT 3.1.1 CONNACK return code (§3.2.2.3) to a [ReasonCode].

0 commit comments

Comments
 (0)