mirror of
https://github.com/fluencelabs/codec
synced 2025-04-25 06:42:14 +00:00
add protobuf codecs, change version
This commit is contained in:
parent
6efaac148b
commit
0caafa60b7
@ -14,7 +14,7 @@ val scalaV = scalaVersion := "2.12.5"
|
||||
|
||||
val commons = Seq(
|
||||
scalaV,
|
||||
version := "0.0.3",
|
||||
version := "0.0.4",
|
||||
fork in Test := true,
|
||||
parallelExecution in Test := false,
|
||||
organization := "one.fluence",
|
||||
|
@ -19,3 +19,5 @@ addSbtPlugin("com.lihaoyi" % "workbench" % "0.4.0")
|
||||
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.7.1"
|
||||
|
||||
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
|
||||
|
||||
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.0.0-M11")
|
||||
|
@ -19,6 +19,7 @@ package fluence.codec.pb
|
||||
|
||||
import com.google.protobuf.ByteString
|
||||
import fluence.codec.PureCodec
|
||||
import scalapb.{GeneratedMessage, GeneratedMessageCompanion, Message}
|
||||
|
||||
import scala.language.higherKinds
|
||||
|
||||
@ -30,4 +31,19 @@ object ProtobufCodecs {
|
||||
arr ⇒ ByteString.copyFrom(arr)
|
||||
)
|
||||
|
||||
/**
|
||||
* Codec for converting byte array to protobuf class.
|
||||
*
|
||||
* @param gen Protobuf class's companion.
|
||||
* @return New codec for converting byte array to a specific protobuf class.
|
||||
*/
|
||||
def protobufDynamicCodec[A <: GeneratedMessage with Message[A]](
|
||||
gen: GeneratedMessageCompanion[A]
|
||||
): PureCodec.Func[Array[Byte], A] = PureCodec.liftFunc[Array[Byte], A](gen.parseFrom)
|
||||
|
||||
/**
|
||||
* Codec for converting protobuf class to a byte array.
|
||||
*/
|
||||
val generatedMessageCodec: PureCodec.Func[GeneratedMessage, Array[Byte]] =
|
||||
PureCodec.liftFunc[GeneratedMessage, Array[Byte]](_.toByteArray)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user