All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ing.baker.runtime.serialization.protomappings.IngredientDescriptorMapping.scala Maven / Gradle / Ivy

There is a newer version: 4.1.0-RC3
Show newest version
package com.ing.baker.runtime.serialization.protomappings

import com.ing.baker.il
import com.ing.baker.runtime.serialization.ProtoMap.{ctxFromProto, ctxToProto, versioned}
import com.ing.baker.runtime.akka.actor.protobuf
import com.ing.baker.runtime.serialization.ProtoMap

import scala.util.Try

class IngredientDescriptorMapping extends ProtoMap[il.IngredientDescriptor, protobuf.IngredientDescriptor] {

  val companion = protobuf.IngredientDescriptor

  def toProto(event: il.IngredientDescriptor): protobuf.IngredientDescriptor = {
    val `type` = ctxToProto(event.`type`)
    protobuf.IngredientDescriptor(Some(event.name), Some(`type`))
  }

  def fromProto(message: protobuf.IngredientDescriptor): Try[il.IngredientDescriptor] =
    for {
      name <- versioned(message.name, "name")
      ingredientTypeProto <- versioned(message.`type`, "type")
      ingredientType <- ctxFromProto(ingredientTypeProto)
    } yield il.IngredientDescriptor(name, ingredientType)

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy