StreamDecoder

fs2.interop.scodec.StreamDecoder
See theStreamDecoder companion object
final class StreamDecoder[+A]

Supports binary decoding of a stream that emits elements as they are decoded.

The main purpose of using a StreamDecoder over a scodec.Decoder is mixing decoding with processing. For example, scodec.codecs.vector(decoderA): Decoder[Vector[A]] could be used to decode a bit stream but the decoded Vector[A] would not be emitted until the end of the bit stream. With StreamDecoder.many(decoderA): StreamDecoder[A], each decoded A value is emitted as soon as it is decoded.

The StreamDecoder companion has various constructors -- most importantly, once and many, that allow a Decoder[A] to be lifted to a StreamDecoder[A].

Given a StreamDecoder[A], a bit stream can be decoded via the decode method or by calling a variant of toPipe.

Attributes

Companion
object
Source
StreamDecoder.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def ++[A2 >: A](that: => StreamDecoder[A2]): StreamDecoder[A2]

Creates a stream decoder that first decodes until this decoder finishes and then decodes using the supplied decoder.

Creates a stream decoder that first decodes until this decoder finishes and then decodes using the supplied decoder.

Note: this should not be used to write recursive decoders (e.g., def ints: StreamDecoder[A] = once(int32) ++ ints) if each incremental decoding step can fail with InsufficientBits. Otherwise, it decoding can get stuck in an infinite loop, where the remaining bits are fed to the recursive call.

Attributes

Source
StreamDecoder.scala
def apply[F[_] : RaiseThrowable](s: Stream[F, BitVector]): Pull[F, A, Option[Stream[F, BitVector]]]

Returns a Pull[F, A, Option[Stream[F, BitVector]]] given a Stream[F, BitVector].

Returns a Pull[F, A, Option[Stream[F, BitVector]]] given a Stream[F, BitVector]. The result of the returned pull is the remainder of the input stream that was not used in decoding.

Attributes

Source
StreamDecoder.scala
def decode[F[_] : RaiseThrowable](s: Stream[F, BitVector]): Stream[F, A]

Returns a Stream[F, A] given a Stream[F, BitVector].

Returns a Stream[F, A] given a Stream[F, BitVector].

Attributes

Source
StreamDecoder.scala
def flatMap[B](f: A => StreamDecoder[B]): StreamDecoder[B]

Creates a stream decoder that, upon decoding an A, applies it to the supplied function and decodes the next part of the input with the returned decoder.

Creates a stream decoder that, upon decoding an A, applies it to the supplied function and decodes the next part of the input with the returned decoder. When that decoder finishes, the remainder of the input is returned to the original decoder for further decoding.

Attributes

Source
StreamDecoder.scala
def handleErrorWith[A2 >: A](f: Throwable => StreamDecoder[A2]): StreamDecoder[A2]

Attributes

Source
StreamDecoder.scala
def isolate(bits: Long): StreamDecoder[A]

Alias for StreamDecoder.isolate(bits)(this).

Alias for StreamDecoder.isolate(bits)(this).

Attributes

Source
StreamDecoder.scala
def map[B](f: A => B): StreamDecoder[B]

Maps the supplied function over each output of this decoder.

Maps the supplied function over each output of this decoder.

Attributes

Source
StreamDecoder.scala
def strict: Decoder[Vector[A]]

Converts this stream decoder to a Decoder[Vector[A]].

Converts this stream decoder to a Decoder[Vector[A]].

Attributes

Source
StreamDecoder.scala
def toPipe[F[_] : RaiseThrowable]: (F, BitVector) => A

Converts this decoder to a Pipe[F, BitVector, A].

Converts this decoder to a Pipe[F, BitVector, A].

Attributes

Source
StreamDecoder.scala
def toPipeByte[F[_] : RaiseThrowable]: (F, Byte) => A

Converts this decoder to a Pipe[F, Byte, A].

Converts this decoder to a Pipe[F, Byte, A].

Attributes

Source
StreamDecoder.scala