mirror of
https://github.com/fluencelabs/codec
synced 2025-04-24 14:22:14 +00:00
commit
70dae6edca
@ -29,18 +29,36 @@ object BitsCodecs {
|
||||
implicit val byteArrayToVector: PureCodec[Array[Byte], ByteVector] =
|
||||
liftB(ByteVector.apply, _.toArray)
|
||||
|
||||
// Notice the use of default Base64 alphabet
|
||||
implicit val base64ToVector: PureCodec[String, ByteVector] =
|
||||
base64AlphabetToVector(Bases.Alphabets.Base64)
|
||||
object Base64 {
|
||||
// Notice the use of default Base64 alphabet
|
||||
implicit val base64ToVector: PureCodec[String, ByteVector] =
|
||||
alphabetToVector(Bases.Alphabets.Base64)
|
||||
|
||||
def base64AlphabetToVector(alphabet: Bases.Base64Alphabet): PureCodec[String, ByteVector] =
|
||||
liftEitherB(
|
||||
str ⇒
|
||||
ByteVector
|
||||
.fromBase64Descriptive(str, alphabet)
|
||||
.left
|
||||
.map(CodecError(_)),
|
||||
vec ⇒ Right(vec.toBase64(alphabet))
|
||||
)
|
||||
def alphabetToVector(alphabet: Bases.Base64Alphabet): PureCodec[String, ByteVector] =
|
||||
liftEitherB(
|
||||
str ⇒
|
||||
ByteVector
|
||||
.fromBase64Descriptive(str, alphabet)
|
||||
.left
|
||||
.map(CodecError(_)),
|
||||
vec ⇒ Right(vec.toBase64(alphabet))
|
||||
)
|
||||
}
|
||||
|
||||
object Base58 {
|
||||
// Notice the use of default Base64 alphabet
|
||||
implicit val base58ToVector: PureCodec[String, ByteVector] =
|
||||
alphabetToVector(Bases.Alphabets.Base58)
|
||||
|
||||
def alphabetToVector(alphabet: Bases.Alphabet): PureCodec[String, ByteVector] =
|
||||
liftEitherB(
|
||||
str ⇒
|
||||
ByteVector
|
||||
.fromBase58Descriptive(str, alphabet)
|
||||
.left
|
||||
.map(CodecError(_)),
|
||||
vec ⇒ Right(vec.toBase58(alphabet))
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import cats.syntax.compose._
|
||||
import org.scalatest.prop.Checkers
|
||||
import org.scalatest.{Matchers, WordSpec}
|
||||
import scodec.bits.ByteVector
|
||||
import BitsCodecs.Base64._
|
||||
import BitsCodecs._
|
||||
import fluence.codec.PureCodec
|
||||
|
||||
@ -32,7 +33,7 @@ class BitsCodecsSpec extends WordSpec with Matchers with Checkers {
|
||||
val arrCodec = implicitly[PureCodec[Array[Byte], ByteVector]]
|
||||
val b64Codec = implicitly[PureCodec[ByteVector, String]]
|
||||
|
||||
check { (bytes: List[Byte]) ⇒
|
||||
check { bytes: List[Byte] ⇒
|
||||
(arrCodec andThen arrCodec.swap).direct.apply[Id](bytes.toArray).value.map(_.toList).contains(bytes) &&
|
||||
(arrCodec andThen b64Codec andThen b64Codec.swap andThen arrCodec.swap).direct
|
||||
.apply[Id](bytes.toArray)
|
||||
|
@ -14,7 +14,8 @@ val scalaV = scalaVersion := "2.12.8"
|
||||
|
||||
val commons = Seq(
|
||||
scalaV,
|
||||
version := "0.0.4",
|
||||
//crossScalaVersions := Seq(scalaVersion.value, "2.13.0-RC1"),
|
||||
version := "0.0.5",
|
||||
fork in Test := true,
|
||||
parallelExecution in Test := false,
|
||||
organization := "one.fluence",
|
||||
@ -30,10 +31,10 @@ val commons = Seq(
|
||||
|
||||
commons
|
||||
|
||||
val kindProjector = addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.9")
|
||||
val kindProjector = addCompilerPlugin("org.typelevel" % "kind-projector" % "0.10.0" cross CrossVersion.binary)
|
||||
|
||||
val Cats1V = "1.5.0"
|
||||
val ScodecBitsV = "1.1.9"
|
||||
val Cats1V = "1.6.0"
|
||||
val ScodecBitsV = "1.1.10"
|
||||
val CirceV = "0.11.1"
|
||||
val ShapelessV = "2.3.+"
|
||||
|
||||
|
@ -24,6 +24,7 @@ import cats.laws.discipline.{MonadErrorTests, SemigroupalTests}
|
||||
import cats.tests.CatsSuite
|
||||
import fluence.codec
|
||||
import org.scalacheck.Arbitrary
|
||||
import org.scalacheck.Arbitrary._
|
||||
import org.scalacheck.ScalacheckShapeless._
|
||||
|
||||
class PureCodecPointLawsSpec extends CatsSuite {
|
||||
|
@ -1,16 +1,16 @@
|
||||
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")
|
||||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0")
|
||||
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.15")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.20")
|
||||
|
||||
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0")
|
||||
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
|
||||
|
||||
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.19")
|
||||
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.20")
|
||||
|
||||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.26")
|
||||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.27")
|
||||
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.6.0")
|
||||
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")
|
||||
|
||||
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.13.1")
|
||||
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.14.0")
|
||||
|
||||
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user