Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bytes Serde #538

Merged
merged 2 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ object SerdeSpec extends ZIOSpecDefault {

val testDataStructureSerde = Serde.string.inmap[TestDataStructure](TestDataStructure.apply)(_.value)

private val anyBytes = Gen.listOf(Gen.byte).map(bytes => new org.apache.kafka.common.utils.Bytes(bytes.toArray))

override def spec = suite("Serde")(
testSerde(Serde.string, Gen.string),
testSerde(Serde.int, Gen.int),
Expand All @@ -19,6 +21,7 @@ object SerdeSpec extends ZIOSpecDefault {
testSerde(Serde.double, Gen.double),
testSerde(Serde.long, Gen.long),
testSerde(Serde.uuid, Gen.uuid),
testSerde(Serde.bytes, anyBytes),
testSerde(Serde.byteArray, Gen.listOf(Gen.byte).map(_.toArray)),
suite("asOption")(
test("serialize and deserialize None values to null and visa versa") {
Expand Down
2 changes: 2 additions & 0 deletions zio-kafka/src/main/scala/zio/kafka/serde/Serdes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zio.kafka.serde

import org.apache.kafka.common.header.Headers
import org.apache.kafka.common.serialization.{ Serde => KafkaSerde, Serdes => KafkaSerdes }
import org.apache.kafka.common.utils.Bytes
import zio.{ RIO, ZIO }

import java.nio.ByteBuffer
Expand All @@ -15,6 +16,7 @@ private[zio] trait Serdes {
lazy val double: Serde[Any, Double] = convertPrimitiveSerde(KafkaSerdes.Double()).inmap(Double2double)(double2Double)
lazy val string: Serde[Any, String] = convertPrimitiveSerde(KafkaSerdes.String())
lazy val byteArray: Serde[Any, Array[Byte]] = convertPrimitiveSerde(KafkaSerdes.ByteArray())
lazy val bytes: Serde[Any, Bytes] = convertPrimitiveSerde(KafkaSerdes.Bytes())
lazy val byteBuffer: Serde[Any, ByteBuffer] = convertPrimitiveSerde(KafkaSerdes.ByteBuffer())
lazy val uuid: Serde[Any, UUID] = convertPrimitiveSerde(KafkaSerdes.UUID())

Expand Down