Skip to content

Instantly share code, notes, and snippets.

@searler
Created August 10, 2015 22:47
Show Gist options
  • Save searler/169859105a121d5f6505 to your computer and use it in GitHub Desktop.
Save searler/169859105a121d5f6505 to your computer and use it in GitHub Desktop.
A trivial convenience mechanism to map between BitVector and ByteVector
import scodec.Codec
import scodec.bits.ByteVector
object ByteVectorCodec extends Codec[ByteVector] {
import scodec.{ Attempt, DecodeResult }
import scodec.SizeBound
import scodec.bits.BitVector
def sizeBound = new SizeBound(0, None)
def encode(value: ByteVector): Attempt[BitVector] = Attempt.successful(value.bits)
def decode(bits: BitVector): Attempt[DecodeResult[ByteVector]] = Attempt.successful(DecodeResult(bits.bytes, BitVector.empty))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment