scodec.stream

decode

package decode

Module containing various streaming decoding combinators. Decoding errors are represented using scodec.stream.decode.DecodingError.

Source
package.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. decode
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class Cursor[+A](run: (BitVector) ⇒ \/[Err, (BitVector, A)]) extends Product with Serializable

  2. case class DecodingError(err: Err) extends Exception with Product with Serializable

  3. trait StreamDecoder[+A] extends AnyRef

    A streaming decoding process, represented as a stream of state actions on scodec.bits.BitVector.

    A streaming decoding process, represented as a stream of state actions on scodec.bits.BitVector. Most clients will typically use one of the decoding convenience methods on this class, rather than using decoder directly.

Value Members

  1. object Cursor extends Serializable

  2. object StreamDecoder

  3. def advance(n: Long): StreamDecoder[Nothing]

    Advance the input by the given number of bits, purely as an effect.

  4. def ask: StreamDecoder[BitVector]

    Obtain the current input.

    Obtain the current input. This stream returns a single element.

  5. def drop(n: Long): StreamDecoder[BitVector]

    Advance the input by the given number of bits.

  6. def emit[A](a: A): StreamDecoder[A]

    The decoder that consumes no input, emits the given a, then halts.

  7. def emitAll[A](as: Seq[A]): StreamDecoder[A]

    The decoder that consumes no input, emits the given A values, then halts.

  8. def fail(err: Err): StreamDecoder[Nothing]

    The decoder that consumes no input and halts with the given error.

  9. def fail(err: Throwable): StreamDecoder[Nothing]

    The decoder that consumes no input and halts with the given error.

  10. val halt: StreamDecoder[Nothing]

    The decoder that consumes no input and emits no values.

  11. def isolate[A](numberOfBits: Long)(d: ⇒ StreamDecoder[A]): StreamDecoder[A]

    Run the given StreamDecoder using only the first numberOfBits bits of the current stream, then advance the cursor by that many bits on completion.

  12. def isolateBytes[A](numberOfBytes: Long)(d: ⇒ StreamDecoder[A]): StreamDecoder[A]

    Run the given StreamDecoder using only the first numberOfBytes bytes of the current stream, then advance the cursor by that many bytes on completion.

  13. def many[A](implicit A: Lazy[Decoder[A]]): StreamDecoder[A]

    Parse a stream of A values from the input, using the given decoder.

    Parse a stream of A values from the input, using the given decoder. The returned stream terminates normally if the final value decoded exhausts in and leaves no trailing bits. The returned stream terminates with an error if the Decoder[A] ever fails on the input.

  14. def many1[A](implicit A: Lazy[Decoder[A]]): StreamDecoder[A]

    Like scodec.stream.decode.many, but fails with an error if no elements are decoded.

    Like scodec.stream.decode.many, but fails with an error if no elements are decoded. The returned stream will have at least one element if it succeeds.

  15. def manyChunked[A](chunkSize: Int)(implicit A: Lazy[Decoder[A]]): StreamDecoder[A]

    Like many, but reads up to chunkSize elements from the stream at a time, to minimize overhead.

    Like many, but reads up to chunkSize elements from the stream at a time, to minimize overhead. Since this "reads ahead" in the stream, it can't be used predictably when the returned decoder will be interleaved with another decoder, as in sepBy, or any other combinator that uses tee.

  16. def modify(f: (BitVector) ⇒ BitVector): StreamDecoder[BitVector]

    Modify the current input.

    Modify the current input. This stream returns a single element.

  17. def once[A](implicit A: Lazy[Decoder[A]]): StreamDecoder[A]

    Run the given Decoder once and emit its result, if successful.

  18. def or[A](p1: StreamDecoder[A], p2: StreamDecoder[A]): StreamDecoder[A]

    Runs p1, then runs p2 if p1 emits no elements.

    Runs p1, then runs p2 if p1 emits no elements. Example: or(tryOnce(codecs.int32), once(codecs.uint32)). This function does no backtracking of its own; backtracking should be handled by p1.

  19. def peek[A](d: StreamDecoder[A]): StreamDecoder[A]

    Run this decoder, but leave its input unconsumed.

    Run this decoder, but leave its input unconsumed. Note that this requires keeping the current stream in memory for as long as the given decoder takes to complete.

  20. def process[A](implicit A: Lazy[Decoder[A]]): Process1[BitVector, A]

    Promote a decoder to a Process1.

    Promote a decoder to a Process1. The returned Process1 may be given chunks larger or smaller than what is needed to decode a single element, and will buffer any unconsumed input, but a decoding error will result if the decoder fails for a reason other than Err.InsufficientBits.

    This combinator relies on the decoder satisfying the following property: If successful on input x, A should also succeed with the same value given input x ++ y, for any choice of y. This ensures the decoder can be given more input than it needs without affecting correctness, and generally restricts this combinator to being used with "self-delimited" decoders. Using this combinator with a decoder not satisfying this property will make results highly dependent on the sequence of chunk sizes passed to the process.

  21. def sepBy[A, D](implicit A: Lazy[Decoder[A]], D: Lazy[Decoder[D]]): StreamDecoder[A]

    Like many, but parses and ignores a D delimiter value in between decoding each A value.

  22. def sepBy1[A, D](implicit A: Lazy[Decoder[A]], D: Lazy[Decoder[D]]): StreamDecoder[A]

    Like scodec.stream.decode.sepBy, but fails with an error if no elements are decoded.

    Like scodec.stream.decode.sepBy, but fails with an error if no elements are decoded. The returned stream will have at least one element if it succeeds.

  23. def set(bits: BitVector): StreamDecoder[Nothing]

    Set the current cursor to the given BitVector.

  24. def suspend[A](d: ⇒ StreamDecoder[A]): StreamDecoder[A]

    Produce a StreamDecoder lazily.

  25. def take(n: Long): StreamDecoder[BitVector]

    Trim the input by calling take(n) on the input BitVector.

  26. def tryMany[A](implicit A: Lazy[Decoder[A]]): StreamDecoder[A]

    Like scodec.stream.decode.many, but in the event of a decoding error, resets cursor to end of last successful decode, then halts normally.

  27. def tryManyChunked[A](chunkSize: Int)(implicit A: Lazy[Decoder[A]]): StreamDecoder[A]

    Like scodec.stream.decode.tryMany, but reads up to chunkSize elements at once.

    Like scodec.stream.decode.tryMany, but reads up to chunkSize elements at once. As mentioned in scodec.stream.decode.manyChunks, the resulting decoder cannot be meaningfully interleaved with other decoders.

  28. def tryOnce[A](implicit A: Lazy[Decoder[A]]): StreamDecoder[A]

    Like scodec.stream.decode.once, but halts normally and leaves the input unconsumed in the event of a decoding error.

    Like scodec.stream.decode.once, but halts normally and leaves the input unconsumed in the event of a decoding error. tryOnce[A].repeat will produce the same result as many[A], but allows.

Inherited from AnyRef

Inherited from Any

Ungrouped