Skip to content

Instantly share code, notes, and snippets.

@pchiusano
Created March 19, 2014 19:56
Show Gist options
  • Select an option

  • Save pchiusano/9649940 to your computer and use it in GitHub Desktop.

Select an option

Save pchiusano/9649940 to your computer and use it in GitHub Desktop.
Streaming binary decoding example
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