package decode
Module containing various streaming decoding combinators. Decoding errors are represented using scodec.stream.decode.DecodingError.
- Source
- package.scala
- Alphabetic
- By Inheritance
- decode
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- case class Cursor [+A](run: (BitVector) ⇒ Attempt[DecodeResult[A]]) extends Product with Serializable
- case class DecodingError (err: Err) extends Exception with Product with Serializable
-
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
decoderdirectly.
Value Members
-
def
advance(n: Long): StreamDecoder[Nothing]
Advance the input by the given number of bits, purely as an effect.
-
def
ask: StreamDecoder[BitVector]
Obtain the current input.
Obtain the current input. This stream returns a single element.
-
def
drop(n: Long): StreamDecoder[BitVector]
Advance the input by the given number of bits.
-
def
emit[A](a: A): StreamDecoder[A]
The decoder that consumes no input, emits the given
a, then halts. -
def
emits[A](as: Seq[A]): StreamDecoder[A]
The decoder that consumes no input, emits the given
Avalues, then halts. -
val
empty: StreamDecoder[Nothing]
The decoder that consumes no input and emits no values.
-
def
fail(err: Err): StreamDecoder[Nothing]
The decoder that consumes no input and halts with the given error.
-
def
fail(err: Throwable): StreamDecoder[Nothing]
The decoder that consumes no input and halts with the given error.
-
def
isolate[A](numberOfBits: Long)(d: ⇒ StreamDecoder[A]): StreamDecoder[A]
Run the given
StreamDecoderusing only the firstnumberOfBitsbits of the current stream, then advance the cursor by that many bits on completion. -
def
isolateBytes[A](numberOfBytes: Long)(d: ⇒ StreamDecoder[A]): StreamDecoder[A]
Run the given
StreamDecoderusing only the firstnumberOfBytesbytes of the current stream, then advance the cursor by that many bytes on completion. -
def
many[A](implicit A: Lazy[Decoder[A]]): StreamDecoder[A]
Parse a stream of
Avalues from the input, using the given decoder.Parse a stream of
Avalues from the input, using the given decoder. The returned stream terminates normally if the final value decoded exhaustsinand leaves no trailing bits. The returned stream terminates with an error if theDecoder[A]ever fails on the input. -
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.
-
def
manyChunked[A](chunkSize: Int)(implicit A: Lazy[Decoder[A]]): StreamDecoder[A]
Like
many, but reads up tochunkSizeelements from the stream at a time, to minimize overhead.Like
many, but reads up tochunkSizeelements 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 insepBy, or any other combinator that usestee. -
def
modify(f: (BitVector) ⇒ BitVector): StreamDecoder[BitVector]
Modify the current input.
Modify the current input. This stream returns a single element.
-
def
once[A](implicit A: Lazy[Decoder[A]]): StreamDecoder[A]
Run the given
Decoderonce and emit its result, if successful. -
def
or[A](s1: StreamDecoder[A], s2: StreamDecoder[A]): StreamDecoder[A]
Runs
s1, then runss2ifs1emits no elements.Runs
s1, then runss2ifs1emits no elements. Example:or(tryOnce(codecs.int32), once(codecs.uint32)). This function does no backtracking of its own; backtracking should be handled bys1. -
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.
-
def
pipe[F[_], A](implicit A: Lazy[Decoder[A]]): Pipe[F, BitVector, A]
Promote a decoder to a
Pipe[F, BitVector, A.Promote a decoder to a
Pipe[F, BitVector, A. The returned pipe 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 thanErr.InsufficientBits.This combinator relies on the decoder satisfying the following property: If successful on input
x,Ashould also succeed with the same value given inputx ++ y, for any choice ofy. 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. -
def
sepBy[A, D](implicit A: Lazy[Decoder[A]], D: Lazy[Decoder[D]]): StreamDecoder[A]
Like
many, but parses and ignores aDdelimiter value in between decoding eachAvalue. -
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. -
def
set(bits: BitVector): StreamDecoder[Nothing]
Set the current cursor to the given
BitVector. -
def
suspend[A](d: ⇒ StreamDecoder[A]): StreamDecoder[A]
Produce a
StreamDecoderlazily. -
def
take(n: Long): StreamDecoder[BitVector]
Trim the input by calling
take(n)on the inputBitVector. -
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.
-
def
tryManyChunked[A](chunkSize: Int)(implicit A: Lazy[Decoder[A]]): StreamDecoder[A]
Like
scodec.stream.decode.tryMany, but reads up tochunkSizeelements at once.Like
scodec.stream.decode.tryMany, but reads up tochunkSizeelements at once. As mentioned in scodec.stream.decode.manyChunked, the resulting decoder cannot be meaningfully interleaved with other decoders. -
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].repeatwill produce the same result asmany[A], but allows. - object Cursor extends Serializable
- object StreamDecoder