diff --git a/build.sbt b/build.sbt index 336bfd9..12c9b16 100644 --- a/build.sbt +++ b/build.sbt @@ -15,7 +15,8 @@ lazy val `teleproto` = .settings(Project.inConfig(Test)(sbtprotoc.ProtocPlugin.protobufConfigSettings): _*) .settings( name := "teleproto", - version := "1.11.0", + version := "1.12.0", + versionScheme := Some("early-semver"), libraryDependencies ++= Seq( library.scalaPB % "protobuf;compile", library.scalaPBJson % Compile, diff --git a/src/main/scala/io/moia/protos/teleproto/Reader.scala b/src/main/scala/io/moia/protos/teleproto/Reader.scala index 1717b38..25508f6 100644 --- a/src/main/scala/io/moia/protos/teleproto/Reader.scala +++ b/src/main/scala/io/moia/protos/teleproto/Reader.scala @@ -17,11 +17,11 @@ package io.moia.protos.teleproto import java.time.{Instant, LocalTime} - import com.google.protobuf.duration.{Duration => PBDuration} import com.google.protobuf.timestamp.Timestamp import scalapb.GeneratedMessage +import java.util.UUID import scala.annotation.implicitNotFound import scala.collection.compat._ import scala.collection.immutable.TreeMap @@ -160,6 +160,13 @@ object Reader extends LowPriorityReads { PbSuccess((Duration(protobuf.seconds, SECONDS) + Duration(protobuf.nanos.toLong, NANOSECONDS)).toCoarsest) } + /** + * Transforms a string into a UUID. + */ + implicit object UUIDReader extends Reader[String, UUID] { + def read(uuid: String): PbResult[UUID] = Try(PbSuccess(UUID.fromString(uuid))).getOrElse(PbFailure("Value must be a UUID.")) + } + /** * Transforms a PB timestamp as fixed point in time (with milliseconds precision) into a Scala concurrent deadline. * diff --git a/src/main/scala/io/moia/protos/teleproto/Writer.scala b/src/main/scala/io/moia/protos/teleproto/Writer.scala index 467a683..28a50b3 100644 --- a/src/main/scala/io/moia/protos/teleproto/Writer.scala +++ b/src/main/scala/io/moia/protos/teleproto/Writer.scala @@ -20,6 +20,7 @@ import com.google.protobuf.duration.{Duration => PBDuration} import com.google.protobuf.timestamp.Timestamp import java.time.{Instant, LocalTime} +import java.util.UUID import scala.annotation.implicitNotFound import scala.collection.compat._ import scala.collection.immutable.TreeMap @@ -129,6 +130,13 @@ object Writer extends LowPriorityWrites { PBDuration(duration.toSeconds, (duration.toNanos % 1000000000).toInt) } + /** + * Writes a UUID as string. + */ + implicit object UUIDWriter extends Writer[UUID, String] { + def write(uuid: UUID): String = uuid.toString + } + /** * Writes a Scala deadline into a ScalaPB Timestamp as fixed point in time. *