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)
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)
Semi-regularly note that the website and docs are out of date and I'd love some help with them :)
I'm hoping to revamp the site when Scala 3's built in site & doc generator is ready and well integrated with SBT
I'm running into an
Insufficient number of elements
error from alistOfN
decoder when using a StreamDecoder on a file. However, if I bump up thechunkSize
passed tofs2.io.file.readAll
enough (~8MB), then the error seems to go away. Is this behavior expected?
hello, I'm curious if this was patched, I'm running into the same thing. currently using 1.11.7 for scodec-core and 2.0.1 for scodec-stream
Unit
? I have a problem, where an HList
is expected, but I have only a single codec. So I could write myCodec :: Codec.zero
. Or how would I go about lifting a Codec
into an HList
? Because I also cannot do myCodec :: HListCodec.hnilCodec
, since hnilCodec
is inaccessible.
What is the the idiomatic way of building a custom Codec? For example: I want to have a Codec[Info]
that consumes 13 bytes and turns it into an Info
class.
Currently I'm mapping over the tuples, which has can be difficult with a bigger number of byte-structures (but that might be something that is unavoidable, but then I am also getting a GenCodec
back which I'm not sure about.
val ChainInfoCodec: GenCodec[(((Boolean, Int), Int), Int), Info] = (bool(8) ~ int32 ~ int32 ~ int32).map {
case (((enabled, min), center), max) =>
Info(enabled, min, center, max)
}
The API does offer narrow
, and widen
. narrow
does give me a proper Codec
back. So at another place in my code I do,
val CountCodec: Codec[Int] =
(int32 ~ ignore(8)).narrow(a => Attempt.successful(a._1 - 1), c => (c, ()))
But then there is also xmap
and exmap
which look they could be helpful.
I'm a bit baffled by an error message I'm getting:
Type mismatch. Required: PictureHeader => Codec[L_], found: PictureHeader => Codec[Vector[Long]]
My code is as follows:
case class PictureHeader(width: Int, height: Int, offsetX: Int, offsetY: Int)
case class Picture(header : PictureHeader, columnOffsets : Vector[Long])
def headerCodec : Codec[PictureHeader] = {
("width" | uint16L) :: ("height" | uint16L) ::
("offsetX" | int16L) :: ("offsetY" | int16L)
}.as[PictureHeader]
def pictureCodec : Codec[Picture] = {
("header" | headerCodec).flatPrepend { header =>
"columnOffsets" | vectorOfN(provide(header.width), uint32L)
}
}.as[Picture]
Codec[L_]
, or even what an L_
is supposed to be.
@oschrenk Is this example code what you're looking for? https://github.com/scodec/scodec/blob/main/unitTests/src/test/scala/scodec/examples/MpegPacketExample.scala
No. I can create scodec codec. I am more looking for the part how to generate Javascript code from scodec and then on how to use it. Maybe less on the code site, but more on project setup side.
Hi everyone.
I'm using scodec to decode bits coming from a socket into messages. My read looks like this:
Stream
.repeatEval(socket.read(receiveBufferSize, readTimeoutOpt))
.unNoneTerminate >>= Stream.chunk)
.through(StreamDecoder.many(Decoder[In]).toPipeByte)
My decoder looks like this:
Attempt.fromTry(Try(VMQuery.parseFrom(bits.toByteArray.drop(4))).map(DecodeResult(_, BitVector.empty)))
I'm using protobuf, so I'm dropping the first four bytes of the message. For small messages, this works fine, but when I get a bigger message, the Attempt
in the above expression evaluates to:
Failure(While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length.)
My understanding is that the many
method will attempt to decode messages repeatedly, and if one can't be decoded, read more bits until it succeeds. The bits that represent the message it's failing on don't all come in at once, so it looks like the decoding is failing. But it's not retrying again once the bits arrive. Any suggestions?