Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 26 2019 21:07
    scala-steward synchronize #139
  • Jan 26 2019 14:33

    mpilquist on v1.11.0

    (compare)

  • Jan 26 2019 14:32

    mpilquist on 1.11.x

    Setting version to 1.11.0 Updated version to 1.11.1-SNAPS… (compare)

  • Jan 25 2019 10:28
    billpcs starred scodec/scodec
  • Jan 22 2019 22:01
    benhanna starred scodec/scodec
  • Jan 21 2019 20:36
    scala-steward opened #139
  • Jan 21 2019 14:51
    mpilquist closed #130
  • Jan 21 2019 14:48
    mpilquist closed #119
  • Jan 21 2019 14:48
    mpilquist commented #119
  • Jan 21 2019 14:48

    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)

  • Jan 21 2019 14:48
    mpilquist closed #138
  • Jan 21 2019 14:40
    mpilquist opened #138
  • Jan 21 2019 14:37

    mpilquist on 1.11.x

    Created 1.11 branch (compare)

  • Jan 21 2019 14:31

    mpilquist on xuwei-k

    Upgraded to 2.13.0-M5 (compare)

  • Jan 21 2019 14:19

    mpilquist on xuwei-k

    Scala 2.13.0-M4 Merge branch 'series/1.10.x' in… Upgraded to latest scala-collec… (compare)

  • Jan 21 2019 14:03

    mpilquist on 1.10.x

    Update sbt-scalajs, scalajs-com… Merge pull request #129 from sc… (compare)

  • Jan 21 2019 14:03
    mpilquist closed #129
  • Jan 21 2019 14:03
    mpilquist closed #126
  • Jan 21 2019 14:03

    mpilquist on 1.10.x

    Pad-left on pbcd codec. Fixes #… Using padLeft in pbcd instead o… Merge pull request #133 from lJ… (compare)

  • Jan 21 2019 14:03
    mpilquist closed #133
Michael Pilquist
@mpilquist
Okay 1.11.6 just released on Sonatype
Carlos Quiroz
@cquiroz
Thanks Michael
Kaspar Minosiants
@minosiants

Hello all,
I'm trying to create protocol for smtp client/server using scodec . In response from the server I've got multy line ascii text. Lines are separeted by \r\n chars. I want to split lines into the list of lines.
Here is the simplified version of the code.

class ProtocolSpec extends Specification {
  "Protocol" should {
    "decode response" in {

      val CRLF = ascii.encode("\r\n").getOrElse(BitVector.empty)
      val codec: Codec[List[String]] = listDelimited(CRLF, ascii)

      val is =  getClass().getResourceAsStream("/output.txt")
      val output = Source.fromInputStream(is).mkString
      val expected = output.split("\r\n").toList

      val vec = ascii.encode(output).getOrElse(BitVector.empty)

      codec.decode(vec).map(_.value) match {
        case Attempt.Successful(result) =>
          result mustEqual expected
        case Attempt.Failure(cause) =>
          true mustEqual false

      }
    }
  }
}

output file contains dump from the server response

250-mail.example.com
250-PIPELINING
250-SIZE 52428800
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250 8BITMIME

decoded result is

List(250-mail.example.com, 250-PIPELINING, 250-SIZE 52428800
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES, 250 8BITMIME)

Not all lines are splited. In binary editor every line ends with 0D0A.

I'm really confused. Could you advise ?

Martijn Hoekstra
@martijnhoekstra
It looks like listDelimited (intentionally) only works for "aligned" delimiters
When decoding, the input bits are first (logically) grouped into delimiter sized chunks and partitioned around delimiter chunks.
Kaspar Minosiants
@minosiants
@martijnhoekstra thanks a lot for the reply. I created a custom codec to deal with it. I was trying to avoid to do it. Could you please explain what does "aligned" delimiters mean.
Martijn Hoekstra
@martijnhoekstra
What I mean by that is (from what I gather from the documentation), it looks for delimiter only at positions (n * delimiter length) for the delimiter, not in between
Kaspar Minosiants
@minosiants
Ah ok . Understood. Thanks again !
Martijn Hoekstra
@martijnhoekstra
it seems non-intuitive to me too!
Luciano
@lJoublanc
Hi @mpilquist . Thanks for your continued work on scodec! I recently updated to 1.11.x and see that the apply summoner has been removed in favour of summoner. Can I ask the rationale behind this?
I think the readme examples don't reflect these changes.
To be honest I don't particularly like it, but having said that, I don't contribute to the project so I won't complain! :laughing: Again, your efforts for maintaining the library are greatly appreciated :100: :+1:
Luciano
@lJoublanc
Also the removal of Encoder.encode makes things much more verbose. Now I would write Codec.summon[E].encode(...) instead of Codec.encode(...). Not a big deal though. I think it's more of a problem if you use the [A: F] implicit syntax instead of writing out a parameter (implicit F: F[A]).
Michael Pilquist
@mpilquist
Hm you’re seeing that with 1.11? Those changes should only be on master branch and are targeted for Dotty supporting release
Michael Pilquist
@mpilquist
Oh no, that made 1.11 by accident
Michael Pilquist
@mpilquist
BTW, the rationale for removing the summoning apply and removing Codec.encode and Codec.decode was to de-emphasize passing of codecs implicitly and instead encourage passing them as values.
For 1.11, I think I’ll release a 1.11.7 that restores binary & source compatibility and save these more drastic changes for scodec-2 / dotty version
sken
@sken77
does scodec has a combinator to turn a Bit/ByteVector into a Java ByteBuffer? im using a jni library right now and it would be nice to be able to use scodec easily with it
Paul Snively
@paul-snively
@sken77: .toByteBuffer.
sken
@sken77
so nice. thanks!
Paul Snively
@paul-snively
You bet!
Luciano
@lJoublanc
For 1.11, I think I’ll release a 1.11.7 that restores binary & source compatibility and save these more drastic changes for scodec-2 / dotty version
:+1:
Michael Pilquist
@mpilquist
Just published 1.11.7 which restores source & binary compatibility
Of course, that means 1.11.5/1.11.6 is not binary compatible with 1.11.7
Anthony Cerruti
@srnb_gitlab
Are there codecs for APNG/WebP?
Michael Pilquist
@mpilquist
I don’t know those acronyms so I’m guessing not ;)
Anthony Cerruti
@srnb_gitlab
Animated PNG, and WebP is Google's lossy or lossless format that also supports animation
I just want something besides GIF to export to
Luciano
@lJoublanc

