megaparsec-9.7.0: Monadic parser combinators

Copyright | © 2021–present Megaparsec contributors
License | FreeBSD
Maintainer | Mark Karpov <markkarpov92@gmail.com>
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Text.Megaparsec.Byte.Binary

Contents

- Generic parsers
- Parsing unsigned values
- Parsing signed values

Description

Binary-format number parsers.

Since: 9.2.0

Synopsis

- class BinaryChunk chunk where
  - convertChunkBE :: (Bits a, Num a) => chunk -> a
  - convertChunkLE :: (Bits a, Num a) => chunk -> a
- anyLE :: forall a e s m. (MonadParsec e s m, FiniteBits a, Num a, BinaryChunk (Tokens s)) => Maybe String -> m a
- anyBE :: forall a e s m. (MonadParsec e s m, FiniteBits a, Num a, BinaryChunk (Tokens s)) => Maybe String -> m a
- word8 :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word8
- word16le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word16
- word16be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word16
- word32le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word32
- word32be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word32
- word64le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word64
- word64be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word64
- int8 :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int8
- int16le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int16
- int16be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int16
- int32le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int32
- int32be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int32
- int64le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int64
- int64be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int64

# Generic parsers

class BinaryChunk chunk where #

Data types that can be converted to little- or big- endian numbers.

Methods

convertChunkBE :: (Bits a, Num a) => chunk -> a #

convertChunkLE :: (Bits a, Num a) => chunk -> a #

#### Instances

Instances details

BinaryChunk ByteString # |
Instance details Defined in Text.Megaparsec.Byte.Binary Methods convertChunkBE :: (Bits a, Num a) => ByteString -> a # convertChunkLE :: (Bits a, Num a) => ByteString -> a #
BinaryChunk ByteString # |
Instance details Defined in Text.Megaparsec.Byte.Binary Methods convertChunkBE :: (Bits a, Num a) => ByteString -> a # convertChunkLE :: (Bits a, Num a) => ByteString -> a #

anyLE #

Arguments

:: forall a e s m. (MonadParsec e s m, FiniteBits a, Num a, BinaryChunk (Tokens s)) |
=> Maybe String | Label, if any
-> m a |

Parse a little-endian number.

You may wish to call this with a visible type application:

    number <- anyLE (Just "little-endian 32 bit word") @Word32

anyBE #

Arguments

:: forall a e s m. (MonadParsec e s m, FiniteBits a, Num a, BinaryChunk (Tokens s)) |
=> Maybe String | Label, if any
-> m a |

Parse a big-endian number.

You may wish to call this with a visible type application:

    number <- anyBE (Just "big-endian 32 bit word") @Word32

# Parsing unsigned values

word8 :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word8 #

Parse a `Word8`.

word16le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word16 #

Parse a little-endian `Word16`.

word16be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word16 #

Parse a big-endian `Word16`.

word32le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word32 #

Parse a little-endian `Word32`.

word32be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word32 #

Parse a big-endian `Word32`.

word64le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word64 #

Parse a little-endian `Word64`.

word64be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Word64 #

Parse a big-endian `Word64`.

# Parsing signed values

int8 :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int8 #

Parse a `Int8`.

int16le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int16 #

Parse a little-endian `Int16`.

int16be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int16 #

Parse a big-endian `Int16`.

int32le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int32 #

Parse a little-endian `Int32`.

int32be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int32 #

Parse a big-endian `Int32`.

int64le :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int64 #

Parse a little-endian `Int64`.

int64be :: (MonadParsec e s m, BinaryChunk (Tokens s)) => m Int64 #

Parse a big-endian `Int64`.