Skip to content

Commit

Permalink
Try with scalapb.proto.
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamet committed Dec 1, 2015
1 parent df8d2e9 commit 772e470
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
"com.trueaccord.lenses" %%% "lenses" % "0.4.4",
"com.trueaccord.scalapb" %%% "scalapb-runtime" % "0.5.15",
"com.trueaccord.scalapb" %%% "scalapb-runtime" % "0.5.16",
"com.trueaccord.scalapb" %%% "scalapb-runtime" % "0.5.16" % PB.protobufConfig,
"com.lihaoyi" %%% "utest" % "0.3.1" % "test"
)

Expand Down
4 changes: 4 additions & 0 deletions src/main/protobuf/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto2";

package com.trueaccord;

import "scalapb/scalapb.proto";

message MyTest {
optional string str1 = 1;
optional int32 my_int = 2;
Expand All @@ -11,5 +13,7 @@ message MyTest {
}

optional Nested nested = 3;

optional string object_id = 4 [(scalapb.field).type = "com.trueaccord.ObjectId"];
}

9 changes: 9 additions & 0 deletions src/main/scala/com/trueaccord/ObjectId.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.trueaccord

case class ObjectId(id: String) extends AnyVal

object ObjectId {
implicit val typeMapper =
com.trueaccord.scalapb.TypeMapper(ObjectId.apply)(_.id)
}

7 changes: 5 additions & 2 deletions src/test/scala/com/trueaccord/JsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ object JsTest extends TestSuite {
val t = MyTest().update(
_.str1 := "foobarbaz",
_.myInt := 15,
_.nested.inside := 17
_.nested.inside := 17,
_.objectId := ObjectId("my_id")
)

'updateWorks {
assert(t ==
MyTest(str1 = Some("foobarbaz"), myInt = Some(15),
nested = Some(MyTest.Nested(inside = Some(17)))))
nested = Some(MyTest.Nested(inside = Some(17))),
objectId = Some(ObjectId("my_id"))
))
}

'parseFromIsInverseOfByteArray {
Expand Down

0 comments on commit 772e470

Please sign in to comment.