Created
June 29, 2015 07:38
-
-
Save velvia/909408dc6f053d6934be to your computer and use it in GitHub Desktop.
Patch to Phantom 1.8.x for ByteBuffer handling
This file contains hidden or 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
// Primitive.scala - only change is asCql method | |
implicit object BlobIsPrimitive extends Primitive[ByteBuffer] { | |
override type PrimitiveType = java.nio.ByteBuffer | |
val cassandraType = CQLSyntax.Types.Blob | |
override def fromRow(column: String, row: Row): Try[ByteBuffer] = nullCheck(column, row) { | |
r => r.getBytes(column) | |
} | |
override def asCql(value: ByteBuffer): String = Bytes.toHexString(value) | |
override def fromString(value: String): ByteBuffer = Bytes.fromHexString(value) | |
override def clz: Class[java.nio.ByteBuffer] = classOf[java.nio.ByteBuffer] | |
} | |
// Addition to PrimitiveTest.scala | |
it should "convert ByteBuffers to valid hex bytes" in { | |
val buf = ByteBuffer.wrap(Array[Byte](1, 2, 3, 4, 5)) | |
Primitive[ByteBuffer].asCql(buf) shouldEqual "0x0102030405" | |
buf.position(2) // Non-zero position | |
Primitive[ByteBuffer].asCql(buf) shouldEqual "0x030405" | |
val slice = buf.slice() // Slice with non-zero arrayOffset | |
Primitive[ByteBuffer].asCql(slice) shouldEqual "0x030405" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment