Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README.md seems to be outdated #94

Closed
unoexperto opened this issue Dec 26, 2016 · 3 comments
Closed

README.md seems to be outdated #94

unoexperto opened this issue Dec 26, 2016 · 3 comments

Comments

@unoexperto
Copy link

unoexperto commented Dec 26, 2016

I'm using Kryo at the moment. I've heard about scodec and decided to try it.

Sadly none of the examples from README.md work for me.

Since it doesn't say what dependencies to use I took the latest from Maven

          "org.scodec" %% "scodec-core" % "1.10.3",
          "org.scodec" %% "scodec-bits" % "1.1.2",
          "org.scodec" %% "scodec-scalaz" % "1.4.1",

Following code can't find codec for String

    val test = "sdfsfd"
    import scodec._
    import scodec.bits._
    import codecs._
    val encoded = Codec.encode(test)

error is

Error:(296, 31) could not find Lazy implicit value of type scodec.Codec[String]
    val encoded = Codec.encode(test)

I was able to compile it by changing it to

val encoded = Codec.encode(test)(codecs.string(Charset.defaultCharset()))

but I doubt it's designed way of using it.

Then following code

    val firstCodec = (uint8 ~ uint8 ~ uint16)
    val result: DecodeResult[(Int ~ Int ~ Int)] = Codec.decode(firstCodec, BitVector(0x10, 0x2a, 0x03, 0xff))
    val add3 = (_: Int) + (_: Int) + (_: Int)
    val sum: DecodeResult[Int] = result map add3

doesn't compile because there is no decode with such prototype. I guess I can change it to

val result: Attempt[DecodeResult[((Int, Int), Int)]] = Codec.decode(BitVector(0x10, 0x2a, 0x03, 0xff))(firstCodec)

but returning type is different so result map add3 doesn't compile because there is no map method.

Could you please update readme to latest version of the library ?

Thank you.

@unoexperto
Copy link
Author

Apparently import scodec.codecs.implicits._ is what I needed.

@Tillaert
Copy link

I've had to modify the example, because Codec.decode now returns an Attempt[DecodeResult[(Int ~ Int ~ Int)]]

The whole example now looks like this:

import scodec._
import scodec.bits._
import codecs._

// Create a codec for an 8-bit unsigned int followed by an 8-bit unsigned int followed by a 16-bit unsigned int
val firstCodec = uint8 ~ uint8 ~ uint16

// Decode a bit vector using that codec
val result: Attempt[DecodeResult[(Int ~ Int ~ Int)]] = Codec.decode(BitVector(0x10, 0x2a, 0x03, 0xff))(firstCodec)
// Successful(DecodeResult(((16,42),1023),BitVector(empty)))

// Sum the result
val add3 = (_: Int) + (_: Int) + (_: Int)

val sum: DecodeResult[Int] = result.require.map(add3)
// DecodeResult(1081,BitVector(empty))

@mpilquist
Copy link
Contributor

Thanks for pointing this out. README has been updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants