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

Serde followups #44

Merged
merged 4 commits into from Oct 4, 2019
Merged

Serde followups #44

merged 4 commits into from Oct 4, 2019

Conversation

iravid
Copy link
Member

@iravid iravid commented Oct 4, 2019

@svroonland - could you have a look?

Copy link
Collaborator

@svroonland svroonland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

def deserializeWith[R, K1, V1](
keyDeserializer: Deserializer[R, K1],
valueDeserializer: Deserializer[R, V1]
)(implicit ev1: K <:< Array[Byte], ev2: V <:< Array[Byte]): RIO[R, CommittableRecord[K1, V1]] =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting trick this subtype evidence, never used it before.

@@ -93,8 +93,8 @@ object Producer {
r: ProducerRecord[K, V]
): RIO[R, ByteArrayProducerRecord] =
for {
key <- keySerializer.serialize(r.key())
value <- valueSerializer.serialize(r.value())
key <- keySerializer.serialize(r.topic, r.headers, r.key())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
I never saw the need for the serializer to know the topic and headers, but I like the idea of not imposing that.

/**
* Obtain an instance of a Serializer of some type from the implicit scope
*/
def of[T](implicit ser: Serializer[Any, T]): Serializer[Any, T] = ser
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for removing the ofs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to move away from encouraging users to use implicit scope for the serializer/deserializer instances.

In other words - not treat them like typeclasses at all, but rather as simple functions.

@@ -48,7 +48,7 @@ class ConsumerTest extends WordSpecLike with Matchers with LazyLogging with Defa
_ <- consumer.subscribe(Subscription.Topics(Set("topic150")))
kvs <- ZIO((1 to 5).toList.map(i => (s"key$i", s"msg$i")))
_ <- produceMany("topic150", kvs)
records <- consumer.plainStream(Serde.of[String], Serde.of[String]).flattenChunks.take(5).runCollect
records <- consumer.plainStream(Serde.string, Serde.string).flattenChunks.take(5).runCollect
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that for the primitive serdes there's no advantage of Serde.of[String] over Serde.string.

@iravid iravid merged commit 1227ba5 into zio:master Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants