Data.Binary.Get.Internal

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

Safe Haskell | None
Language | Haskell98

Data.Binary.Get.Internal

Contents

- The Get type
- Parsing
- With input chunks
- Utility
  - ByteStrings

Synopsis

- data Get a
- runCont :: Get a -> forall r. ByteString -> Success a r -> Decoder r
- data Decoder a
  - = Fail !ByteString String
  - | Partial (Maybe ByteString -> Decoder a)
  - | Done !ByteString a
  - | BytesRead !Int64 (Int64 -> Decoder a)
- runGetIncremental :: Get a -> Decoder a
- readN :: Int -> (ByteString -> a) -> Get a
- readNWith :: Int -> (Ptr a -> IO a) -> Get a
- bytesRead :: Get Int64
- isolate :: Int -> Get a -> Get a
- withInputChunks :: s -> Consume s -> ([ByteString] -> b) -> ([ByteString] -> Get b) -> Get b
- type Consume s = s -> ByteString -> Either s (ByteString, ByteString)
- failOnEOF :: [ByteString] -> Get a
- get :: Get ByteString
- put :: ByteString -> Get ()
- ensureN :: Int -> Get ()
- remaining :: Get Int64
- getBytes :: Int -> Get ByteString
- isEmpty :: Get Bool
- lookAhead :: Get a -> Get a
- lookAheadM :: Get (Maybe a) -> Get (Maybe a)
- lookAheadE :: Get (Either a b) -> Get (Either a b)
- label :: String -> Get a -> Get a
- getByteString :: Int -> Get ByteString

# The Get type

data Get a #

Instances

Monad Get # |
Instance details Defined in Data.Binary.Get.Internal Methods (>>=) :: Get a -> (a -> Get b) -> Get b Source # (>>) :: Get a -> Get b -> Get b Source # return :: a -> Get a Source # fail :: String -> Get a Source #
Functor Get # |
Instance details Defined in Data.Binary.Get.Internal Methods fmap :: (a -> b) -> Get a -> Get b Source # (<$) :: a -> Get b -> Get a Source #
MonadFail Get # |
Instance details Defined in Data.Binary.Get.Internal Methods fail :: String -> Get a Source #
Applicative Get # |
Instance details Defined in Data.Binary.Get.Internal Methods pure :: a -> Get a Source # (<*>) :: Get (a -> b) -> Get a -> Get b Source # liftA2 :: (a -> b -> c) -> Get a -> Get b -> Get c Source # (*>) :: Get a -> Get b -> Get b Source # (<*) :: Get a -> Get b -> Get a Source #
Alternative Get # | Since: 0.7.0.0
Instance details Defined in Data.Binary.Get.Internal Methods empty :: Get a Source # (<|>) :: Get a -> Get a -> Get a Source # some :: Get a -> Get [a] Source # many :: Get a -> Get [a] Source #
MonadPlus Get # | Since: 0.7.1.0
Instance details Defined in Data.Binary.Get.Internal Methods mzero :: Get a Source # mplus :: Get a -> Get a -> Get a Source #

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

data Decoder a #

A decoder produced 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

Functor Decoder # |
Instance details Defined in Data.Binary.Get.Internal Methods fmap :: (a -> b) -> Decoder a -> Decoder b Source # (<$) :: a -> Decoder b -> Decoder a Source #
Show a => Show (Decoder a) # |
Instance details Defined in Data.Binary.Get.Internal Methods showsPrec :: Int -> Decoder a -> ShowS Source # show :: Decoder a -> String Source # showList :: [Decoder a] -> ShowS Source #

runGetIncremental :: Get a -> Decoder a #

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 a #

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 #

`readNWith n f` where `f` must be deterministic and not have side effects.

# Parsing

bytesRead :: Get Int64 #

Get the total number of bytes read to this point.

isolate #

Arguments

:: Int | The number of bytes that must be consumed
-> Get a | The decoder to isolate
-> Get a |

Isolate a decoder to operate with a fixed number of bytes, and fail if fewer bytes were consumed, or more bytes were attempted to be consumed. If the given decoder fails, `isolate` will also fail. Offset from `bytesRead` will be relative to the start of `isolate`, not the absolute of the input.

Since: 0.7.2.0

# With input chunks

withInputChunks :: s -> Consume s -> ([ByteString] -> b) -> ([ByteString] -> Get b) -> Get b #

type Consume s = s -> ByteString -> Either s (ByteString, ByteString) #

failOnEOF :: [ByteString] -> Get a #

get :: Get ByteString #

Get the current chunk.

put :: ByteString -> Get () #

Replace the current chunk.

ensureN :: Int -> Get () #

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

# Utility

remaining :: Get Int64 #

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 ByteString #

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

DEPRECATED. Same as `getByteString`.

isEmpty :: Get Bool #

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

lookAhead :: Get a -> Get a #

Run the given decoder, but without consuming its input. If the given decoder fails, then so will this function.

Since: 0.7.0.0

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

Run the given decoder, and only consume its input if it returns `Just`. If `Nothing` is returned, the input will be unconsumed. If the given decoder fails, then so will this function.

Since: 0.7.0.0

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

Run the given decoder, and only consume its input if it returns `Right`. If `Left` is returned, the input will be unconsumed. If the given decoder fails, then so will this function.

Since: 0.7.1.0

label :: String -> Get a -> Get a #

Label a decoder. If the decoder fails, the label will be appended on a new line to the error message string.

Since: 0.7.2.0

## ByteStrings

getByteString :: Int -> Get ByteString #

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.