Skip to content

Commit

Permalink
Merge pull request #18 from narma/store_bytearray_properly
Browse files Browse the repository at this point in the history
add codec for bytearray
  • Loading branch information
myazinn authored Sep 9, 2022
2 parents 3127578 + 242872d commit 42b790a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package zio.cassandra.session.cql.codec

import com.datastax.oss.driver.api.core.ProtocolVersion
import com.datastax.oss.driver.api.core.`type`.DataType
import com.datastax.oss.driver.api.core.`type`.codec.TypeCodecs
import com.datastax.oss.driver.api.core.`type`.codec.{ ExtraTypeCodecs, TypeCodecs }
import com.datastax.oss.driver.api.core.`type`.codec.registry.CodecRegistry
import com.datastax.oss.driver.api.core.data.UdtValue
import com.datastax.oss.driver.internal.core.`type`.{ DefaultListType, DefaultMapType, DefaultSetType }
Expand Down Expand Up @@ -64,6 +64,7 @@ trait CellReadsInstances1 extends CellReadsInstances2 {
implicit val uuidCellReads: CellReads[UUID] = withCheckedNull(TypeCodecs.UUID.decode)

implicit val byteBufferCellReads: CellReads[ByteBuffer] = withCheckedNull(TypeCodecs.BLOB.decode)
implicit val byteArrayCellReads: CellReads[Array[Byte]] = withCheckedNull(ExtraTypeCodecs.BLOB_TO_ARRAY.decode)

private def withCheckedNull[T](f: (ByteBuffer, ProtocolVersion) => T): CellReads[T] =
instance { (bytes, protocol) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zio.cassandra.session.cql.codec

import com.datastax.oss.driver.api.core.ProtocolVersion
import com.datastax.oss.driver.api.core.`type`.codec.TypeCodecs
import com.datastax.oss.driver.api.core.`type`.codec.{ ExtraTypeCodecs, TypeCodecs }
import com.datastax.oss.driver.api.core.`type`.codec.registry.CodecRegistry
import com.datastax.oss.driver.api.core.`type`.{ DataType, UserDefinedType }
import com.datastax.oss.driver.api.core.data.UdtValue
Expand Down Expand Up @@ -64,6 +64,7 @@ trait CellWritesInstances1 extends CellWritesInstances2 {
implicit val uuidCellWrites: CellWrites[UUID] = instance_(TypeCodecs.UUID.encode)

implicit val byteBufferCellWrites: CellWrites[ByteBuffer] = instance_(TypeCodecs.BLOB.encode)
implicit val byteArrayCellWrites: CellWrites[Array[Byte]] = instance_(ExtraTypeCodecs.BLOB_TO_ARRAY.encode)

private def instance_[T](f: (T, ProtocolVersion) => ByteBuffer): CellWrites[T] =
instance((t, p) => f(t, p))
Expand Down

0 comments on commit 42b790a

Please sign in to comment.