Require complete MacAddressCompat

This commit is contained in:
Mygod
2020-06-05 13:46:48 -04:00
parent e6da1a911e
commit 478ed93a10

View File

@@ -58,11 +58,13 @@ inline class MacAddressCompat(val addr: Long) {
*/ */
fun fromString(addr: String) = ByteBuffer.allocate(Long.SIZE_BYTES).run { fun fromString(addr: String) = ByteBuffer.allocate(Long.SIZE_BYTES).run {
order(ByteOrder.LITTLE_ENDIAN) order(ByteOrder.LITTLE_ENDIAN)
try { val bytes = try {
put(addr.split(':').map { Integer.parseInt(it, 16).toByte() }.toByteArray()) addr.split(':').map { Integer.parseInt(it, 16).toByte() }.toByteArray()
} catch (e: NumberFormatException) { } catch (e: NumberFormatException) {
throw IllegalArgumentException(e) throw IllegalArgumentException(e)
} }
require(bytes.size == ETHER_ADDR_LEN)
put(bytes)
rewind() rewind()
MacAddressCompat(long) MacAddressCompat(long)
} }