This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/zio/zio/issues/6278 | |
import zio.{Cause, FiberId, FiberRef, LogLevel, LogSpan, RuntimeConfigAspect, ZIO, ZIOAppDefault, ZLogger, ZTraceElement} | |
object Example extends ZIOAppDefault { | |
val specialLogger: ZLogger[Cause[Any], Unit] = | |
( | |
trace: ZTraceElement, | |
fiberId: FiberId, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class A(code:Int) | |
import akka.http.scaladsl.marshalling.PredefinedToEntityMarshallers._ | |
import akka.http.scaladsl.unmarshalling.PredefinedFromEntityUnmarshallers._ | |
implicit val aResponseUnmarshaller = stringUnmarshaller.map {s:String => A(s.toInt) } | |
implicit val aResponseMarshaller = StringMarshaller.compose{p:A => p.code.toString} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def configure[T <: Config](implicit tag: ClassTag[T], convert:FromRequestUnmarshaller[T]) = path("app" / "configure" / tag.runtimeClass.getSimpleName) { | |
post { | |
entity(as[T]) { c => | |
actorRef ! c | |
complete(StatusCodes.OK) | |
} | |
} | |
} | |
trait Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def command(marker:Command) = path("app" / "command" / marker.toString) { | |
post { | |
entity(as[String]) { _ => | |
actorRef ! marker | |
complete(StatusCodes.OK) | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bracketed[T](start:BitVector, end:BitVector, extract: Codec[T]): Codec[T] = filtered(extract, new Codec[BitVector] { | |
override def sizeBound: SizeBound = SizeBound.unknown | |
override def encode(bits: BitVector): Attempt[BitVector] = Attempt.successful(start ++ bits ++ end) | |
override def decode(bits: BitVector): Attempt[DecodeResult[BitVector]] = { | |
bits.bytes.indexOfSlice(start.bytes) match { | |
case -1 => Attempt.failure(Err("Does not contain start.")) | |
case si => bits.bytes.indexOfSlice(end.bytes) match { | |
case -1 => Attempt.failure(Err("Does not contain end.")) | |
case ei => Attempt.successful(DecodeResult(bits.slice((si + start.size) * 8L, ei * 8L), bits.drop((ei + end.size) * 8L))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scodec.Decoder | |
import scodec.bits.BitVector | |
import scodec.Err | |
import scodec.Attempt | |
import scodec.DecodeResult | |
class FixedSizeDecoder[A](sizeBytes: Long, decoder: Decoder[A]) extends Decoder[A] { | |
val size = sizeBytes * 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scodec.Codec | |
import akka.util.ByteString | |
object ByteStringCodec extends Codec[ByteString] { | |
import scodec.{ Attempt, DecodeResult } | |
import scodec.SizeBound | |
import scodec.bits.BitVector | |
def sizeBound = new SizeBound(0, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scodec.Codec | |
import scodec.bits.ByteVector | |
object ByteVectorCodec extends Codec[ByteVector] { | |
import scodec.{ Attempt, DecodeResult } | |
import scodec.SizeBound | |
import scodec.bits.BitVector | |
def sizeBound = new SizeBound(0, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object XorChecksumCodec { | |
def xorByte(bits: BitVector): BitVector = BitVector(bits.bytes.foldLeft[Byte](0)((a, b) => (a ^ b).asInstanceOf[Byte])) | |
def apply[T](target: Codec[T]) = checksummed(target, xorByte, trailer(target), true) | |
def trailer[T](target: Codec[T]): Codec[(BitVector, BitVector)] = new Codec[(BitVector, BitVector)] { | |
def sizeBound = target.sizeBound + new SizeBound(0, Some(8L)) | |
def encode(value: (BitVector, BitVector)): Attempt[BitVector] = Attempt.successful(value._1 ++ value._2) | |
def decode(bits: BitVector): Attempt[DecodeResult[(BitVector, BitVector)]] = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val contents: Codec[Data] = discriminated[Data].by(ignore(0)) | |
.typecase((), empty) | |
.typecase((), XXX) | |
.typecase((), YYY) | |
) |
NewerOlder