diff --git a/modules/redis-client/src/main/scala/io/renku/queue/client/Message.scala b/modules/redis-client/src/main/scala/io/renku/queue/client/Message.scala index 34652c29..aad997b6 100644 --- a/modules/redis-client/src/main/scala/io/renku/queue/client/Message.scala +++ b/modules/redis-client/src/main/scala/io/renku/queue/client/Message.scala @@ -24,17 +24,7 @@ final case class Message(id: MessageId, encoding: Encoding, payload: ByteVector) final case class MessageId(value: String) extends AnyVal -sealed trait Encoding extends Product: +enum Encoding: lazy val name: String = productPrefix - -object Encoding: - - val all: Set[Encoding] = Set(Binary, Json) - - def from(v: String): Either[IllegalArgumentException, Encoding] = - all - .find(_.productPrefix.equalsIgnoreCase(v)) - .toRight(new IllegalArgumentException(s"'$v' not a valid payload Encoding")) - - case object Binary extends Encoding - case object Json extends Encoding + case Binary + case Json diff --git a/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala index 266454b6..642502fc 100644 --- a/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala +++ b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala @@ -66,7 +66,7 @@ class RedisQueueClient[F[_]: Async: Log](client: RedisClient) extends QueueClien ByteVector.encodeUtf8(encoding.name).fold(throw _, identity) private def decodeEncoding(encoding: ByteVector): Encoding = - encoding.decodeUtf8.flatMap(Encoding.from).fold(throw _, identity) + encoding.decodeUtf8.map(Encoding.valueOf).fold(throw _, identity) override def acquireEventsStream( queueName: QueueName, diff --git a/modules/redis-client/src/test/scala/io/renku/redis/client/RedisClientGenerators.scala b/modules/redis-client/src/test/scala/io/renku/redis/client/RedisClientGenerators.scala index b83272e3..d4c4f1b7 100644 --- a/modules/redis-client/src/test/scala/io/renku/redis/client/RedisClientGenerators.scala +++ b/modules/redis-client/src/test/scala/io/renku/redis/client/RedisClientGenerators.scala @@ -30,7 +30,7 @@ object RedisClientGenerators: .flatMap(Gen.stringOfN(_, alphaLowerChar).map(QueueName(_))) val encodingGen: Gen[Encoding] = - Gen.oneOf(Encoding.all) + Gen.oneOf(Encoding.values.toSet) val clientIdGen: Gen[ClientId] = Gen