megaparsec-9.3.1: Monadic parser combinators
Copyright© 2021–present Megaparsec contributors
LicenseFreeBSD
MaintainerMark Karpov <markkarpov92@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Text.Megaparsec.Byte.Binary

Description

Binary-format number parsers.

Since: 9.2.0

Synopsis

Generic parsers

class BinaryChunk chunk where Source #

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

Methods

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

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

Instances

Instances details
BinaryChunk ByteString Source # 
Instance details

Defined in Text.Megaparsec.Byte.Binary

Methods

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

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

BinaryChunk ByteString Source # 
Instance details

Defined in Text.Megaparsec.Byte.Binary

Methods

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

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

anyLE Source #

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

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

Parse a Word8.

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

Parse a little-endian Word16.

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

Parse a big-endian Word16.

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

Parse a little-endian Word32.

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

Parse a big-endian Word32.

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

Parse a little-endian Word64.

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

Parse a big-endian Word64.

Parsing signed values

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

Parse a Int8.

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

Parse a little-endian Int16.

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

Parse a big-endian Int16.

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

Parse a little-endian Int32.

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

Parse a big-endian Int32.

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

Parse a little-endian Int64.

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

Parse a big-endian Int64.