Last active
October 8, 2015 15:31
-
-
Save goldobin/a3253f117b471202b1b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.UUID | |
import java.nio.ByteBuffer | |
object UuidConverters { | |
implicit class BigIntToUuid(v: BigInt) { | |
def toUuid: UUID = { | |
val bb: ByteBuffer = ByteBuffer.wrap(v.toByteArray) | |
val high: Long = bb.getLong | |
val low: Long = bb.getLong | |
new UUID(high, low) | |
} | |
} | |
implicit class UuidToBigInt(v: UUID) { | |
def toBigInt: BigInt = { | |
val bb = ByteBuffer.allocate(16) | |
bb.putLong(v.getMostSignificantBits) | |
bb.putLong(v.getLeastSignificantBits) | |
BigInt(bb.array) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment