scodec.stream

decode

package decode

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

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) ⇒ \/[String, (BitVector, A)]) extends Product with Serializable

  2. case class DecodingError(message: String) 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.

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(msg: String): StreamDecoder[Nothing]

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

  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: 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 arg0: 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 modify(f: (BitVector) ⇒ BitVector): StreamDecoder[BitVector]

    Modify the current input.

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

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

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

  17. 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.

  18. 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.

  19. def process[A](implicit A: 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 than what is needed to decode a single element, and will buffer any leftover input, but a decoding error will result if the buffer size is ever less than what is needed to decode an A.

    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.

  20. def sepBy[A, D](implicit arg0: Decoder[A], arg1: Decoder[D]): StreamDecoder[A]

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

  21. def sepBy1[A, D](implicit arg0: Decoder[A], arg1: 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.

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

    Set the current cursor to the given BitVector.

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

    Produce a StreamDecoder lazily.

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

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

  25. def tryMany[A](implicit A: 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.

  26. def tryOnce[A](implicit A: 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.

  27. def tryProcess[A](attemptBits: Long)(implicit A: Decoder[A]): Process1[BitVector, A]

    Like scodec.stream.decode.process, but the returned process may be given chunks larger OR smaller than what is needed to decode a single element.

    Like scodec.stream.decode.process, but the returned process may be given chunks larger OR smaller than what is needed to decode a single element. After the buffer size has grown beyond attemptBits, decoding failures are raised rather than being treated as an indication that more input is needed. Without this argument, a failing decoder due to malformed input would eventually buffer the entire input before halting.

    In addition to the monotonicity requirement given in scodec.stream.decode.process, we require also that if A fails on x ++ y, it must also fail for x, for any choices of x and y. This ensures that we can feed the decoder less than its expected input, and interpret failure as an indication that more input is needed.

Inherited from AnyRef

Inherited from Any

Ungrouped