mpilquist on v1.11.0
mpilquist on 1.11.x
Setting version to 1.11.0 Updated version to 1.11.1-SNAPS… (compare)
mpilquist on 1.11.x
Scala 2.13.0-M4 Merge branch 'series/1.10.x' in… Upgraded to latest scala-collec… and 2 more (compare)
mpilquist on 1.11.x
Created 1.11 branch (compare)
mpilquist on xuwei-k
Upgraded to 2.13.0-M5 (compare)
mpilquist on xuwei-k
Scala 2.13.0-M4 Merge branch 'series/1.10.x' in… Upgraded to latest scala-collec… (compare)
mpilquist on 1.10.x
Update sbt-scalajs, scalajs-com… Merge pull request #129 from sc… (compare)
mpilquist on 1.10.x
Pad-left on pbcd codec. Fixes #… Using padLeft in pbcd instead o… Merge pull request #133 from lJ… (compare)
mappedEnum(uint8, Color.Red -> 10, Color.Green -> 20, Color.Blue -> 30)
given Codec[Arrows] = mappedEnum(
uint4,
Arrows.Up -> 0,
Arrows.UpRight -> 1,
Arrows.Right -> 2,
Arrows.DownRight -> 3,
Arrows.Down -> 4,
Arrows.DownLeft -> 5,
Arrows.Left -> 6,
Arrows.UpLeft -> 7,
Arrows.Neither -> 8
)
even better than relying on definition order :D
StreamEncoder
companion object - e.g., StreamEncoder.many(myCodec).toPipe[IO]
Hi! I’m trying to write a codec for macaroons:
macaroon: VERSION opt_location IDENTIFIER EOS caveats EOS SIGNATURE
caveats: caveat caveats
|
caveat: opt_location IDENTIFIER opt_vid EOS
I’ve got:
private val caveat: Codec[Caveat] =
"caveat" | (optionalLocation :: identifier :: optionalVerificationKeyId <~ endOfSection)
.as[Caveat]
private val caveats: Codec[Vector[Caveat]] =
"caveats" | vector(caveat)
val macaroonV2: Codec[Macaroon] =
(version ~> optionalLocation :: identifier :: endOfSection ~> caveats :: endOfSection ~> authenticationTag)
.as[Macaroon]
but when trying to decode, the vector
codec fails upon endOfSection
right before the authenticationTag
. How do I find/create a variant of vector
that just returns the result so far and remaining bits as soon as its codec.decode
fails?
def seeWhatHappensVector[A](codec: Codec[A]): Codec[Vector[A]] =
Codec[Vector[A]](
Encoder.encodeSeq(codec.asEncoder)(_),
(bits: BitVector) => {
@tailrec def helper(rest: BitVector,
acc: Vector[A]): Attempt[DecodeResult[Vector[A]]] =
codec.decode(rest) match {
case Successful(DecodeResult(v, rem)) => helper(rem, v +: acc)
case Failure(_) => successful(DecodeResult(acc, rest))
}
helper(bits, Vector.empty)
}
)
listOfN
will work because I don't know how many frames there are ahead of time.
def fromHeader(header: TagFrameHeader): Codec[TagFrameContent] =
fixedSizeBytes(header.size.size, utf8)
.xmap(TagFrameContent.apply, (x: TagFrameContent) => x.content)
TagFrameHeader.codec.flatZip(TagFrameContent.fromHeader)