Z-Data-0.8.3.0: Array, vector and text
Copyright(c) Dong Han 2017-2019
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.Data.Array.Unaligned

Description

This module implements unaligned element access with ghc primitives (> 8.6), which can be used as a simple binary encoding / decoding method.

Synopsis

Documentation

class Unaligned a where Source #

Primitive types which can be unaligned accessed

It can also be used as a lightweight method to peek/poke value from/to C structs when you pass MutableByteArray# to FFI as struct pointer, e.g.

 -- | note the .hsc syntax
 peekSocketAddrMBA :: HasCallStack => MBA## SocketAddr -> IO SocketAddr
 peekSocketAddrMBA p = do
     family <- peekMBA p (#offset struct sockaddr, sa_family)
     case family :: CSaFamily of
         (#const AF_INET) -> do
             addr <- peekMBA p (#offset struct sockaddr_in, sin_addr)
             port <- peekMBA p (#offset struct sockaddr_in, sin_port)
             return (SocketAddrInet (PortNumber port) addr)
         ....

Methods

unalignedSize :: UnalignedSize a Source #

byte size

indexWord8ArrayAs# :: ByteArray# -> Int# -> a Source #

index element off byte array with offset in bytes(maybe unaligned)

readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, a #) Source #

read element from byte array with offset in bytes(maybe unaligned)

writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> a -> State# s -> State# s Source #

write element to byte array with offset in bytes(maybe unaligned)

peekMBA :: MutableByteArray# RealWorld -> Int -> IO a Source #

IO version of writeWord8ArrayAs# but more convenient to write manually.

pokeMBA :: MutableByteArray# RealWorld -> Int -> a -> IO () Source #

IO version of readWord8ArrayAs# but more convenient to write manually.

indexBA :: ByteArray# -> Int -> a Source #

index element off byte array with offset in bytes(maybe unaligned)

Instances

Instances details
Unaligned Char Source #

Char's instance use 31bit wide char prim-op.

Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Double Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Float Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Int Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Int8 Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Int16 Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Int32 Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Int64 Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Word Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Word8 Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Word16 Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Word32 Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned Word64 Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CChar Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CSChar Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CUChar Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CShort Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CUShort Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CInt Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CUInt Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CLong Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CULong Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CLLong Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CULLong Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CBool Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CFloat Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CDouble Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CPtrdiff Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CSize Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CWchar Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CSigAtomic Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CClock Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CTime Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CUSeconds Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CSUSeconds Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CIntPtr Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CUIntPtr Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CIntMax Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned CUIntMax Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (Ptr a) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Char) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Double) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Float) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Int) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Int16) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Int32) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Int64) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Word) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Word16) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Word32) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Word64) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Char) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Double) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Float) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Int) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Int16) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Int32) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Int64) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Word) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Word16) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Word32) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Word64) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned a => Unaligned (RadixDown a) Source # 
Instance details

Defined in Z.Data.Vector.Sort

(Unaligned a, Unaligned b) => Unaligned (a, b) Source #

Write a, b in order

Instance details

Defined in Z.Data.Array.Unaligned

(Unaligned a, Unaligned b, Unaligned c) => Unaligned (a, b, c) Source #

Write a, b, c in order

Instance details

Defined in Z.Data.Array.Unaligned

Methods

unalignedSize :: UnalignedSize (a, b, c) Source #

indexWord8ArrayAs# :: ByteArray# -> Int# -> (a, b, c) Source #

readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b, c) #) Source #

writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> (a, b, c) -> State# s -> State# s Source #

peekMBA :: MutableByteArray# RealWorld -> Int -> IO (a, b, c) Source #

pokeMBA :: MutableByteArray# RealWorld -> Int -> (a, b, c) -> IO () Source #

indexBA :: ByteArray# -> Int -> (a, b, c) Source #

(Unaligned a, Unaligned b, Unaligned c, Unaligned d) => Unaligned (a, b, c, d) Source #

Write a, b, c, d in order

Instance details

Defined in Z.Data.Array.Unaligned

Methods

unalignedSize :: UnalignedSize (a, b, c, d) Source #

indexWord8ArrayAs# :: ByteArray# -> Int# -> (a, b, c, d) Source #

readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b, c, d) #) Source #

writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> (a, b, c, d) -> State# s -> State# s Source #

peekMBA :: MutableByteArray# RealWorld -> Int -> IO (a, b, c, d) Source #

pokeMBA :: MutableByteArray# RealWorld -> Int -> (a, b, c, d) -> IO () Source #

indexBA :: ByteArray# -> Int -> (a, b, c, d) Source #

(Unaligned a, Unaligned b, Unaligned c, Unaligned d, Unaligned e) => Unaligned (a, b, c, d, e) Source #

Write a, b, c, d, e in order

Instance details

Defined in Z.Data.Array.Unaligned

Methods

unalignedSize :: UnalignedSize (a, b, c, d, e) Source #

indexWord8ArrayAs# :: ByteArray# -> Int# -> (a, b, c, d, e) Source #

readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b, c, d, e) #) Source #

writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> (a, b, c, d, e) -> State# s -> State# s Source #

