Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ addSbtPlugin("com.lihaoyi" % "workbench" % "0.4.0")

libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.7.1"

addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
16 changes: 16 additions & 0 deletions protobuf/src/main/scala/fluence/codec/pb/ProtobufCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}