Require complete MacAddressCompat
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user