peekMBA :: MutableByteArray# RealWorld -> Int -> IO (a, b, c, d, e) Source #

pokeMBA :: MutableByteArray# RealWorld -> Int -> (a, b, c, d, e) -> IO () Source #

indexBA :: ByteArray# -> Int -> (a, b, c, d, e) Source #

(Unaligned a, Unaligned b, Unaligned c, Unaligned d, Unaligned e, Unaligned f) => Unaligned (a, b, c, d, e, f) Source #

Write a, b, c, d, e, f in order

Instance details

Defined in Z.Data.Array.Unaligned

Methods

unalignedSize :: UnalignedSize (a, b, c, d, e, f) Source #

indexWord8ArrayAs# :: ByteArray# -> Int# -> (a, b, c, d, e, f) Source #

readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b, c, d, e, f) #) Source #

writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> (a, b, c, d, e, f) -> State# s -> State# s Source #

peekMBA :: MutableByteArray# RealWorld -> Int -> IO (a, b, c, d, e, f) Source #

pokeMBA :: MutableByteArray# RealWorld -> Int -> (a, b, c, d, e, f) -> IO () Source #

indexBA :: ByteArray# -> Int -> (a, b, c, d, e, f) Source #

(Unaligned a, Unaligned b, Unaligned c, Unaligned d, Unaligned e, Unaligned f, Unaligned g) => Unaligned (a, b, c, d, e, f, g) Source #

Write a, b, c, d, e, f, g in order

Instance details

Defined in Z.Data.Array.Unaligned

Methods

unalignedSize :: UnalignedSize (a, b, c, d, e, f, g) Source #

indexWord8ArrayAs# :: ByteArray# -> Int# -> (a, b, c, d, e, f, g) Source #

readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b, c, d, e, f, g) #) Source #

writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> (a, b, c, d, e, f, g) -> State# s -> State# s Source #

peekMBA :: MutableByteArray# RealWorld -> Int -> IO (a, b, c, d, e, f, g) Source #

pokeMBA :: MutableByteArray# RealWorld -> Int -> (a, b, c, d, e, f, g) -> IO () Source #

indexBA :: ByteArray# -> Int -> (a, b, c, d, e, f, g) Source #

(Unaligned a, Unaligned b, Unaligned c, Unaligned d, Unaligned e, Unaligned f, Unaligned g, Unaligned h) => Unaligned (a, b, c, d, e, f, g, h) Source #

Write a, b, c, d, e, f, g, h in order

Instance details

Defined in Z.Data.Array.Unaligned

Methods

unalignedSize :: UnalignedSize (a, b, c, d, e, f, g, h) Source #

indexWord8ArrayAs# :: ByteArray# -> Int# -> (a, b, c, d, e, f, g, h) Source #

readWord8ArrayAs# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b, c, d, e, f, g, h) #) Source #

writeWord8ArrayAs# :: MutableByteArray# s -> Int# -> (a, b, c, d, e, f, g, h) -> State# s -> State# s Source #

peekMBA :: MutableByteArray# RealWorld -> Int -> IO (a, b, c, d, e, f, g, h) Source #

pokeMBA :: MutableByteArray# RealWorld -> Int -> (a, b, c, d, e, f, g, h) -> IO () Source #

indexBA :: ByteArray# -> Int -> (a, b, c, d, e, f, g, h) Source #

primArrayToBE :: forall a. (Prim a, Unaligned (BE a)) => PrimArray a -> Int -> Int -> PrimArray Word8 Source #

Encode PrimArray elements in big endian.

primArrayFromBE :: forall a. (Prim a, Unaligned (BE a)) => PrimArray Word8 -> Int -> Int -> PrimArray a Source #

Decode PrimArray elements in big endian.

newtype LE a Source #

little endianess wrapper

Constructors

LE 

Fields

Instances

Instances details
Eq a => Eq (LE a) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Methods

(==) :: LE a -> LE a -> Bool #

(/=) :: LE a -> LE a -> Bool #

Show a => Show (LE a) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Methods

showsPrec :: Int -> LE a -> ShowS #

show :: LE a -> String #

showList :: [LE a] -> ShowS #

Unaligned (LE Char) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Double) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Float) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Int) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Int16) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Int32) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Int64) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Word) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Word16) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Word32) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (LE Word64) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

newtype BE a Source #

big endianess wrapper

Constructors

BE 

Fields

Instances

Instances details
Eq a => Eq (BE a) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Methods

(==) :: BE a -> BE a -> Bool #

(/=) :: BE a -> BE a -> Bool #

Show a => Show (BE a) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Methods

showsPrec :: Int -> BE a -> ShowS #

show :: BE a -> String #

showList :: [BE a] -> ShowS #

Unaligned (BE Char) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Double) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Float) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Int) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Int16) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Int32) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Int64) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Word) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Word16) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Word32) Source # 
Instance details

Defined in Z.Data.Array.Unaligned

Unaligned (BE Word64) Source # 
Instance details

Defined in Z.Data.Array.Unaligned