-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update gitignore * add a protobuf example of a custom deserializer
- Loading branch information
1 parent
0e1d39e
commit 2147a15
Showing
6 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20") | ||
|
||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.3") | ||
|
||
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
syntax = "proto2"; | ||
|
||
package io.example.conduktor.custom.deserializers; | ||
|
||
message Person { | ||
required string name = 1; | ||
required int32 id = 2; | ||
optional string email = 3; | ||
|
||
enum PhoneType { | ||
MOBILE = 0; | ||
HOME = 1; | ||
WORK = 2; | ||
} | ||
|
||
message PhoneNumber { | ||
required string number = 1; | ||
optional PhoneType type = 2 [default = HOME]; | ||
} | ||
|
||
repeated PhoneNumber phones = 4; | ||
} | ||
|
||
message AddressBook { | ||
repeated Person people = 1; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/scala/io/example/conduktor/custom/deserializers/MyCustomProtobufDeserializer.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.example.conduktor.custom.deserializers | ||
|
||
import org.apache.kafka.common.serialization.{Deserializer, Serializer} | ||
import io.example.conduktor.custom.deserializers.addressbook._ | ||
|
||
final class MyCustomProtobufSerializer extends Serializer[Person] { | ||
override def serialize(topic: String, data: Person): Array[Byte] = data.toByteArray | ||
} | ||
|
||
final class MyCustomProtobufDeserializer extends Deserializer[Person] { | ||
override def deserialize(topic: String, data: Array[Byte]): Person = { | ||
Person.parseFrom(data) | ||
} | ||
} |