basement-0.0.16: 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 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 Basement.Endianness Methods byteSwap :: Word16 -> Word16
ByteSwap Word32 Source # |
Instance details Defined in Basement.Endianness Methods byteSwap :: Word32 -> Word32
ByteSwap Word64 Source # |
Instance details Defined in Basement.Endianness Methods byteSwap :: Word64 -> Word64

# Big Endian

newtype BE a Source #

Big Endian value

Constructors

BE |

Fields

- unBE :: a

#### Instances

Instances details

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

Instance details

Defined in Basement.Endianness

Methods

(.&.) :: BE a -> BE a -> BE a Source #

(.|.) :: BE a -> BE a -> BE a Source #

xor :: BE a -> BE a -> BE a Source #

complement :: BE a -> BE a Source #

shift :: BE a -> Int -> BE a Source #

rotate :: BE a -> Int -> BE a Source #

zeroBits :: BE a Source #

bit :: Int -> BE a Source #

setBit :: BE a -> Int -> BE a Source #

clearBit :: BE a -> Int -> BE a Source #

complementBit :: BE a -> Int -> BE a Source #

testBit :: BE a -> Int -> Bool Source #

bitSizeMaybe :: BE a -> Maybe Int Source #

bitSize :: BE a -> Int Source #

isSigned :: BE a -> Bool Source #

shiftL :: BE a -> Int -> BE a Source #

unsafeShiftL :: BE a -> Int -> BE a Source #

shiftR :: BE a -> Int -> BE a Source #

unsafeShiftR :: BE a -> Int -> BE a Source #

rotateL :: BE a -> Int -> BE a Source #

rotateR :: BE a -> Int -> BE a Source #

popCount :: BE a -> Int Source #

Show a => Show (BE a) Source # |
Instance details Defined in Basement.Endianness Methods showsPrec :: Int -> BE a -> ShowS Source # show :: BE a -> String Source # showList :: [BE a] -> ShowS Source #
NormalForm a => NormalForm (BE a) Source # |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: BE a -> () Source #
PrimMemoryComparable a => PrimMemoryComparable (BE a) Source # |
Instance details Defined in Basement.PrimType
PrimType a => PrimType (BE a) Source # |

Instance details

Defined in Basement.PrimType

Associated Types

type PrimSize (BE a) :: Nat Source #

Methods

primSizeInBytes :: Proxy (BE a) -> CountOf Word8 Source #

primShiftToBytes :: Proxy (BE a) -> Int Source #

primBaUIndex :: ByteArray# -> Offset (BE a) -> BE a Source #

primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (BE a) -> prim (BE a) Source #

primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (BE a) -> BE a -> prim () Source #

primAddrIndex :: Addr# -> Offset (BE a) -> BE a Source #

primAddrRead :: PrimMonad prim => Addr# -> Offset (BE a) -> prim (BE a) Source #

primAddrWrite :: PrimMonad prim => Addr# -> Offset (BE a) -> BE a -> prim () Source #

Eq a => Eq (BE a) Source # |
Instance details Defined in Basement.Endianness Methods (==) :: BE a -> BE a -> Bool Source # (/=) :: BE a -> BE a -> Bool Source #
(ByteSwap a, Ord a) => Ord (BE a) Source # |
Instance details Defined in Basement.Endianness Methods compare :: BE a -> BE a -> Ordering Source # (<) :: BE a -> BE a -> Bool Source # (<=) :: BE a -> BE a -> Bool Source # (>) :: BE a -> BE a -> Bool Source # (>=) :: BE a -> BE a -> Bool Source # max :: BE a -> BE a -> BE a Source # min :: BE a -> BE a -> BE a Source #
type PrimSize (BE a) Source # |
Instance details Defined in Basement.PrimType type PrimSize (BE a) = PrimSize a

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

Convert a value in cpu endianess to big endian

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

Convert from a big endian value to the cpu endianness

