Skip to content

Commit

Permalink
Update to latest zio-prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Apr 4, 2021
1 parent b48db93 commit 1fbe821
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 57 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ lazy val commonSettings = Seq(
username,
password)).toSeq,

resolvers +=
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
)

lazy val root = Project("desert", file("."))
Expand All @@ -71,7 +73,7 @@ lazy val core = CrossProject("desert-core", file("desert-core"))(JVMPlatform, JS
description := "A Scala binary serialization library",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"dev.zio" %% "zio-prelude" % "1.0.0-RC3",
"dev.zio" %% "zio-prelude" % "1.0.0-RC3+18-1b303eec-SNAPSHOT",
"com.chuusai" %% "shapeless" % "2.3.3",
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait BinarySerializer[T] { self =>
object BinarySerializer {
final case class SerializationEnv(output: BinaryOutput, typeRegistry: TypeRegistry)

type Ser[T] = ZPure[SerializerState, SerializerState, SerializationEnv, DesertFailure, T]
type Ser[T] = ZPure[Nothing, SerializerState, SerializerState, SerializationEnv, DesertFailure, T]

object Ser {
final def fromEither[T](value: Either[DesertFailure, T]): Ser[T] =
Expand All @@ -39,7 +39,7 @@ trait BinaryDeserializer[T] { self =>
object BinaryDeserializer {
final case class DeserializationEnv(input: BinaryInput, typeRegistry: TypeRegistry)

type Deser[T] = ZPure[SerializerState, SerializerState, DeserializationEnv, DesertFailure, T]
type Deser[T] = ZPure[Nothing, SerializerState, SerializerState, DeserializationEnv, DesertFailure, T]

object Deser {
final def fromEither[T](value: Either[DesertFailure, T]): Deser[T] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,10 @@ class GenericBinaryCodec(evolutionSteps: Vector[Evolution]) extends GenericDeriv
finalState <- Ser.fromEither(
serializer.value.serialize(taggedTransients.tag(genericValue))
.provide(chunkedOutput)
.runEither(initialState))
.map(_._1) // state
.getState
.map(_._1)
.either
.runResult(initialState))
_ <- chunkedOutput.writeEvolutionHeader(finalState.fieldIndices)
_ <- chunkedOutput.writeOrderedChunks()
_ <- setSerializerState(finalState.serializerState)
Expand All @@ -634,7 +636,9 @@ class GenericBinaryCodec(evolutionSteps: Vector[Evolution]) extends GenericDeriv
transientFields)
result <- Deser.fromEither(deserializer.value.deserialize()
.provide(chunkedInput)
.runEither(initialState))
.getState
.either
.runResult(initialState))
(finalState, hlist) = result
_ <- setDeserializerState(finalState.serializerState)
} yield gen.from(taggedTransients.untag(hlist))
Expand Down Expand Up @@ -843,7 +847,7 @@ object GenericBinaryCodec {
transientFields: Map[Symbol, Any]
)

type ChunkedSer[T] = ZPure[ChunkedSerState, ChunkedSerState, ChunkedOutput, DesertFailure, T]
type ChunkedSer[T] = ZPure[Nothing, ChunkedSerState, ChunkedSerState, ChunkedOutput, DesertFailure, T]

object ChunkedSerOps {
final def getChunkedOutput: ChunkedSer[ChunkedOutput] = ZPure.environment
Expand All @@ -860,7 +864,9 @@ object GenericBinaryCodec {
chunkedState <- getChunkedState
runResult <- fromEither(value
.provide(SerializationEnv(output, chunkedState.typeRegistry))
.runEither(chunkedState.serializerState))
.getState
.either
.runResult(chunkedState.serializerState))
(resultState, result) = runResult
_ <- setChunkedState(chunkedState.copy(serializerState = resultState))
} yield result
Expand Down Expand Up @@ -905,7 +911,7 @@ object GenericBinaryCodec {
def inputFor(version: Byte): Either[DesertFailure, BinaryInput]
}

type ChunkedDeser[T] = ZPure[ChunkedSerState, ChunkedSerState, ChunkedInput, DesertFailure, T]
type ChunkedDeser[T] = ZPure[Nothing, ChunkedSerState, ChunkedSerState, ChunkedInput, DesertFailure, T]

object ChunkedDeserOps {
final def getChunkedInput: ChunkedDeser[ChunkedInput] = ZPure.environment
Expand All @@ -921,7 +927,9 @@ object GenericBinaryCodec {
chunkedState <- getChunkedState
runResult <- fromEither(value
.provide(DeserializationEnv(input, chunkedState.typeRegistry))
.runEither(chunkedState.serializerState))
.getState
.either
.runResult(chunkedState.serializerState))
(resultState, result) = runResult
_ <- setChunkedState(chunkedState.copy(serializerState = resultState))
} yield result
Expand Down
Loading

0 comments on commit 1fbe821

Please sign in to comment.