Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.math.Ordered
- case class IPv4Addr(val address: Int)
- extends AnyVal
- with Product4[Byte, Byte, Byte, Byte]
- // with Ordered[IPv4Addr]
- {
- @inline def _1: Byte = (address & 0xff).toByte
- @inline def _2: Byte = ((address >>> 8) & 0xff).toByte
- @inline def _3: Byte = ((address >>> 16) & 0xff).toByte
- @inline def _4: Byte = ((address >>> 24) & 0xff).toByte
- def toBytes: Array[Byte] = Array(_1, _2, _3, _4)
- @inline private def printByte(byte: Byte): String =
- (byte.toInt + 128).toString
- override def toString(): String =
- s"${printByte(_1)}.${printByte(_2)}.${printByte(_3)}.${printByte(_4)}"
- }
- object IPv4Addr {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement