Z-Data-0.1.7.2: 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 :: a -> Int 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
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 CBytes Source #

This instance peek bytes until \NUL(or input chunk ends), poke bytes with an extra \NUL terminator.

Instance details

Defined in Z.Data.CBytes

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

newtype LE a Source #

little endianess wrapper

Constructors

LE 

Fields

Instances
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
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