Created
March 19, 2014 19:56
-
-
Save pchiusano/9649940 to your computer and use it in GitHub Desktop.
Streaming binary decoding example
This file contains hidden or 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
| trait StreamDecoder[+A] { | |
| import scodec.stream.{decode => D} | |
| def mapEither[B](f: A => String \/ B): StreamDecoder[B] = | |
| flatMap { a => f(a).fold(D.fail, D.emit) } | |
| } | |
| val packets: StreamDecoder[MpegPacket] = pcapRecordStreamDecoder mapEither { record => | |
| val datagramPayloadBits = record.data.drop(22 * 8).drop(20 * 8) | |
| decode.many[MpegPacket].decode(datagramPayloadBits) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment