flatparse-0.5.1.0: High-performance parsing from strict bytestrings
Safe HaskellSafe-Inferred
LanguageHaskell2010

FlatParse.Basic.Integers

Description

Machine integer parsers.

Synopsis

Native byte order

anyWord8 :: ParserT st e Word8 Source #

Parse any Word8.

anyWord16 :: ParserT st e Word16 Source #

Parse any Word16 (native byte order).

anyWord32 :: ParserT st e Word32 Source #

Parse any Word32 (native byte order).

anyWord64 :: ParserT st e Word64 Source #

Parse any Word64 (native byte order).

anyInt8 :: ParserT st e Int8 Source #

Parse any Int8.

anyInt16 :: ParserT st e Int16 Source #

Parse any Int16 (native byte order).

anyInt32 :: ParserT st e Int32 Source #

Parse any Int32 (native byte order).

anyInt64 :: ParserT st e Int64 Source #

Parse any Int64 (native byte order).

anyWord :: ParserT st e Word Source #

Parse any Word (native size).

anyInt :: ParserT st e Int Source #

Parse any Int (native size).

Explicit endianness

Native endianness parsers are used where possible. For non-native endianness parsers, we parse then use the corresponding byteSwapX function. On x86, this is inlined as a single BSWAP instruction.

anyWord16le :: ParserT st e Word16 Source #

Parse any Word16 (little-endian).

anyWord16be :: ParserT st e Word16 Source #

Parse any Word16 (big-endian).

anyWord32le :: ParserT st e Word32 Source #

Parse any Word32 (little-endian).

anyWord32be :: ParserT st e Word32 Source #

Parse any Word32 (big-endian).

anyWord64le :: ParserT st e Word64 Source #

Parse any Word64 (little-endian).

anyWord64be :: ParserT st e Word64 Source #

Parse any Word64 (big-endian).

anyInt16le :: ParserT st e Int16 Source #

Parse any Int16 (little-endian).

anyInt16be :: ParserT st e Int16 Source #

Parse any Int16 (big-endian).

anyInt32le :: ParserT st e Int32 Source #

Parse any Int32 (little-endian).

anyInt32be :: ParserT st e Int32 Source #

Parse any Int32 (big-endian).

anyInt64le :: ParserT st e Int64 Source #

Parse any Int64 (little-endian).

anyInt64be :: ParserT st e Int64 Source #

Parse any Int64 (big-endian).

Value assertions

word8 :: Word8 -> ParserT st e () Source #

Read the next 1 byte and assert its value as a Word8.

CPS parsers

withAnyWord8 :: (Word8 -> ParserT st e r) -> ParserT st e r Source #

Parse any Word8 (CPS).

withAnyWord16 :: (Word16 -> ParserT st e r) -> ParserT st e r Source #

Parse any Word16 (native byte order) (CPS).

withAnyWord32 :: (Word32 -> ParserT st e r) -> ParserT st e r Source #

Parse any Word32 (native byte order) (CPS).

withAnyWord64 :: (Word64 -> ParserT st e r) -> ParserT st e r Source #

Parse any Word64 (native byte order) (CPS).

withAnyInt8 :: (Int8 -> ParserT st e r) -> ParserT st e r Source #

Parse any Int8 (CPS).

withAnyInt16 :: (Int16 -> ParserT st e r) -> ParserT st e r Source #

Parse any Int16 (native byte order) (CPS).

withAnyInt32 :: (Int32 -> ParserT st e r) -> ParserT st e r Source #

Parse any Int32 (native byte order) (CPS).

withAnyInt64 :: (Int64 -> ParserT st e r) -> ParserT st e r Source #

Parse any Int64 (native byte order) (CPS).

withAnyWord :: (Word -> ParserT st e r) -> ParserT st e r Source #

Parse any Word (native size) (CPS).

withAnyInt :: (Int -> ParserT st e r) -> ParserT st e r Source #

Parse any Int (native size) (CPS).

Unsafe

These unsafe parsers and helpers may be useful for efficient parsing in special situations e.g. you already know that the input has enough bytes. You should only use them if you can assert their necessary guarantees (see the individual function documentation).

anyWord8Unsafe :: ParserT st e Word8 Source #

Unsafely parse any Word8, without asserting the input is non-empty.

The caller must guarantee that the input has enough bytes.

Value assertions

word8Unsafe :: Word8 -> ParserT st e () Source #

Unsafely read the next 1 byte and assert its value as a Word8.

The caller must guarantee that the input has enough bytes.

word16Unsafe :: Word16 -> ParserT st e () Source #

Unsafely read the next 2 bytes and assert their value as a Word16 (native byte order).

The caller must guarantee that the input has enough bytes.

word32Unsafe :: Word32 -> ParserT st e () Source #

Unsafely read the next 4 bytes and assert their value as a Word32. (native byte order).

The caller must guarantee that the input has enough bytes.

word64Unsafe :: Word64 -> ParserT st e () Source #

Unsafely read the next 8 bytes and assert their value as a Word64. (native byte order).

The caller must guarantee that the input has enough bytes.

Helper definitions

withAnySized# :: Int# -> (Addr# -> Int# -> a) -> (a -> ParserT st e r) -> ParserT st e r Source #

Helper for defining CPS parsers for types of a constant byte size (i.e. machine integers).

Call this with an indexXYZOffAddr primop (e.g. indexWord8OffAddr) and the size in bytes of the type you're parsing.

withAnySizedUnsafe# :: Int# -> (Addr# -> Int# -> a) -> (a -> ParserT st e r) -> ParserT st e r Source #

Unsafe helper for defining CPS parsers for types of a constant byte size (i.e. machine integers).

Is really just syntactic sugar for applying the given parser and shifting the buffer along.

The caller must guarantee that the input has enough bytes.

sizedUnsafe# :: Eq a => Int# -> (Addr# -> Int# -> a) -> a -> ParserT st e () Source #

Unsafe helper for defining parsers for types of a constant byte size (i.e. machine integers) which assert the parsed value's... value.

Call this with an indexXYZOffAddr primop (e.g. indexWord8OffAddr), the size in bytes of the type you're parsing, and the expected value to test the parsed value against.

The caller must guarantee that the input has enough bytes.