A caster takes the untyped value returned by the PB reflection APIs and provides a typesafe value.
A caster takes the untyped value returned by the PB reflection APIs and provides a typesafe value. It is also responsible for determining whether a path adhere's to the desired stated type in the ProtoAccessor factory methods.
type of GeneratedMessage
from which data should be extracted.
type of data to be extracted from A
.
A representation of an accessor function whose domain is something extending Protocol Buffers'
GenerateMessage
.
A representation of an accessor function whose domain is something extending Protocol Buffers'
GenerateMessage
.
A trait that extends function to remove contravariance on A
and covariance on B
.
This eases implicit search and therefore conversion from string-based paths.
Note: only ProtoAccessor.ProtoAccessorImpl
implements this trait.
type of GeneratedMessage
from which data should be extracted.
type of data to be extracted from A
.
Contains either
and option
factory methods to produce ProtoAccessor from string-based
paths.
Contains either
and option
factory methods to produce ProtoAccessor from string-based
paths. Note that conversions can be called explicitly or can be used implicitly. In the
following examples, Score
's definition can be found at
aloha-proto/Scores.proto.
import com.eharmony.aloha.score.Scores.Score // Explicit val a1: Either[String, ProtoAccessor[Score, Option[Long]]] = ProtoAccessor.either[Score, Option[Long]]("error.model.id") // a2: Either[String, ProtoAccessor[Score, Option[Long]]] val a2 = ProtoAccessor.either[Score, Option[Long]]("error.model.id") // Implicit val a3: Either[String, ProtoAccessor[Score, Option[String]]] = "error.model.name" // Implicit, many at a time ... val as: Seq[Either[String, ProtoAccessor[Score, Option[Long]]]] = Seq("error.model.id", "error.model.id")
If error information isn't important, use the Option-based API:
import com.eharmony.aloha.score.Scores.Score // Explicit val a1: Option[ProtoAccessor[Score, Option[Long]]] = ProtoAccessor.option[Score, Option[Long]]("error.model.id") // Implicit val a3: Option[ProtoAccessor[Score, Option[String]]] = "error.model.name"
An attempt is made to fully respect types so the following won't work because
"error.model.id" is represented by a Long
in the protobuf definition:
// Returns error message on the Left. import com.eharmony.aloha.score.Scores.Score val a1: Either[String, ProtoAccessor[Score, Option[Int]]] = "error.model.id"
Additionally, Option and non-Option based accessors are respected. If a non-required
path
element is found in the path, and the accessor doesn't return an Option, an error will be
returned:
// Returns error message on the Left because "error" is optional in the PB definition. import com.eharmony.aloha.score.Scores.Score val a1: Either[String, ProtoAccessor[Score, Long]] = "error.model.id"
This package provides definitions necessary create accessor functions that can extract data from Protocol Buffer instances using PB's reflection APIs.