Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tellnobody1 committed Apr 25, 2022
1 parent 2386255 commit 15bdeb6
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 135 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 zero-deps
Copyright (c) 2022 zero-deps

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions bench/src/main/scala-3/data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object States {
given MessageCodec[Version] = caseCodecIdx
given MessageCodec[VectorClock] = caseCodecIdx
val codec = caseCodecIdx[Data]
val bytes: Array[Byte] = encode(data)(codec)
val bytes: Array[Byte] = encode(data)(using codec)
}
}

Expand All @@ -87,7 +87,7 @@ class Encode {

@Benchmark
def proto(state: States.MacrosState, bh: Blackhole): Unit = {
bh.consume(encode(state.data)(state.codec))
bh.consume(encode(state.data)(using state.codec))
}
}

Expand All @@ -112,6 +112,6 @@ class Decode {

@Benchmark
def proto(state: States.MacrosState, bh: Blackhole): Unit = {
bh.consume(decode(state.bytes)(state.codec))
bh.consume(decode(state.bytes)(using state.codec))
}
}
6 changes: 3 additions & 3 deletions bench/src/main/scala-3/msg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object States {
given MessageCodec[Stat] = caseCodecIdx
given MessageCodec[StatMeta] = caseCodecIdx
val codec = caseCodecIdx[Msg]
val bytes: Array[Byte] = encode(msg)(codec)
val bytes: Array[Byte] = encode(msg)(using codec)
}
}

Expand All @@ -33,7 +33,7 @@ class Encode {

@Benchmark
def proto(state: States.MacrosState, bh: Blackhole): Unit = {
bh.consume(encode(state.msg)(state.codec))
bh.consume(encode(state.msg)(using state.codec))
}
}

Expand All @@ -45,6 +45,6 @@ class Decode {

@Benchmark
def proto(state: States.MacrosState, bh: Blackhole): Unit = {
bh.consume(decode(state.bytes)(state.codec))
bh.consume(decode(state.bytes)(using state.codec))
}
}
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ val `proto-parent` = project.in(file(".")).settings(
, version := zero.git.version()
).aggregate(proto, protosyntax, protopurs, prototex, protoops, bench)

ThisBuild / scalaVersion := "3.1.1"
ThisBuild / crossScalaVersions := "3.1.1" :: "2.13.8" :: "2.12.15" :: Nil
ThisBuild / scalaVersion := "3.1.3-RC2"
ThisBuild / crossScalaVersions := "3.1.3-RC2" :: "2.13.8" :: "2.12.15" :: Nil

lazy val proto = project.in(file("proto")).settings(
name := "proto",
version := zero.git.version(),
libraryDependencies += "com.google.protobuf" % "protobuf-java" % "3.19.3",
libraryDependencies += "com.google.protobuf" % "protobuf-java" % "3.20.1",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % Test
).dependsOn(protoops)

Expand Down Expand Up @@ -82,7 +82,7 @@ ThisBuild / scalacOptions ++= {
"-source", "future-migration", "-deprecation"
, "release", "11"
, "-Yexplicit-nulls"
, "-Xcheck-macros"
// , "-Xcheck-macros"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.2
sbt.version=1.7.0-M2
10 changes: 5 additions & 5 deletions proto/src/main/scala-3/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package proto
import java.io.{OutputStream, InputStream}
import com.google.protobuf.{CodedOutputStream, CodedInputStream}

def encode[A](a: A)(using c: MessageCodec[A]): Array[Byte] =
def encode[A](a: A)(implicit c: MessageCodec[A]): Array[Byte] =
val p = c.prepare(a)
val bytes = new Array[Byte](p.size)
val os = CodedOutputStream.newInstance(bytes).nn
p.write(os)
bytes

def encodeS[A](a: A, s: OutputStream)(using c: MessageCodec[A]): OutputStream =
def encodeS[A](a: A, s: OutputStream)(implicit c: MessageCodec[A]): OutputStream =
val p = c.prepare(a)
val os = CodedOutputStream.newInstance(s).nn
p.write(os)
s

def decode[A](xs: Array[Byte])(using c: MessageCodec[A]): A =
def decode[A](xs: Array[Byte])(implicit c: MessageCodec[A]): A =
c.read(CodedInputStream.newInstance(xs).nn)

def decode[A](xs: Array[Byte], offset: Int)(using c: MessageCodec[A]): A =
def decode[A](xs: Array[Byte], offset: Int)(implicit c: MessageCodec[A]): A =
c.read(CodedInputStream.newInstance(xs, offset, xs.length-offset).nn)

def decodeS[A](s: InputStream)(using c: MessageCodec[A]): A =
def decodeS[A](s: InputStream)(implicit c: MessageCodec[A]): A =
c.read(CodedInputStream.newInstance(s).nn)
Loading

0 comments on commit 15bdeb6

Please sign in to comment.