Package

deaktator.pops

fn

Permalink

package fn

This package provides definitions necessary create accessor functions that can extract data from Protocol Buffer instances using PB's reflection APIs.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. fn
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. sealed trait Caster[A <: GeneratedMessage, B] extends Serializable

    Permalink

    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.

    A

    type of GeneratedMessage from which data should be extracted.

    B

    type of data to be extracted from A.

  2. sealed trait ProtoAccessor[A <: GeneratedMessage, B] extends (A) ⇒ B with Serializable

    Permalink

    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.

    A

    type of GeneratedMessage from which data should be extracted.

    B

    type of data to be extracted from A.

Value Members

  1. object ProtoAccessor extends Serializable

    Permalink

    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"

Inherited from AnyRef

Inherited from Any

Ungrouped