memory-0.13: 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 #

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

Eq Endianness # |
Methods (==) :: Endianness -> Endianness -> Bool # (/=) :: Endianness -> Endianness -> Bool #
Show Endianness # |
Methods showsPrec :: Int -> Endianness -> ShowS # show :: Endianness -> String # showList :: [Endianness] -> ShowS #

getSystemEndianness :: Endianness #

Return the system endianness

newtype BE a #

Big Endian value

Constructors

BE |
Fields unBE :: a

Instances

Eq a => Eq (BE a) # |
Methods (==) :: BE a -> BE a -> Bool # (/=) :: BE a -> BE a -> Bool #
Show a => Show (BE a) # |
Methods showsPrec :: Int -> BE a -> ShowS # show :: BE a -> String # showList :: [BE a] -> ShowS #
Storable a => Storable (BE a) # |
Methods sizeOf :: BE a -> Int # alignment :: BE a -> Int # peekElemOff :: Ptr (BE a) -> Int -> IO (BE a) # pokeElemOff :: Ptr (BE a) -> Int -> BE a -> IO () # peekByteOff :: Ptr b -> Int -> IO (BE a) # pokeByteOff :: Ptr b -> Int -> BE a -> IO () # peek :: Ptr (BE a) -> IO (BE a) # poke :: Ptr (BE a) -> BE a -> IO () #

newtype LE a #

Little Endian value

Constructors

LE |
Fields unLE :: a

Instances

Eq a => Eq (LE a) # |
Methods (==) :: LE a -> LE a -> Bool # (/=) :: LE a -> LE a -> Bool #
Show a => Show (LE a) # |
Methods showsPrec :: Int -> LE a -> ShowS # show :: LE a -> String # showList :: [LE a] -> ShowS #
Storable a => Storable (LE a) # |
Methods sizeOf :: LE a -> Int # alignment :: LE a -> Int # peekElemOff :: Ptr (LE a) -> Int -> IO (LE a) # pokeElemOff :: Ptr (LE a) -> Int -> LE a -> IO () # peekByteOff :: Ptr b -> Int -> IO (LE a) # pokeByteOff :: Ptr b -> Int -> LE a -> IO () # peek :: Ptr (LE a) -> IO (LE a) # poke :: Ptr (LE a) -> LE a -> IO () #

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

Convert from a big endian value to the cpu endianness

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

Convert a value in cpu endianess to big endian

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

Convert from a little endian value to the cpu endianness

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

Convert a value in cpu endianess to little endian

class Storable a => ByteSwap a #

Class of types that can be byte-swapped.

e.g. Word16, Word32, Word64

Minimal complete definition

byteSwap

Instances

ByteSwap Word16 # |
Methods byteSwap :: Word16 -> Word16
ByteSwap Word32 # |
Methods byteSwap :: Word32 -> Word32
ByteSwap Word64 # |
Methods byteSwap :: Word64 -> Word64