Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Get e a
- runCont :: Get e a -> forall r. Int64 -> ByteString -> Success e a r -> Decoder e r
- data Decoder e a
- = Fail !ByteString (Either String e)
- | Partial (Maybe ByteString -> Decoder e a)
- | Done !ByteString a
- | BytesRead !Int64 (Int64 -> Decoder e a)
- runGetIncremental :: Int64 -> Get e a -> Decoder e a
- readN :: Int -> (ByteString -> a) -> Get () a
- readNWith :: Int -> (Ptr a -> IO a) -> Get () a
- bytesRead :: Get e Int64
- totalBytesRead :: Get e Int64
- isolate :: Int -> Get e a -> (Int -> e) -> Get e a
- withInputChunks :: s -> Consume s -> ([ByteString] -> b) -> ([ByteString] -> Get e b) -> Get e b
- type Consume s = s -> ByteString -> Either s (ByteString, ByteString)
- failOnEOF :: [ByteString] -> Get () a
- get :: Get e ByteString
- put :: ByteString -> Get e ()
- ensureN :: Int -> Get () ()
- isEmpty :: Get e Bool
- failG :: e -> Get 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)
- label :: String -> Get String a -> Get String a
- onError :: (e -> e') -> Get e a -> Get e' a
- withError :: Get () a -> e -> Get e a
- getByteString :: Int -> Get () ByteString
The Get e type
A decoder produced by running a Get
monad.
Fail !ByteString (Either String e) | The decoder ran into an error. The decoder either used
|
Partial (Maybe ByteString -> Decoder e a) | The decoder has consumed the available input and needs
more to continue. Provide |
Done !ByteString a | The decoder has successfully finished. Except for the output value you also get the unused input. |
BytesRead !Int64 (Int64 -> Decoder e 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. |
readN :: Int -> (ByteString -> a) -> Get () a Source #
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 () a Source #
readNWith n f
where f
must be deterministic and not have side effects.
Parsing
totalBytesRead :: Get e Int64 Source #
Get e the total number of bytes read to this point.
With input chunks
withInputChunks :: s -> Consume s -> ([ByteString] -> b) -> ([ByteString] -> Get e b) -> Get e b Source #
type Consume s = s -> ByteString -> Either s (ByteString, ByteString) Source #
failOnEOF :: [ByteString] -> Get () a Source #
get :: Get e ByteString Source #
Get e the current chunk.
put :: ByteString -> Get e () Source #
Replace the current chunk.
ensureN :: Int -> Get () () Source #
Ensure that there are at least n
bytes available. If not, the
computation will escape with Partial
.
Utility
isEmpty :: Get e Bool Source #
Test whether all input has been consumed, i.e. there are no remaining undecoded bytes.
lookAhead :: Get e a -> Get e a Source #
Run the given decoder, but without consuming its input. If the given decoder fails, then so will this function.
Since: 0.7.0.0
onError :: (e -> e') -> Get e a -> Get e' a Source #
Convert decoder error. If the decoder fails, the given function will be applied to the error message.
withError :: Get () a -> e -> Get e a Source #
Set decoder error. If the decoder fails, the given error will be used as the error message.
ByteStrings
getByteString :: Int -> Get () ByteString Source #
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.