memory-0.18.0: memory and related abstraction stuff

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | stable
Portability | good
Safe Haskell | None
Language | Haskell2010

Data.Memory.Endian

Description

Synopsis

- data Endianness
  - = LittleEndian
  - | BigEndian
- getSystemEndianness :: Endianness
- newtype BE a = BE {
  - unBE :: a
  }
- newtype LE a = LE {
  - unLE :: a
  }
- fromBE :: ByteSwap a => BE a -> a
- toBE :: ByteSwap a => a -> BE a
- fromLE :: ByteSwap a => LE a -> a
- toLE :: ByteSwap a => a -> LE a
- class Storable a => ByteSwap a

# Documentation

data Endianness Source #

represent the CPU endianness

Big endian system stores bytes with the MSB as the first byte. Little endian system stores bytes with the LSB as the first byte.

middle endian is purposely avoided.

Constructors

LittleEndian |
BigEndian |

#### Instances

Instances details

Show Endianness Source # |
Instance details Defined in Data.Memory.Endian Methods showsPrec :: Int -> Endianness -> ShowS Source # show :: Endianness -> String Source # showList :: [Endianness] -> ShowS Source #
Eq Endianness Source # |
Instance details Defined in Data.Memory.Endian Methods (==) :: Endianness -> Endianness -> Bool Source # (/=) :: Endianness -> Endianness -> Bool Source #

getSystemEndianness :: Endianness Source #

Return the system endianness

newtype BE a Source #

Big Endian value

Constructors

BE |

Fields

- unBE :: a

#### Instances

Instances details

Storable a => Storable (BE a) Source # |

Instance details

Defined in Data.Memory.Endian

Methods

sizeOf :: BE a -> Int Source #

alignment :: BE a -> Int Source #

peekElemOff :: Ptr (BE a) -> Int -> IO (BE a) Source #

pokeElemOff :: Ptr (BE a) -> Int -> BE a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (BE a) Source #

pokeByteOff :: Ptr b -> Int -> BE a -> IO () Source #

peek :: Ptr (BE a) -> IO (BE a) Source #

poke :: Ptr (BE a) -> BE a -> IO () Source #

Show a => Show (BE a) Source # |
Instance details Defined in Data.Memory.Endian Methods showsPrec :: Int -> BE a -> ShowS Source # show :: BE a -> String Source # showList :: [BE a] -> ShowS Source #
Eq a => Eq (BE a) Source # |
Instance details Defined in Data.Memory.Endian Methods (==) :: BE a -> BE a -> Bool Source # (/=) :: BE a -> BE a -> Bool Source #

newtype LE a Source #

Little Endian value

Constructors

LE |

Fields

- unLE :: a

#### Instances

Instances details

Storable a => Storable (LE a) Source # |

Instance details

Defined in Data.Memory.Endian

Methods

sizeOf :: LE a -> Int Source #

alignment :: LE a -> Int Source #

peekElemOff :: Ptr (LE a) -> Int -> IO (LE a) Source #

pokeElemOff :: Ptr (LE a) -> Int -> LE a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (LE a) Source #

pokeByteOff :: Ptr b -> Int -> LE a -> IO () Source #

peek :: Ptr (LE a) -> IO (LE a) Source #

poke :: Ptr (LE a) -> LE a -> IO () Source #

Show a => Show (LE a) Source # |
Instance details Defined in Data.Memory.Endian Methods showsPrec :: Int -> LE a -> ShowS Source # show :: LE a -> String Source # showList :: [LE a] -> ShowS Source #
Eq a => Eq (LE a) Source # |
Instance details Defined in Data.Memory.Endian Methods (==) :: LE a -> LE a -> Bool Source # (/=) :: LE a -> LE a -> Bool Source #

fromBE :: ByteSwap a => BE a -> a Source #

Convert from a big endian value to the cpu endianness

toBE :: ByteSwap a => a -> BE a Source #

Convert a value in cpu endianess to big endian

fromLE :: ByteSwap a => LE a -> a Source #

Convert from a little endian value to the cpu endianness

toLE :: ByteSwap a => a -> LE a Source #

Convert a value in cpu endianess to little endian

class Storable a => ByteSwap a Source #

Class of types that can be byte-swapped.

e.g. Word16, Word32, Word64

Minimal complete definition

byteSwap

#### Instances

Instances details

ByteSwap Word16 Source # |
Instance details Defined in Data.Memory.Endian Methods byteSwap :: Word16 -> Word16
ByteSwap Word32 Source # |
Instance details Defined in Data.Memory.Endian Methods byteSwap :: Word32 -> Word32
ByteSwap Word64 Source # |
Instance details Defined in Data.Memory.Endian Methods byteSwap :: Word64 -> Word64