Basement.Endianness

basement-0.0.12: Foundation scrap box of array & string

License | BSD-style
Maintainer | Haskell Foundation
Stability | experimental
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Basement.Endianness

Contents

- Big Endian
- Little Endian
- System Endianness

Description

Set endianness tag to a given primitive. This will help for serialising data for protocols (such as the network protocols).

Synopsis

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

# Documentation

class ByteSwap a #

Class of types that can be byte-swapped.

e.g. Word16, Word32, Word64

Minimal complete definition

byteSwap

#### Instances

Instances details

ByteSwap Word16 # |
Instance details Defined in Basement.Endianness Methods byteSwap :: Word16 -> Word16
ByteSwap Word32 # |
Instance details Defined in Basement.Endianness Methods byteSwap :: Word32 -> Word32
ByteSwap Word64 # |
Instance details Defined in Basement.Endianness Methods byteSwap :: Word64 -> Word64

# Big Endian

newtype BE a #

Big Endian value

Constructors

BE |
Fields unBE :: a

#### Instances

Instances details

Bits a => Bits (BE a) # |
Instance details Defined in Basement.Endianness Methods (.&.) :: BE a -> BE a -> BE a # (.|.) :: BE a -> BE a -> BE a # xor :: BE a -> BE a -> BE a # complement :: BE a -> BE a # shift :: BE a -> Int -> BE a # rotate :: BE a -> Int -> BE a # zeroBits :: BE a # bit :: Int -> BE a # setBit :: BE a -> Int -> BE a # clearBit :: BE a -> Int -> BE a # complementBit :: BE a -> Int -> BE a # testBit :: BE a -> Int -> Bool # bitSizeMaybe :: BE a -> Maybe Int # bitSize :: BE a -> Int # isSigned :: BE a -> Bool # shiftL :: BE a -> Int -> BE a # unsafeShiftL :: BE a -> Int -> BE a # shiftR :: BE a -> Int -> BE a # unsafeShiftR :: BE a -> Int -> BE a # rotateL :: BE a -> Int -> BE a # rotateR :: BE a -> Int -> BE a # popCount :: BE a -> Int #
Show a => Show (BE a) # |
Instance details Defined in Basement.Endianness Methods showsPrec :: Int -> BE a -> ShowS # show :: BE a -> String # showList :: [BE a] -> ShowS #
NormalForm a => NormalForm (BE a) # |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: BE a -> () #
PrimMemoryComparable a => PrimMemoryComparable (BE a) # |
Instance details Defined in Basement.PrimType
PrimType a => PrimType (BE a) # |
Instance details Defined in Basement.PrimType Associated Types type PrimSize (BE a) :: Nat # Methods primSizeInBytes :: Proxy (BE a) -> CountOf Word8 # primShiftToBytes :: Proxy (BE a) -> Int # primBaUIndex :: ByteArray# -> Offset (BE a) -> BE a # primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (BE a) -> prim (BE a) # primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (BE a) -> BE a -> prim () # primAddrIndex :: Addr# -> Offset (BE a) -> BE a # primAddrRead :: PrimMonad prim => Addr# -> Offset (BE a) -> prim (BE a) # primAddrWrite :: PrimMonad prim => Addr# -> Offset (BE a) -> BE a -> prim () #
Eq a => Eq (BE a) # |
Instance details Defined in Basement.Endianness Methods (==) :: BE a -> BE a -> Bool # (/=) :: BE a -> BE a -> Bool #
(ByteSwap a, Ord a) => Ord (BE a) # |
Instance details Defined in Basement.Endianness Methods compare :: BE a -> BE a -> Ordering # (<) :: BE a -> BE a -> Bool # (<=) :: BE a -> BE a -> Bool # (>) :: BE a -> BE a -> Bool # (>=) :: BE a -> BE a -> Bool # max :: BE a -> BE a -> BE a # min :: BE a -> BE a -> BE a #
type PrimSize (BE a) # |
Instance details Defined in Basement.PrimType type PrimSize (BE a) = PrimSize a

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

Convert a value in cpu endianess to big endian

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

Convert from a big endian value to the cpu endianness

# Little Endian

newtype LE a #

Little Endian value

Constructors

LE |
Fields unLE :: a

#### Instances

Instances details

Bits a => Bits (LE a) # |
Instance details Defined in Basement.Endianness Methods (.&.) :: LE a -> LE a -> LE a # (.|.) :: LE a -> LE a -> LE a # xor :: LE a -> LE a -> LE a # complement :: LE a -> LE a # shift :: LE a -> Int -> LE a # rotate :: LE a -> Int -> LE a # zeroBits :: LE a # bit :: Int -> LE a # setBit :: LE a -> Int -> LE a # clearBit :: LE a -> Int -> LE a # complementBit :: LE a -> Int -> LE a # testBit :: LE a -> Int -> Bool # bitSizeMaybe :: LE a -> Maybe Int # bitSize :: LE a -> Int # isSigned :: LE a -> Bool # shiftL :: LE a -> Int -> LE a # unsafeShiftL :: LE a -> Int -> LE a # shiftR :: LE a -> Int -> LE a # unsafeShiftR :: LE a -> Int -> LE a # rotateL :: LE a -> Int -> LE a # rotateR :: LE a -> Int -> LE a # popCount :: LE a -> Int #
Show a => Show (LE a) # |
Instance details Defined in Basement.Endianness Methods showsPrec :: Int -> LE a -> ShowS # show :: LE a -> String # showList :: [LE a] -> ShowS #
NormalForm a => NormalForm (LE a) # |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: LE a -> () #
PrimMemoryComparable a => PrimMemoryComparable (LE a) # |
Instance details Defined in Basement.PrimType
PrimType a => PrimType (LE a) # |
Instance details Defined in Basement.PrimType Associated Types type PrimSize (LE a) :: Nat # Methods primSizeInBytes :: Proxy (LE a) -> CountOf Word8 # primShiftToBytes :: Proxy (LE a) -> Int # primBaUIndex :: ByteArray# -> Offset (LE a) -> LE a # primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (LE a) -> prim (LE a) # primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (LE a) -> LE a -> prim () # primAddrIndex :: Addr# -> Offset (LE a) -> LE a # primAddrRead :: PrimMonad prim => Addr# -> Offset (LE a) -> prim (LE a) # primAddrWrite :: PrimMonad prim => Addr# -> Offset (LE a) -> LE a -> prim () #
Eq a => Eq (LE a) # |
Instance details Defined in Basement.Endianness Methods (==) :: LE a -> LE a -> Bool # (/=) :: LE a -> LE a -> Bool #
(ByteSwap a, Ord a) => Ord (LE a) # |
Instance details Defined in Basement.Endianness Methods compare :: LE a -> LE a -> Ordering # (<) :: LE a -> LE a -> Bool # (<=) :: LE a -> LE a -> Bool # (>) :: LE a -> LE a -> Bool # (>=) :: LE a -> LE a -> Bool # max :: LE a -> LE a -> LE a # min :: LE a -> LE a -> LE a #
type PrimSize (LE a) # |
Instance details Defined in Basement.PrimType type PrimSize (LE a) = PrimSize a

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

Convert a value in cpu endianess to little endian

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

Convert from a little endian value to the cpu endianness

# System Endianness

data Endianness #

Constructors

LittleEndian |
BigEndian |

#### Instances

Instances details

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

endianness :: Endianness #

endianness of the current architecture