Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
- data Get e a
- getLazyByteString :: Int64 -> Get () ByteString
- getLazyByteStringNul :: Get () ByteString
- getRemainingLazyByteString :: Get e ByteString
- getPtr :: Storable a => Int -> Get () a
- getWord8 :: Get () Word8
- getWord16be :: Get () Word16
- getWord16le :: Get () Word16
- getWord32be :: Get () Word32
- getWord32le :: Get () Word32
- getWord64be :: Get () Word64
- getWord64le :: Get () Word64
- getWordhost :: Get () Word
- getWord16host :: Get () Word16
- getWord32host :: Get () Word32
- getWord64host :: Get () Word64
- failGet :: e -> Get e a
- constant :: (forall r. XDecoder e r) -> Get e a
- bytesRead :: Get e Int64
- demandInput :: Get () ()
- skip :: Int -> Get () ()
- isNotEmpty :: Get e Bool
- isEmpty :: Get e Bool
- getByteString :: Int -> Get () ByteString
- modify :: (ByteString -> ByteString) -> Get e ()
- readN :: Int -> (ByteString -> a) -> Get () a
- ensureN :: Int -> Get () ()
- runAndKeepTrack :: Get e a -> Get x (CompletedXDecoder e a, [ByteString])
- pushBack :: [ByteString] -> Get e ()
- pushFront :: ByteString -> Get e ()
- xrunGetIncremental :: Get e a -> XDecoder e a
- noMeansNo :: XDecoder e a -> XDecoder e a
- prompt :: ByteString -> XDecoder e a -> (ByteString -> XDecoder e a) -> XDecoder e a
- isolate :: Int -> Get e a -> Get (IsolateError e) a
- lookAhead :: Get e a -> Get e a
- lookAheadM :: Get e (Maybe a) -> Get e (Maybe a)
- lookAheadE :: Get e (Either a b) -> Get e (Either a b)
- readNWith :: Int -> (Ptr a -> IO a) -> Get () a
- calculateOffset :: XDecoder e a -> Decoder e a
- pushChunk :: Decoder e a -> ByteString -> Decoder e a
- pushChunks :: Decoder e a -> ByteString -> Decoder e a
- pushEndOfInput :: Decoder e a -> Decoder e a
- (!+) :: Semigroup e => e -> Get e a -> Get e a
- addLabel :: Semigroup e => e -> Get e a -> Get e a
- (!-) :: e -> Get d a -> Get e a
- setLabel :: e -> Get d a -> Get e a
- (!!-) :: (d -> e) -> Get d a -> Get e a
- modifyLabel :: (d -> e) -> Get d a -> Get e a
- data Decoder e a
- decoder :: (ByteString -> Int64 -> e -> x) -> ((Maybe ByteString -> Decoder e a) -> x) -> (ByteString -> Int64 -> a -> x) -> Decoder e a -> x
- _Fail :: Prism' (Decoder e a) (ByteString, Int64, e)
- _Partial :: Prism' (Decoder e a) (Maybe ByteString -> Decoder e a)
- _Done :: Prism' (Decoder e a) (ByteString, Int64, a)
- runGet :: Get e a -> ByteString -> RunGetResult e a
- runGetIncremental :: Get e a -> Decoder e a
- data XDecoder e a
- xdecoder :: (ByteString -> e -> x) -> ((Maybe ByteString -> XDecoder e a) -> x) -> (ByteString -> a -> x) -> (Int64 -> (Int64 -> XDecoder e a) -> x) -> XDecoder e a -> x
- _XFail :: Prism' (XDecoder e a) (ByteString, e)
- _XPartial :: Prism' (XDecoder e a) (Maybe ByteString -> XDecoder e a)
- _XDone :: Prism' (XDecoder e a) (ByteString, a)
- _XBytesRead :: Prism' (XDecoder e a) (Int64, Int64 -> XDecoder e a)
- data CompletedXDecoder e a
- completedXDecoder :: (ByteString -> e -> x) -> (ByteString -> a -> x) -> CompletedXDecoder e a -> x
- _CompletedFail :: Prism' (CompletedXDecoder e a) (ByteString, e)
- _CompletedDone :: Prism' (CompletedXDecoder e a) (ByteString, a)
- completedIso :: Iso (CompletedXDecoder e a) (CompletedXDecoder f b) (Either e a, ByteString) (Either f b, ByteString)
- completedByteString :: Lens' (CompletedXDecoder e a) ByteString
- completedValue :: Lens' (CompletedXDecoder e a) (Either e a)
- uncomplete :: Prism' (XDecoder e a) (CompletedXDecoder e a)
- uncompletedByteString :: Traversal' (XDecoder e a) ByteString
- uncompletedValue :: Traversal' (XDecoder e a) (Either e a)
Get data type
Bifunctor Get | Map on the error and result of a
|
Monad (Get e) | Sequence an action through the
runGet (return x :: Get () Int) (BLC.pack "abc") == _RunGet # x
|
Functor (Get e) | Map on the result of a
|
Applicative (Get e) | Apply a function on the
runGet (pure x :: Get () Int) (BLC.pack "abc") == _RunGet # x |
Alt (Get e) | Pick between two
|
Apply (Get e) | Apply a function on the
|
Bind (Get e) | Sequence an action through the
|
Semigroup (Get e a) | Pick between two
|
Primitive parsers
getLazyByteString :: Int64 -> Get () ByteString Source
>>>
runGet (getLazyByteString 5) (BLC.pack "")
RunGetFail 0 ()
>>>
runGet (getLazyByteString 5) (BLC.pack "abc")
RunGetFail 3 ()
>>>
runGet (getLazyByteString 5) (BLC.pack "abcdefg")
RunGet "abcde"
getLazyByteStringNul :: Get () ByteString Source
>>>
runGet getLazyByteStringNul (BLC.pack "")
RunGetFail 0 ()
>>>
runGet getLazyByteStringNul (BLC.pack "abc")
RunGetFail 3 ()
>>>
runGet getLazyByteStringNul (BLC.pack "abc\0")
RunGet "abc"
>>>
runGet getLazyByteStringNul (BLC.pack "abc\0def")
RunGet "abc"
getRemainingLazyByteString :: Get e ByteString Source
>>>
runGet getRemainingLazyByteString (BLC.pack "")
RunGet ""
>>>
runGet getRemainingLazyByteString (BLC.pack "abc")
RunGet "abc"
getWord8 :: Get () Word8 Source
>>>
runGet getWord8 (BLC.pack "abc")
RunGet 97
>>>
runGet getWord8 (BLC.pack "123")
RunGet 49
getWord16be :: Get () Word16 Source
>>>
runGet getWord16be (BLC.pack "abc")
RunGet 24930
>>>
runGet getWord16be (BLC.pack "123")
RunGet 12594
getWord16le :: Get () Word16 Source
>>>
runGet getWord16le (BLC.pack "abc")
RunGet 25185
>>>
runGet getWord16le (BLC.pack "123")
RunGet 12849
getWord32be :: Get () Word32 Source
>>>
runGet getWord32be (BLC.pack "abcdef")
RunGet 1633837924
>>>
runGet getWord32be (BLC.pack "123456")
RunGet 825373492
getWord32le :: Get () Word32 Source
- - >>> runGet getWord32le (BLC.pack "abcdef") RunGet 1684234849
>>>
runGet getWord32le (BLC.pack "123456")
RunGet 875770417
getWord64be :: Get () Word64 Source
>>>
runGet getWord64be (BLC.pack "abcdefghi")
RunGet 7017280452245743464
>>>
runGet getWord64be (BLC.pack "123456789")
RunGet 3544952156018063160
getWord64le :: Get () Word64 Source
>>>
runGet getWord64le (BLC.pack "abcdefghi")
RunGet 7523094288207667809
>>>
runGet getWord64le (BLC.pack "123456789")
RunGet 4050765991979987505
getWordhost :: Get () Word Source
>>>
runGet getWordhost (BLC.pack "abcdefghi")
RunGet 7523094288207667809
>>>
runGet getWordhost (BLC.pack "123456789")
RunGet 4050765991979987505
getWord16host :: Get () Word16 Source
>>>
runGet getWord16host (BLC.pack "abcde")
RunGet 25185
>>>
runGet getWord16host (BLC.pack "12345")
RunGet 12849
getWord32host :: Get () Word32 Source
>>>
runGet getWord32host (BLC.pack "abcde")
RunGet 1684234849
>>>
runGet getWord32host (BLC.pack "12345")
RunGet 875770417
getWord64host :: Get () Word64 Source
>>>
runGet getWord64host (BLC.pack "abcdeghi")
RunGet 7595434456733934177
>>>
runGet getWord64host (BLC.pack "123456789")
RunGet 4050765991979987505
failGet :: e -> Get e a Source
A Get
decoder that always fails with the given value.
runGet (failGet x :: Get Int ()) (BLC.pack s) == _RunGetFail # (0, x)
>>>
runGet (failGet "abc" :: Get String ()) (BLC.pack "def")
RunGetFail 0 "abc"
bytesRead :: Get e Int64 Source
>>>
runGet (bytesRead :: Get () Int64) (BLC.pack "")
RunGet 0
>>>
runGet (bytesRead :: Get () Int64) (BLC.pack "abc")
RunGet 0
>>>
runGet (getWord8 >> getWord16be >> getWord32le >> bytesRead) (BLC.pack "abcdefghijk")
RunGet 7
demandInput :: Get () () Source
>>>
runGet demandInput (BLC.pack "")
RunGetFail 0 ()
>>>
runGet demandInput (BLC.pack "a")
RunGet ()
>>>
runGet demandInput (BLC.pack "abc")
RunGet ()
skip :: Int -> Get () () Source
>>>
runGet (getWord8 >>= \c -> skip 2 >> getWord8 >>= \d -> return (c,d)) (BLC.pack "")
RunGetFail 0 ()
>>>
runGet (getWord8 >>= \c -> skip 2 >> getWord8 >>= \d -> return (c,d)) (BLC.pack "abcdefghi")
RunGet (97,100)
>>>
runGet (getWord8 >>= \c -> skip 2 >> getWord8 >>= \d -> return (c,d)) (BLC.pack "abc")
RunGetFail 3 ()
isNotEmpty :: Get e Bool Source
>>>
runGet isNotEmpty (BLC.pack "")
RunGet False
>>>
runGet isNotEmpty (BLC.pack "abc")
RunGet True
>>>
runGet (isNotEmpty >>= \p -> getWord8 >>= \w -> return (w, p)) (BLC.pack "abc")
RunGet (97,True)
>>>
runGet (isNotEmpty >>= \p -> getWord8 >>= \w -> return (w, p)) (BLC.pack "")
RunGetFail 0 ()
>>>
runGet (isNotEmpty >>= \p -> getWord8 >>= \w -> return (w, p)) (BLC.pack "a")
RunGet (97,True)
>>>
runGet isEmpty (BLC.pack "")
RunGet True
>>>
runGet isEmpty (BLC.pack "abc")
RunGet False
>>>
runGet (isEmpty >>= \p -> getWord8 >>= \w -> return (w, p)) (BLC.pack "abc")
RunGet (97,False)
>>>
runGet (isEmpty >>= \p -> getWord8 >>= \w -> return (w, p)) (BLC.pack "")
RunGetFail 0 ()
>>>
runGet (isEmpty >>= \p -> getWord8 >>= \w -> return (w, p)) (BLC.pack "a")
RunGet (97,False)
getByteString :: Int -> Get () ByteString Source
>>>
runGet (getByteString (-3)) (BLC.pack "")
RunGet ""
>>>
runGet (getByteString 3) (BLC.pack "")
RunGetFail 0 ()
>>>
runGet (getByteString 3) (BLC.pack "abc")
RunGet "abc"
>>>
runGet (getByteString 3) (BLC.pack "abcdef")
RunGet "abc"
modify :: (ByteString -> ByteString) -> Get e () Source
readN :: Int -> (ByteString -> a) -> Get () a Source
>>>
runGet (readN 3 id) (BLC.pack "abc")
RunGet "abc"
>>>
runGet (readN 3 id) (BLC.pack "ab")
RunGetFail 0 ()
>>>
runGet (readN 3 id) (BLC.pack "abcdef")
RunGet "abcdef"
>>>
runGet (readN (-3) id) (BLC.pack "abcdef")
RunGet ""
ensureN :: Int -> Get () () Source
>>>
runGet (ensureN 3) (BLC.pack "")
RunGetFail 0 ()
>>>
runGet (ensureN 3) (BLC.pack "abc")
RunGet ()
>>>
runGet (ensureN 3) (BLC.pack "abcdef")
RunGet ()
Higher-level combinators
runAndKeepTrack :: Get e a -> Get x (CompletedXDecoder e a, [ByteString]) Source
Run a Get
decoder, but keep a track of the input that ran it to completion.
>>>
runGet (runAndKeepTrack getWord8 :: Get () (CompletedXDecoder () Word8, [BC.ByteString])) (BLC.pack "")
RunGet (CompletedFail "" (),[])
>>>
runGet (runAndKeepTrack getWord8 :: Get () (CompletedXDecoder () Word8, [BC.ByteString])) (BLC.pack "abc")
RunGet (CompletedDone "bc" 97,["abc"])
pushBack :: [ByteString] -> Get e () Source
>>>
runGet (pushBack [] :: Get () ()) (BLC.pack "")
RunGet ()
>>>
runGet (pushBack [] :: Get () ()) (BLC.pack "abc")
RunGet ()
>>>
runGet (pushBack [BC.pack "def"] :: Get () ()) (BLC.pack "")
RunGet ()
>>>
runGet (pushBack [BC.pack "def"] :: Get () ()) (BLC.pack "abc")
RunGet ()
pushFront :: ByteString -> Get e () Source
>>>
runGet (pushFront (BC.pack "def") :: Get () ()) (BLC.pack "")
RunGet ()
>>>
runGet (pushFront (BC.pack "def") :: Get () ()) (BLC.pack "abc")
RunGet ()
xrunGetIncremental :: Get e a -> XDecoder e a Source
prompt :: ByteString -> XDecoder e a -> (ByteString -> XDecoder e a) -> XDecoder e a Source
isolate :: Int -> Get e a -> Get (IsolateError e) a Source
>>>
runGet (isolate 1 getWord8) (BLC.pack "ab")
RunGet 97
>>>
runGet (isolate 1 getWord8) (BLC.pack "abcde")
RunGet 97
>>>
runGet (isolate 2 getWord16le) (BLC.pack "abcde")
RunGet 25185
>>>
runGet (isolate 1 getWord16le) (BLC.pack "abcde")
RunGetFail 0 (IsolateXFail ())
>>>
runGet (isolate (-3) getWord16le) (BLC.pack "abcde")
RunGetFail 0 NegativeSize
>>>
runGet (isolate 3 getWord16le) (BLC.pack "abcde")
RunGetFail 2 (UnexpectedConsumed 2 3)
lookAhead :: Get e a -> Get e a Source
>>>
runGet (lookAhead getWord8) (BLC.pack "")
RunGetFail 0 ()
>>>
runGet (lookAhead getWord8) (BLC.pack "abc")
RunGet 97
>>>
runGet (lookAhead getWord8) (BLC.pack "a")
RunGet 97
lookAheadM :: Get e (Maybe a) -> Get e (Maybe a) Source
>>>
runGet (lookAheadM (getWord8 >>= \w -> return (if even w then Just (w + 5) else Nothing))) (BLC.pack "abc")
RunGet Nothing
>>>
runGet (lookAheadM (getWord8 >>= \w -> return (if even w then Just (w + 5) else Nothing))) (BLC.pack "bc")
RunGet (Just 103)
>>>
runGet (lookAheadM (getWord8 >>= \w -> return (if even w then Just (w + 5) else Nothing))) (BLC.pack "")
RunGetFail 0 ()
lookAheadE :: Get e (Either a b) -> Get e (Either a b) Source
>>>
runGet (lookAheadE (getWord8 >>= \w -> return (if even w then Left (w + 5) else Right (w - 4)))) (BLC.pack "abc")
RunGet (Right 93)
>>>
runGet (lookAheadE (getWord8 >>= \w -> return (if even w then Left (w + 5) else Right (w - 4)))) (BLC.pack "bc")
RunGet (Left 103)
>>>
runGet (lookAheadE (getWord8 >>= \w -> return (if even w then Left (w + 5) else Right (w - 4)))) (BLC.pack "")
RunGetFail 0 ()
calculateOffset :: XDecoder e a -> Decoder e a Source
pushChunk :: Decoder e a -> ByteString -> Decoder e a Source
pushChunks :: Decoder e a -> ByteString -> Decoder e a Source
pushEndOfInput :: Decoder e a -> Decoder e a Source
Error label
(!+) :: Semigroup e => e -> Get e a -> Get e a infixl 3 Source
>>>
runGet ([(), ()] !+ (setLabel [] getWord8)) (BLC.pack "")
RunGetFail 0 [(),()]
>>>
runGet ([(), ()] !+ (setLabel [] getWord8)) (BLC.pack "abc")
RunGet 97
addLabel :: Semigroup e => e -> Get e a -> Get e a Source
>>>
runGet ([(), ()] `addLabel` (setLabel [] getWord8)) (BLC.pack "")
RunGetFail 0 [(),()]
>>>
runGet ([(), ()] `addLabel` (setLabel [] getWord8)) (BLC.pack "abc")
RunGet 97
(!-) :: e -> Get d a -> Get e a infixl 3 Source
>>>
runGet ("error" !- getWord8) (BLC.pack "")
RunGetFail 0 "error"
>>>
runGet ("error" !- getWord8) (BLC.pack "abc")
RunGet 97
setLabel :: e -> Get d a -> Get e a Source
>>>
runGet ("error" `setLabel` getWord8) (BLC.pack "")
RunGetFail 0 "error"
>>>
runGet ("error" `setLabel` getWord8) (BLC.pack "abc")
RunGet 97
(!!-) :: (d -> e) -> Get d a -> Get e a infixl 3 Source
>>>
runGet (reverse !!- setLabel "error" getWord8) (BLC.pack "")
RunGetFail 0 "rorre"
>>>
runGet (reverse !!- setLabel "error" getWord8) (BLC.pack "abc")
RunGet 97
modifyLabel :: (d -> e) -> Get d a -> Get e a Source
>>>
runGet (reverse `modifyLabel` setLabel "error" getWord8) (BLC.pack "")
RunGetFail 0 "rorre"
>>>
runGet (reverse `modifyLabel` setLabel "error" getWord8) (BLC.pack "abc")
RunGet 97
Decoder
Bifunctor Decoder |
|
Functor (Decoder e) |
|
decoder :: (ByteString -> Int64 -> e -> x) -> ((Maybe ByteString -> Decoder e a) -> x) -> (ByteString -> Int64 -> a -> x) -> Decoder e a -> x Source
>>>
decoder (\b i n -> B.length b + fromIntegral i + n) (\_ -> 99) (\b n a -> B.length b + fromIntegral n + a) (_Fail # (BC.pack "abc", 12, 19))
34
>>>
decoder (\b i n -> B.length b + fromIntegral i + n) (\_ -> 99) (\b n a -> B.length b + fromIntegral n + a) (_Partial # (\b -> _Fail # (fromMaybe (BC.pack "abc") b, 12, 19)))
99
>>>
decoder (\b i n -> B.length b + fromIntegral i + n) (\_ -> 99) (\b n a -> B.length b + fromIntegral n + a) (_Done # (BC.pack "abc", 12, 19))
34
_Fail :: Prism' (Decoder e a) (ByteString, Int64, e) Source
>>>
(_Fail # (BC.pack "abc", 19, 31)) ^? _Fail
Just ("abc",19,31)
>>>
isNothing ((_Fail # (BC.pack "abc", 19, 31)) ^? _Partial)
True
>>>
(_Fail # (BC.pack "abc", 19, 31)) ^? _Done
Nothing
_Partial :: Prism' (Decoder e a) (Maybe ByteString -> Decoder e a) Source
>>>
(_Partial # (\b -> _Fail # (fromMaybe (BC.pack "abc") b, 12, 19))) ^? _Fail
Nothing
>>>
isJust ((_Partial # (\b -> _Fail # (fromMaybe (BC.pack "abc") b, 12, 19))) ^? _Partial)
True
>>>
(_Partial # (\b -> _Fail # (fromMaybe (BC.pack "abc") b, 12, 19))) ^? _Done
Nothing
_Done :: Prism' (Decoder e a) (ByteString, Int64, a) Source
>>>
(_Done # (BC.pack "abc", 19, 31)) ^? _Fail
Nothing
>>>
isNothing ((_Done # (BC.pack "abc", 19, 31)) ^? _Partial)
True
>>>
(_Done # (BC.pack "abc", 19, 31)) ^? _Done
Just ("abc",19,31)
Run Get parser
runGet :: Get e a -> ByteString -> RunGetResult e a Source
runGetIncremental :: Get e a -> Decoder e a Source
XDecoder data type
Reduction
xdecoder :: (ByteString -> e -> x) -> ((Maybe ByteString -> XDecoder e a) -> x) -> (ByteString -> a -> x) -> (Int64 -> (Int64 -> XDecoder e a) -> x) -> XDecoder e a -> x Source
Prisms
_XFail :: Prism' (XDecoder e a) (ByteString, e) Source
_XDone :: Prism' (XDecoder e a) (ByteString, a) Source
CompletedXDecoder data type
data CompletedXDecoder e a Source
Bitraversable CompletedXDecoder | |
Bifunctor CompletedXDecoder | |
Bifoldable CompletedXDecoder | |
Functor (CompletedXDecoder e) | |
Foldable (CompletedXDecoder e) | |
Traversable (CompletedXDecoder e) | |
(Eq e, Eq a) => Eq (CompletedXDecoder e a) | |
(Ord e, Ord a) => Ord (CompletedXDecoder e a) | |
(Show e, Show a) => Show (CompletedXDecoder e a) |
Reduction
completedXDecoder :: (ByteString -> e -> x) -> (ByteString -> a -> x) -> CompletedXDecoder e a -> x Source
Prism
_CompletedFail :: Prism' (CompletedXDecoder e a) (ByteString, e) Source
_CompletedDone :: Prism' (CompletedXDecoder e a) (ByteString, a) Source
Isomorphism
completedIso :: Iso (CompletedXDecoder e a) (CompletedXDecoder f b) (Either e a, ByteString) (Either f b, ByteString) Source
Lens
completedValue :: Lens' (CompletedXDecoder e a) (Either e a) Source
Prism
uncomplete :: Prism' (XDecoder e a) (CompletedXDecoder e a) Source
Traversal
uncompletedValue :: Traversal' (XDecoder e a) (Either e a) Source