Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ Global / onChangedBuildSource := ReloadOnSourceChanges
inThisBuild(
Seq(
version := "0.1",
scalaVersion := "2.13.5",
scalacOptions ++= "-Ymacro-annotations" :: "-language:experimental.macros" :: Nil
scalaVersion := "2.13.6",
scalacOptions ++= Seq(
"-Ymacro-annotations",
"-language:experimental.macros",
//"-Xlog-implicits",
"-Ymacro-debug-lite",
// for nicer error messages
//"-Vimplicits",
"-Vtype-diffs"
)
)
)

Expand All @@ -16,12 +24,19 @@ lazy val `scala-macros` = (project in file("scala-macros"))
.settings(
libraryDependencies ++= Seq(
scalaReflect % scalaVersion.value,
scalaPbRuntime
scalaPbRuntime,
beamSdksJavaCore,
beamRunnersDirectJava
)
)

lazy val `scala-macros-usage` = (project in file("scala-macros-usage"))
.dependsOn(`scala-macros`)
.settings(
libraryDependencies ++= scalaPbRuntime :: Nil
libraryDependencies ++= Seq(
scalaPbRuntime,
beamSdksJavaCore,
beamRunnersDirectJava,
scalaTest
)
)
6 changes: 6 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ import sbt._
object Dependencies {
val scalaReflect = "org.scala-lang" % "scala-reflect"
val scalaPbRuntime = "com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion

val beamVersion = "2.28.0"
val beamSdksJavaCore = "org.apache.beam" % "beam-sdks-java-core" % beamVersion
val beamRunnersDirectJava = "org.apache.beam" % "beam-runners-direct-java" % beamVersion % Runtime

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7" % Test
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.github.fpopic.scalamacros.beam

import org.apache.beam.sdk.coders.Coder
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import java.io.{ByteArrayInputStream, ByteArrayOutputStream}

case class Pojo(s: String, i: Int, l: List[Int], s2: String)
case class ContainsNested(i: Int, pojo: Pojo)

class DefMacroCoderSpec extends AnyFlatSpec with Matchers {

behavior of "DefMacroCoder"

it should "generate a coder and serialize/deserialize properly the value." in {
import DefMacroCoder.{intCoder, stringCoder, listCoder}
val coder: Coder[Pojo] = DefMacroCoder.productCoder[Pojo]

val pojo = Pojo(s = "4", i = 1, l = List(2, 3), s2 = "5")

val encoded: Array[Byte] = {
val os = new ByteArrayOutputStream()
coder.encode(pojo, os)
os.toByteArray
}
val decoded: Pojo = coder.decode(new ByteArrayInputStream(encoded))

pojo shouldBe decoded
}

it should "generate a coder for nested case class and serialize/deserialize properly the value." in {
import DefMacroCoder.{intCoder, stringCoder, listCoder}
implicit val pojoCoder: Coder[Pojo] = DefMacroCoder.productCoder[Pojo]
val coder: Coder[ContainsNested] = DefMacroCoder.productCoder[ContainsNested]

val pojo = ContainsNested(i = 7, pojo = Pojo(s = "4", i = 1, l = List(2, 3), s2 = "5"))

val encoded: Array[Byte] = {
val os = new ByteArrayOutputStream()
coder.encode(pojo, os)
os.toByteArray
}
val decoded: ContainsNested = coder.decode(new ByteArrayInputStream(encoded))

pojo shouldBe decoded
}

}

This file was deleted.

This file was deleted.

Loading