Skip to content

Instantly share code, notes, and snippets.

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