Just published 1.11.7 which restores source & binary compatibility

Looks good! :+1:

Luciano
@lJoublanc
Completely unrelated to the above, but any idea why Codec.{apply,summon}[A] would fail to resolve, while implicitly[Codec[A]] works fine?
Michael Pilquist
@mpilquist
That would be very weird. I could see the opposite maybe due to use of Lazy
Luciano
@lJoublanc
Ah figured it out, was very subtle - had a private Poly which couldn't be accessed with Lazy.
I'm now used to the splain plugin, and didn't realise I could still get debug info from -Xlog-implicits, which saved me in the end.
RAJKUMAR NATARAJAN
@rajcspsg
Hi
I have below case class
case class Foo(code: Int, msg: String, headers: Map[String,String] = Map.empty)
I don't know how to write the Codec for Map[String, String]
I could n't find any example online or in document
any help on this?
Michael Pilquist
@mpilquist
Are you okay with entries being serialized in their iteration order?
def map[K, V](keyCodec: Codec[K], valueCodec: Codec[V]): Codec[Map[K, V]] =
    listOfN(int32, keyCodec ~ valueCodec).xmap(_.toMap, _.toList)
RAJKUMAR NATARAJAN
@rajcspsg
@mpilquist yeap
I will try this and let you know if I need any help
RAJKUMAR NATARAJAN
@rajcspsg
Thanks @mpilquist It works for me!!!
Luciano
@lJoublanc

I've implemented some codecs for google protobuf. In the spec, each element is discriminated by it's index. So I have created an algebra PartialCodec[A] := i ===> Codec[A]. You can think of this loosely as Int => Codec[A].
Now, I've written a bunch of combinators and everything works relatively well. But I've run into a huge problem. I'm unable to write codecs for recursive structures explicitly!
In vanilla scodec this works fine, using lazily. But I've found that if I want to do the same, it won't work, because I always need to apply my partial function Int => Codec[A] to pass it to the combinators.
Here's an example:

    import scodec.TransformSyntax
    import scodec.protocols.protobuf.v3.{message => msg, oneOf => oneOF}
    import scodec.protocols.protobuf.v3.implicits._

    case class First(i: Int, s: Second)
    case class Second(l: Long, e: Either[String, First])
    object Second {
      implicit def pc: PartialCodec.Aux[2, Second] =
        msg(int64 := 1, oneOF(string := 2, lazily(PartialCodec[First] := 3))).as[Second]
    }

This compiles fine, but results in a SO. lazily doesn't work, because := 3 forces evaluation of the codec (remember def lazily[A](codec: ***=>*** Codec[A]): Codec[A])
I've got a gruesome workaround, but would like to know if someone can think of a nicer way to tackle this.

Alice
@fp-alice

Hello everyone! I've been using scodec with Http4s and websockets as an alternative to protobuf or similar, and I have a file that looks like this.

import scodec.codecs._
import scodec.codecs.implicits._

sealed trait In {
  def toString: String
}

object In {
  implicit val discriminated: Discriminated[In, Int] = Discriminated(uint8)
}

case class ClientConnect(account: String) extends In {
  override def toString: String = s"$account connected"
}

object ClientConnect {
  implicit val discriminator: Discriminator[In, ClientConnect, Int] = Discriminator(0)
}

case class ClientDisconnect(account: String) extends In {
  override def toString: String = s"$account disconnected"
}

object ClientDisconnect {
  implicit val discriminator: Discriminator[In, ClientDisconnect, Int] = Discriminator(1)
}

case class ClientUpdatePosition(account: String, location: (Double, Double, Double)) extends In {
  override def toString: String = s"$account moved to $location"
}

object ClientUpdatePosition {
  implicit val discriminator: Discriminator[In, ClientUpdatePosition, Int] = Discriminator(2)
}

Maybe it's just me, but i feel this is un-ergonomic, is there an easier way for me to get a coproduct decoder with separate files and no companion objects?

Alice
@fp-alice
Will this work if I break up the individual packets into different files? or do they have to extend a sealed trait in the same file
Alice
@fp-alice
Worked for me :) thanks for the suggestion
Michael Pilquist
@mpilquist
Great :)
Luciano
@lJoublanc
Slightly off-topic, but Is there an equivalent to Transformer in cats?
Michael Pilquist
@mpilquist
FunctionK basically
Lj Chen
@floating-cat

Hello everyone,
I want to implement the socks5 protocol by using the fs2 & scodec. The client will first send an authorization request, and then it will send a data request. After that, it will send many data (bits). I want to reply after I received the auth request and the data request.
I checked the fs2-chat example, and it uses the discriminated[Model].by to covert these data to ADT for replying. I want to do it too. But this protocol doesn't have any tags (it use the order of sending), so I can't covert it back to an ADT by using similar ways.
Currently, two bad ideas come to mind:

  1. Decode/encode the request/reply manually.
  2. Write a custom Codec with a mutable variable for tracking it, and produce the ADT each time.

Is there any better to do it by using scodec?