# Little Endian

newtype LE a Source #

Little Endian value

Constructors

LE |

Fields

- unLE :: a

#### Instances

Instances details

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

Instance details

Defined in Basement.Endianness

Methods

(.&.) :: LE a -> LE a -> LE a Source #

(.|.) :: LE a -> LE a -> LE a Source #

xor :: LE a -> LE a -> LE a Source #

complement :: LE a -> LE a Source #

shift :: LE a -> Int -> LE a Source #

rotate :: LE a -> Int -> LE a Source #

zeroBits :: LE a Source #

bit :: Int -> LE a Source #

setBit :: LE a -> Int -> LE a Source #

clearBit :: LE a -> Int -> LE a Source #

complementBit :: LE a -> Int -> LE a Source #

testBit :: LE a -> Int -> Bool Source #

bitSizeMaybe :: LE a -> Maybe Int Source #

bitSize :: LE a -> Int Source #

isSigned :: LE a -> Bool Source #

shiftL :: LE a -> Int -> LE a Source #

unsafeShiftL :: LE a -> Int -> LE a Source #

shiftR :: LE a -> Int -> LE a Source #

unsafeShiftR :: LE a -> Int -> LE a Source #

rotateL :: LE a -> Int -> LE a Source #

rotateR :: LE a -> Int -> LE a Source #

popCount :: LE a -> Int Source #

Show a => Show (LE a) Source # |
Instance details Defined in Basement.Endianness Methods showsPrec :: Int -> LE a -> ShowS Source # show :: LE a -> String Source # showList :: [LE a] -> ShowS Source #
NormalForm a => NormalForm (LE a) Source # |
Instance details Defined in Basement.NormalForm Methods toNormalForm :: LE a -> () Source #
PrimMemoryComparable a => PrimMemoryComparable (LE a) Source # |
Instance details Defined in Basement.PrimType
PrimType a => PrimType (LE a) Source # |

Instance details

Defined in Basement.PrimType

Associated Types

type PrimSize (LE a) :: Nat Source #

Methods

primSizeInBytes :: Proxy (LE a) -> CountOf Word8 Source #

primShiftToBytes :: Proxy (LE a) -> Int Source #

primBaUIndex :: ByteArray# -> Offset (LE a) -> LE a Source #

primMbaURead :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (LE a) -> prim (LE a) Source #

primMbaUWrite :: PrimMonad prim => MutableByteArray# (PrimState prim) -> Offset (LE a) -> LE a -> prim () Source #

primAddrIndex :: Addr# -> Offset (LE a) -> LE a Source #

primAddrRead :: PrimMonad prim => Addr# -> Offset (LE a) -> prim (LE a) Source #

primAddrWrite :: PrimMonad prim => Addr# -> Offset (LE a) -> LE a -> prim () Source #

Eq a => Eq (LE a) Source # |
Instance details Defined in Basement.Endianness Methods (==) :: LE a -> LE a -> Bool Source # (/=) :: LE a -> LE a -> Bool Source #
(ByteSwap a, Ord a) => Ord (LE a) Source # |
Instance details Defined in Basement.Endianness Methods compare :: LE a -> LE a -> Ordering Source # (<) :: LE a -> LE a -> Bool Source # (<=) :: LE a -> LE a -> Bool Source # (>) :: LE a -> LE a -> Bool Source # (>=) :: LE a -> LE a -> Bool Source # max :: LE a -> LE a -> LE a Source # min :: LE a -> LE a -> LE a Source #
type PrimSize (LE a) Source # |
Instance details Defined in Basement.PrimType type PrimSize (LE a) = PrimSize a

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

Convert a value in cpu endianess to little endian

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

Convert from a little endian value to the cpu endianness

# System Endianness

data Endianness Source #

Constructors

LittleEndian |
BigEndian |

#### Instances

Instances details

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

endianness :: Endianness Source #

endianness of the current architecture