Skip to content

Instantly share code, notes, and snippets.

@Maksim-Zhuravlev
Created April 17, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maksim-Zhuravlev/29238c547bd4f5eed1d1d392d9845abe to your computer and use it in GitHub Desktop.
Save Maksim-Zhuravlev/29238c547bd4f5eed1d1d392d9845abe to your computer and use it in GitHub Desktop.
Example of scodec
package GIFReader
import scodec._
import bits._
import codecs._
import java.nio.file.{Files, Paths}
case class GIFHeader(width : Int, height : Int)
/**
* Created by maxim on 17.04.2016.
*/
class Decoder(path : String) {
val byteArray = Files.readAllBytes(Paths.get(path))
val bitVector = BitVector(byteArray)
val headerCodec = (constant(hex"474946383961".bits) :: uint16L :: uint16L).as[GIFHeader] //GIF89a
val decoded = headerCodec.decode(bitVector)
println(decoded.require.value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment