binary-strict-0.4.8.5: Binary deserialisation using strict ByteStrings

CopyrightLennart Kolmodin
LicenseBSD3-style (see LICENSE)
MaintainerAdam Langley <agl@imperialviolet.org>
Stabilityexperimental
Portabilityportable to Hugs and GHC.
Safe HaskellNone
LanguageHaskell2010

Data.Binary.Strict.Get

Contents

Description

This is a strict version of the Get monad from the binary package. It's pretty much just a copy and paste job from the original source code. The binary team are currently unsure about their future plans w.r.t. strictness, so this is a stop gap measure.

To use, write a function in the Get monad:

import Data.Binary.Strict.Get as BinStrict
import Data.ByteString as BS
parse :: BinStrict.Get
parse = getWord16be
main = print $ runGet parse $ BS.pack [1, 1]

This results in a tuple of (Right 257, "") (where the second element is just the remaining data after the parser has run)

Synopsis

The Get type

data Get a Source #

Instances
Monad Get Source # 
Instance details

Defined in Data.Binary.Strict.Get

Methods

(>>=) :: Get a -> (a -> Get b) -> Get b #

(>>) :: Get a -> Get b -> Get b #

return :: a -> Get a #

fail :: String -> Get a #

Functor Get Source # 
Instance details

Defined in Data.Binary.Strict.Get

Methods

fmap :: (a -> b) -> Get a -> Get b #

(<$) :: a -> Get b -> Get a #

Applicative Get Source # 
Instance details

Defined in Data.Binary.Strict.Get

Methods

pure :: a -> Get a #

(<*>) :: Get (a -> b) -> Get a -> Get b #

liftA2 :: (a -> b -> c) -> Get a -> Get b -> Get c #

(*>) :: Get a -> Get b -> Get b #

(<*) :: Get a -> Get b -> Get a #

Alternative Get Source # 
Instance details

Defined in Data.Binary.Strict.Get

Methods

empty :: Get a #

(<|>) :: Get a -> Get a -> Get a #

some :: Get a -> Get [a] #

many :: Get a -> Get [a] #

MonadPlus Get Source # 
Instance details

Defined in Data.Binary.Strict.Get

Methods

mzero :: Get a #

mplus :: Get a -> Get a -> Get a #

BinaryParser Get Source # 
Instance details

Defined in Data.Binary.Strict.Get

runGet :: Get a -> ByteString -> (Either String a, ByteString) Source #

Run a parser on the given input and return the result (either an error string from a call to fail, or the parsing result) and the remainder of of the input.

Parsing

lookAhead :: Get a -> Get a Source #

Run ga, but return without consuming its input. Fails if ga fails.

lookAheadM :: Get (Maybe a) -> Get (Maybe a) Source #

Like lookAhead, but consume the input if gma returns 'Just _'. Fails if gma fails.

lookAheadE :: Get (Either a b) -> Get (Either a b) Source #

Like lookAhead, but consume the input if gea returns 'Right _'. Fails if gea fails.

plus :: Get a -> Get a -> Get a Source #

Utility

skip :: Int -> Get () Source #

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

bytesRead :: Get Int Source #

Get the total number of bytes read to this point.

remaining :: Get Int Source #

Get the number of remaining unparsed bytes. Useful for checking whether all input has been consumed.

isEmpty :: Get Bool Source #

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

Parsing particular types

ByteStrings

getByteString :: Int -> Get ByteString Source #

An efficient get method for strict ByteStrings. Fails if fewer than n bytes are left in the input.

Big-endian reads

Little-endian reads

Host-endian, unaligned reads

Floating point