Created
August 10, 2015 22:48
-
-
Save searler/0bddad0c1498de3e4a39 to your computer and use it in GitHub Desktop.
A trivial convenience Codec to map between Akka ByteString and scodec BitVector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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