{-# LINE 1 "src/Codec/Lz4/Foreign.chs" #-}
module Codec.Lz4.Foreign (
lZ4VersionNumber
, lZ4VersionString
, lZ4CompressDefault
, lZ4DecompressSafe
, lZ4CompressBound
, lZ4FIsError
, lZ4FGetErrorName
, lZ4FGetVersion
, lZ4FCreateCompressionContext
, lZ4FFreeCompressionContext
, lZ4FFreeDecompressionContext
, lZ4FHeaderSizeMax
, lZ4FCompressBegin
, lZ4FCompressBound
, lZ4FCompressUpdate
, lZ4FCompressEnd
, lZ4FCreateDecompressionContext
, lZ4FDecompress
, lZ4MaxInputSize
, lZ4CompressHC
, lZ4HCClevelMax
, LZ4FErrorCode
, LzCtx
, LzCtxPtr
, LzDecompressionCtx
, LzDecompressionCtxPtr
, LzPreferencesPtr
, BlockMode (Lz4fBlocklinked)
, BlockSize (Lz4fDefault)
, ContentChecksum (Lz4fNocontentchecksum)
, BlockChecksum (Lz4fNoblockchecksum)
, FrameType (Lz4fFrame)
) where
import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp
import Data.Coerce (coerce)
import Foreign.C.String (CString)
import Foreign.C.Types (CInt, CUInt, CSize (..))
import Foreign.Marshal.Alloc (alloca)
import Foreign.Ptr (castPtr, Ptr)
import Foreign.Storable (peek)
data BlockSize = Lz4fDefault
| Lz4fMax64kb
| Lz4fMax256kb
| Lz4fMax1mb
| Lz4fMax4mb
instance Enum BlockSize where
succ Lz4fDefault = Lz4fMax64kb
succ Lz4fMax64kb = Lz4fMax256kb
succ Lz4fMax256kb = Lz4fMax1mb
succ Lz4fMax1mb = Lz4fMax4mb
succ Lz4fMax4mb = error "BlockSize.succ: Lz4fMax4mb has no successor"
pred Lz4fMax64kb = Lz4fDefault
pred Lz4fMax256kb = Lz4fMax64kb
pred Lz4fMax1mb = Lz4fMax256kb
pred Lz4fMax4mb = Lz4fMax1mb
pred Lz4fDefault = error "BlockSize.pred: Lz4fDefault has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Lz4fMax4mb
fromEnum Lz4fDefault = 0
fromEnum Lz4fMax64kb = 4
fromEnum Lz4fMax256kb = 5
fromEnum Lz4fMax1mb = 6
fromEnum Lz4fMax4mb = 7
toEnum 0 = Lz4fDefault
toEnum 4 = Lz4fMax64kb
toEnum 5 = Lz4fMax256kb
toEnum 6 = Lz4fMax1mb
toEnum 7 = Lz4fMax4mb
toEnum unmatched = error ("BlockSize.toEnum: Cannot match " ++ show unmatched)
{-# LINE 50 "src/Codec/Lz4/Foreign.chs" #-}
data BlockMode = Lz4fBlocklinked
| Lz4fBlockindependent
instance Enum BlockMode where
succ Lz4fBlocklinked = Lz4fBlockindependent
succ Lz4fBlockindependent = error "BlockMode.succ: Lz4fBlockindependent has no successor"
pred Lz4fBlockindependent = Lz4fBlocklinked
pred Lz4fBlocklinked = error "BlockMode.pred: Lz4fBlocklinked has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Lz4fBlockindependent
fromEnum Lz4fBlocklinked = 0
fromEnum Lz4fBlockindependent = 1
toEnum 0 = Lz4fBlocklinked
toEnum 1 = Lz4fBlockindependent
toEnum unmatched = error ("BlockMode.toEnum: Cannot match " ++ show unmatched)
{-# LINE 51 "src/Codec/Lz4/Foreign.chs" #-}
data ContentChecksum = Lz4fNocontentchecksum
| Lz4fContentchecksumenabled
instance Enum ContentChecksum where
succ Lz4fNocontentchecksum = Lz4fContentchecksumenabled
succ Lz4fContentchecksumenabled = error "ContentChecksum.succ: Lz4fContentchecksumenabled has no successor"
pred Lz4fContentchecksumenabled = Lz4fNocontentchecksum
pred Lz4fNocontentchecksum = error "ContentChecksum.pred: Lz4fNocontentchecksum has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Lz4fContentchecksumenabled
fromEnum Lz4fNocontentchecksum = 0
fromEnum Lz4fContentchecksumenabled = 1
toEnum 0 = Lz4fNocontentchecksum
toEnum 1 = Lz4fContentchecksumenabled
toEnum unmatched = error ("ContentChecksum.toEnum: Cannot match " ++ show unmatched)
{-# LINE 52 "src/Codec/Lz4/Foreign.chs" #-}
data BlockChecksum = Lz4fNoblockchecksum
| Lz4fBlockchecksumenabled
instance Enum BlockChecksum where
succ Lz4fNoblockchecksum = Lz4fBlockchecksumenabled
succ Lz4fBlockchecksumenabled = error "BlockChecksum.succ: Lz4fBlockchecksumenabled has no successor"
pred Lz4fBlockchecksumenabled = Lz4fNoblockchecksum
pred Lz4fNoblockchecksum = error "BlockChecksum.pred: Lz4fNoblockchecksum has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Lz4fBlockchecksumenabled
fromEnum Lz4fNoblockchecksum = 0
fromEnum Lz4fBlockchecksumenabled = 1
toEnum 0 = Lz4fNoblockchecksum
toEnum 1 = Lz4fBlockchecksumenabled
toEnum unmatched = error ("BlockChecksum.toEnum: Cannot match " ++ show unmatched)
{-# LINE 53 "src/Codec/Lz4/Foreign.chs" #-}
data FrameType = Lz4fFrame
| Lz4fSkippableframe
instance Enum FrameType where
succ Lz4fFrame = Lz4fSkippableframe
succ Lz4fSkippableframe = error "FrameType.succ: Lz4fSkippableframe has no successor"
pred Lz4fSkippableframe = Lz4fFrame
pred Lz4fFrame = error "FrameType.pred: Lz4fFrame has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from Lz4fSkippableframe
fromEnum Lz4fFrame = 0
fromEnum Lz4fSkippableframe = 1
toEnum 0 = Lz4fFrame
toEnum 1 = Lz4fSkippableframe
toEnum unmatched = error ("FrameType.toEnum: Cannot match " ++ show unmatched)
{-# LINE 54 "src/Codec/Lz4/Foreign.chs" #-}
lZ4VersionNumber :: (CInt)
lZ4VersionNumber =
C2HSImp.unsafePerformIO $
lZ4VersionNumber'_ >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 56 "src/Codec/Lz4/Foreign.chs" #-}
lZ4VersionString :: (String)
lZ4VersionString =
C2HSImp.unsafePerformIO $
lZ4VersionString'_ >>= \res ->
C2HSImp.peekCString res >>= \res' ->
return (res')
{-# LINE 58 "src/Codec/Lz4/Foreign.chs" #-}
lZ4CompressDefault :: (CString) -> (CString) -> (CInt) -> (CInt) -> IO ((CInt))
lZ4CompressDefault a1 a2 a3 a4 =
(flip ($)) a1 $ \a1' ->
(flip ($)) a2 $ \a2' ->
let {a3' = fromIntegral a3} in
let {a4' = fromIntegral a4} in
lZ4CompressDefault'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 60 "src/Codec/Lz4/Foreign.chs" #-}
lZ4DecompressSafe :: (CString) -> (CString) -> (CInt) -> (CInt) -> IO ((CInt))
lZ4DecompressSafe a1 a2 a3 a4 =
(flip ($)) a1 $ \a1' ->
(flip ($)) a2 $ \a2' ->
let {a3' = fromIntegral a3} in
let {a4' = fromIntegral a4} in
lZ4DecompressSafe'_ a1' a2' a3' a4' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 61 "src/Codec/Lz4/Foreign.chs" #-}
lZ4CompressBound :: (CInt) -> (CInt)
lZ4CompressBound a1 =
C2HSImp.unsafePerformIO $
let {a1' = fromIntegral a1} in
lZ4CompressBound'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 63 "src/Codec/Lz4/Foreign.chs" #-}
type LZ4FErrorCode = CSize
{-# LINE 66 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FIsError :: (LZ4FErrorCode) -> (Bool)
lZ4FIsError a1 =
C2HSImp.unsafePerformIO $
let {a1' = id a1} in
lZ4FIsError'_ a1' >>= \res ->
let {res' = C2HSImp.toBool res} in
return (res')
{-# LINE 68 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FGetErrorName :: (LZ4FErrorCode) -> (String)
lZ4FGetErrorName a1 =
C2HSImp.unsafePerformIO $
let {a1' = id a1} in
lZ4FGetErrorName'_ a1' >>= \res ->
C2HSImp.peekCString res >>= \res' ->
return (res')
{-# LINE 69 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FGetVersion :: (CUInt)
lZ4FGetVersion =
C2HSImp.unsafePerformIO $
lZ4FGetVersion'_ >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 71 "src/Codec/Lz4/Foreign.chs" #-}
data LzCtx
type LzCtxPtr = C2HSImp.ForeignPtr (LzCtx)
{-# LINE 75 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FCreateCompressionContext :: (CUInt) -> IO ((LZ4FErrorCode), (Ptr LzCtx))
lZ4FCreateCompressionContext a2 =
alloca $ \a1' ->
let {a2' = fromIntegral a2} in
lZ4FCreateCompressionContext'_ a1' a2' >>= \res ->
let {res' = id res} in
peek a1'>>= \a1'' ->
return (res', a1'')
{-# LINE 77 "src/Codec/Lz4/Foreign.chs" #-}
data LzPreferences
type LzPreferencesPtr = C2HSImp.ForeignPtr (LzPreferences)
{-# LINE 81 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FHeaderSizeMax :: Integral a => a
lZ4FHeaderSizeMax = 19
{-# LINE 84 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FCompressBegin :: (LzCtxPtr) -> (Ptr a) -> (CSize) -> (LzPreferencesPtr) -> IO ((CSize))
lZ4FCompressBegin a1 a2 a3 a4 =
C2HSImp.withForeignPtr a1 $ \a1' ->
let {a2' = castPtr a2} in
let {a3' = coerce a3} in
C2HSImp.withForeignPtr a4 $ \a4' ->
lZ4FCompressBegin'_ a1' a2' a3' a4' >>= \res ->
let {res' = coerce res} in
return (res')
{-# LINE 86 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FCompressBound :: (CSize) -> (LzPreferencesPtr) -> (CSize)
lZ4FCompressBound a1 a2 =
C2HSImp.unsafePerformIO $
let {a1' = coerce a1} in
C2HSImp.withForeignPtr a2 $ \a2' ->
lZ4FCompressBound'_ a1' a2' >>= \res ->
let {res' = coerce res} in
return (res')
{-# LINE 88 "src/Codec/Lz4/Foreign.chs" #-}
data LzCompressOptions
type LzCompressOptionsPtr = C2HSImp.Ptr (LzCompressOptions)
{-# LINE 92 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FCompressUpdate :: (LzCtxPtr) -> (Ptr a) -> (CSize) -> (Ptr b) -> (CSize) -> (LzCompressOptionsPtr) -> IO ((CSize))
lZ4FCompressUpdate a1 a2 a3 a4 a5 a6 =
C2HSImp.withForeignPtr a1 $ \a1' ->
let {a2' = castPtr a2} in
let {a3' = coerce a3} in
let {a4' = castPtr a4} in
let {a5' = coerce a5} in
let {a6' = id a6} in
lZ4FCompressUpdate'_ a1' a2' a3' a4' a5' a6' >>= \res ->
let {res' = coerce res} in
return (res')
{-# LINE 102 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FCompressEnd :: (LzCtxPtr) -> (Ptr a) -> (CSize) -> (LzCompressOptionsPtr) -> IO ((CSize))
lZ4FCompressEnd a1 a2 a3 a4 =
C2HSImp.withForeignPtr a1 $ \a1' ->
let {a2' = castPtr a2} in
let {a3' = coerce a3} in
let {a4' = id a4} in
lZ4FCompressEnd'_ a1' a2' a3' a4' >>= \res ->
let {res' = coerce res} in
return (res')
{-# LINE 105 "src/Codec/Lz4/Foreign.chs" #-}
data LzDecompressionCtx
type LzDecompressionCtxPtr = C2HSImp.ForeignPtr (LzDecompressionCtx)
{-# LINE 109 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FCreateDecompressionContext :: (CUInt) -> IO ((LZ4FErrorCode), (Ptr LzDecompressionCtx))
lZ4FCreateDecompressionContext a2 =
alloca $ \a1' ->
let {a2' = fromIntegral a2} in
lZ4FCreateDecompressionContext'_ a1' a2' >>= \res ->
let {res' = id res} in
peek a1'>>= \a1'' ->
return (res', a1'')
{-# LINE 111 "src/Codec/Lz4/Foreign.chs" #-}
data LzDecompressOptions
type LzDecompressOptionsPtr = C2HSImp.Ptr (LzDecompressOptions)
{-# LINE 115 "src/Codec/Lz4/Foreign.chs" #-}
lZ4FDecompress :: (LzDecompressionCtxPtr) -> (Ptr a) -> (Ptr CSize) -> (Ptr b) -> (Ptr CSize) -> (LzDecompressOptionsPtr) -> IO ((CSize))
lZ4FDecompress a1 a2 a3 a4 a5 a6 =
C2HSImp.withForeignPtr a1 $ \a1' ->
let {a2' = castPtr a2} in
let {a3' = castPtr a3} in
let {a4' = castPtr a4} in
let {a5' = castPtr a5} in
let {a6' = id a6} in
lZ4FDecompress'_ a1' a2' a3' a4' a5' a6' >>= \res ->
let {res' = coerce res} in
return (res')
{-# LINE 125 "src/Codec/Lz4/Foreign.chs" #-}
lZ4MaxInputSize :: Integral a => a
lZ4MaxInputSize = 0x7e000000
{-# LINE 129 "src/Codec/Lz4/Foreign.chs" #-}
lZ4CompressHC :: (CString) -> (CString) -> (CInt) -> (CInt) -> (CInt) -> IO ((CInt))
lZ4CompressHC :: CString -> CString -> CInt -> CInt -> CInt -> IO CInt
lZ4CompressHC CString
a1 CString
a2 CInt
a3 CInt
a4 CInt
a5 =
(((CString -> IO CInt) -> CString -> IO CInt)
-> CString -> (CString -> IO CInt) -> IO CInt
forall a b c. (a -> b -> c) -> b -> a -> c
flip (CString -> IO CInt) -> CString -> IO CInt
forall a b. (a -> b) -> a -> b
($)) CString
a1 ((CString -> IO CInt) -> IO CInt)
-> (CString -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \CString
a1' ->
(((CString -> IO CInt) -> CString -> IO CInt)
-> CString -> (CString -> IO CInt) -> IO CInt
forall a b c. (a -> b -> c) -> b -> a -> c
flip (CString -> IO CInt) -> CString -> IO CInt
forall a b. (a -> b) -> a -> b
($)) CString
a2 ((CString -> IO CInt) -> IO CInt)
-> (CString -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \CString
a2' ->
let {a3' :: CInt
a3' = CInt -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
a3} in
let {a4' :: CInt
a4' = CInt -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
a4} in
let {a5' :: CInt
a5' = CInt -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
a5} in
CString -> CString -> CInt -> CInt -> CInt -> IO CInt
lZ4CompressHC'_ CString
a1' CString
a2' CInt
a3' CInt
a4' CInt
a5' IO CInt -> (CInt -> IO CInt) -> IO CInt
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
let {res' :: CInt
res' = CInt -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
res} in
CInt -> IO CInt
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
res')
{-# LINE 132 "src/Codec/Lz4/Foreign.chs" #-}
lZ4HCClevelMax :: Integral a => a
lZ4HCClevelMax = 12
{-# LINE 136 "src/Codec/Lz4/Foreign.chs" #-}
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4_versionNumber"
lZ4VersionNumber'_ :: (IO C2HSImp.CInt)
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4_versionString"
lZ4VersionString'_ :: (IO (C2HSImp.Ptr C2HSImp.CChar))
foreign import ccall unsafe "Codec/Lz4/Foreign.chs.h LZ4_compress_default"
lZ4CompressDefault'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))
foreign import ccall unsafe "Codec/Lz4/Foreign.chs.h LZ4_decompress_safe"
lZ4DecompressSafe'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4_compressBound"
lZ4CompressBound'_ :: (C2HSImp.CInt -> (IO C2HSImp.CInt))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_isError"
lZ4FIsError'_ :: (LZ4FErrorCode -> (IO C2HSImp.CUInt))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_getErrorName"
lZ4FGetErrorName'_ :: (LZ4FErrorCode -> (IO (C2HSImp.Ptr C2HSImp.CChar)))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_getVersion"
lZ4FGetVersion'_ :: (IO C2HSImp.CUInt)
foreign import ccall "Codec/Lz4/Foreign.chs.h &LZ4F_freeCompressionContext"
lZ4FFreeCompressionContext :: C2HSImp.FinalizerPtr ()
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_createCompressionContext"
lZ4FCreateCompressionContext'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr (LzCtx))) -> (C2HSImp.CUInt -> (IO LZ4FErrorCode)))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_compressBegin"
lZ4FCompressBegin'_ :: ((C2HSImp.Ptr (LzCtx)) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((C2HSImp.Ptr (LzPreferences)) -> (IO C2HSImp.CULong)))))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_compressBound"
lZ4FCompressBound'_ :: (C2HSImp.CULong -> ((C2HSImp.Ptr (LzPreferences)) -> (IO C2HSImp.CULong)))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_compressUpdate"
lZ4FCompressUpdate'_ :: ((C2HSImp.Ptr (LzCtx)) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((LzCompressOptionsPtr) -> (IO C2HSImp.CULong)))))))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_compressEnd"
lZ4FCompressEnd'_ :: ((C2HSImp.Ptr (LzCtx)) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((LzCompressOptionsPtr) -> (IO C2HSImp.CULong)))))
foreign import ccall "Codec/Lz4/Foreign.chs.h &LZ4F_freeDecompressionContext"
lZ4FFreeDecompressionContext :: C2HSImp.FinalizerPtr ()
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_createDecompressionContext"
lZ4FCreateDecompressionContext'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr (LzDecompressionCtx))) -> (C2HSImp.CUInt -> (IO LZ4FErrorCode)))
foreign import ccall safe "Codec/Lz4/Foreign.chs.h LZ4F_decompress"
lZ4FDecompress'_ :: ((C2HSImp.Ptr (LzDecompressionCtx)) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CULong) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CULong) -> ((LzDecompressOptionsPtr) -> (IO C2HSImp.CULong)))))))
foreign import ccall unsafe "Codec/Lz4/Foreign.chs.h LZ4_compress_HC"
lZ4CompressHC'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))