Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
urmaul committed Oct 18, 2024
1 parent 873edae commit bec3f77
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,8 @@ import scala.util.Success
class ProtocolBuffersRoundTripTest extends UnitTest with ScalaCheckPropertyChecks {
import ProtocolBuffersRoundTripTest._

// TODO: remove?
implicit val colorReader: Reader[food.Meal.Color, Color] = ProtocolBuffers.reader[food.Meal.Color, Color]

implicit val reader: Reader[food.Meal, Meal] = ProtocolBuffers.reader[food.Meal, Meal]
// implicit val writer: Writer[Meal, food.Meal] = ProtocolBuffers.writer[Meal, food.Meal]
val writerFB: Writer[FruitBasket, food.Meal.FruitBasket] = ProtocolBuffers.writer[FruitBasket, food.Meal.FruitBasket]
// val writerLFB: Writer[FruitBasket, food.Meal.Lunch.FruitBasket] = ProtocolBuffers.writer[FruitBasket, food.Meal.Lunch.FruitBasket]
val writerLFB: Writer[FruitBasket, food.Meal.Lunch.FruitBasket] = new Writer[FruitBasket, food.Meal.Lunch.FruitBasket] {
override def write(model: FruitBasket): food.Meal.Lunch.FruitBasket = food.Meal.Lunch.FruitBasket(value = writerFB.write(model))
}
val writerLB: Writer[LunchBox, food.Meal.LunchBox] = ProtocolBuffers.writer[LunchBox, food.Meal.LunchBox]
// val writerLLB: Writer[LunchBox, food.Meal.Lunch.LunchBox] = ProtocolBuffers.writer[LunchBox, food.Meal.Lunch.LunchBox]
val writerLLB: Writer[LunchBox, food.Meal.Lunch.LunchBox] = new Writer[LunchBox, food.Meal.Lunch.LunchBox] {
override def write(model: LunchBox): food.Meal.Lunch.LunchBox = food.Meal.Lunch.LunchBox(value = writerLB.write(model))
}
val writerL: Writer[Lunch, food.Meal.Lunch] = ProtocolBuffers.writer[Lunch, food.Meal.Lunch]
implicit val writer: Writer[Meal, food.Meal] = new Writer[Meal, food.Meal] {
override def write(model: Meal): food.Meal = food.Meal(
lunch = writerL.write(model.lunch)
)
}
// implicit val writer: Writer[Meal, food.Meal] = ProtocolBuffers.writer[Meal, food.Meal]
implicit val writer: Writer[Meal, food.Meal] = ProtocolBuffers.writer[Meal, food.Meal]

val version = 1
val modelReader = VersionedModelReader[Int, Meal](version -> food.Meal)
Expand Down Expand Up @@ -67,25 +47,6 @@ class ProtocolBuffersRoundTripTest extends UnitTest with ScalaCheckPropertyCheck
reader.read(writer.write(meal)) shouldBe PbSuccess(meal)
}
}
"do that thing" in {
val meal = Meal(
FruitBasket(
List(
Fruit("z", Color.Red),
Fruit("cqxnceqq", Color.pink),
Fruit("hXRwEsHU", Color.Red),
Fruit("ysBUXsSQDr", Color.Yellow),
Fruit("hMldwXGXA", Color.pink),
Fruit("oyg", Color.Yellow),
Fruit("dGQ", Color.Yellow),
Fruit("vpy", Color.Blue)
)
)
)
val proto = writer.write(meal)
println(s"proto ${proto}")
reader.read(proto) shouldBe PbSuccess(meal)
}

"create model writer and reader that round trip successfully via JSON" in {
forAll(mealGen) { meal =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.google.protobuf.Descriptors
import com.google.protobuf.timestamp.Timestamp
import scalapb.descriptors.EnumDescriptor
import scalapb.{GeneratedEnum, GeneratedEnumCompanion, UnrecognizedEnum}
//import io.moia.protos.teleproto.BaseTransformers._ // TODO: remove

sealed abstract class ProtobufEnum(val value: Int) extends GeneratedEnum {
type EnumType = ProtobufEnum
Expand Down Expand Up @@ -93,11 +92,6 @@ object Protobuf {

implicit val subReader: Reader[SubProtobuf, SubModel] = ProtocolBuffers.reader[SubProtobuf, SubModel]

// TODO: remove?
implicit val enumReader: Reader[ProtobufEnum, ModelEnum] = ProtocolBuffers.reader[ProtobufEnum, ModelEnum]
// implicit val enumWriter: Writer[ModelEnum, ProtobufEnum] = ProtocolBuffers.writer[ModelEnum, ProtobufEnum]
// val enumWriter: Writer[ModelEnum, ProtobufEnum] = ProtocolBuffers.writer[ModelEnum, ProtobufEnum]

val reader: Reader[Protobuf, Model] = ProtocolBuffers.reader[Protobuf, Model]

@backward("2e0e9b")
Expand Down

0 comments on commit bec3f77

Please sign in to comment.