binary-0.6.4.0: Binary serialisation for Haskell values using lazy ByteStrings

Safe HaskellNone

Data.Binary.Get.Internal

Contents

Synopsis

The Get type

runCont :: Get a -> forall r. ByteString -> Success a r -> Decoder rSource

data Decoder a Source

A decoder procuced by running a Get monad.

Constructors

Fail !ByteString String

The decoder ran into an error. The decoder either used fail or was not provided enough input.

Partial (Maybe ByteString -> Decoder a)

The decoder has consumed the available input and needs more to continue. Provide Just if more input is available and Nothing otherwise, and you will get a new Decoder.

Done !ByteString a

The decoder has successfully finished. Except for the output value you also get the unused input.

BytesRead !Int64 (Int64 -> Decoder a)

The decoder needs to know the current position in the input. Given the number of bytes remaning in the decoder, the outer decoder runner needs to calculate the position and resume the decoding.

Instances

runGetIncremental :: Get a -> Decoder aSource

Run a Get monad. See Decoder for what to do next, like providing input, handling decoding errors and to get the output value.

readN :: Int -> (ByteString -> a) -> Get aSource

Return at least n bytes, maybe more. If not enough data is available the computation will escape with Partial.

readNWith :: Int -> (Ptr a -> IO a) -> Get aSource

Parsing

skip :: Int -> Get ()Source

Skip ahead n bytes. Fails if fewer than n bytes are available.

bytesRead :: Get Int64Source

Get the total number of bytes read to this point.

get :: Get ByteStringSource

Get the current chunk.

put :: ByteString -> Get ()Source

Replace the current chunk.

demandInput :: Get ()Source

Demand more input. If none available, fail.

ensureN :: Int -> Get ()Source

Ensure that there are at least n bytes available. If not, the computation will escape with Partial.

Utility

remaining :: Get Int64Source

Deprecated: This will force all remaining input, don't use it.

DEPRECATED. Get the number of bytes of remaining input. Note that this is an expensive function to use as in order to calculate how much input remains, all input has to be read and kept in-memory. The decoder keeps the input as a strict bytestring, so you are likely better off by calculating the remaining input in another way.

getBytes :: Int -> Get ByteStringSource

Deprecated: Use 'getByteString' instead of 'getBytes'.

DEPRECATED. Same as getByteString.

isEmpty :: Get BoolSource

Test whether all input has been consumed, i.e. there are no remaining undecoded bytes.

ByteStrings

getByteString :: Int -> Get ByteStringSource

An efficient get method for strict ByteStrings. Fails if fewer than n bytes are left in the input. If n <= 0 then the empty string is returned.