-- GENERATED by C->Haskell Compiler, version 0.28.7 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/FoundationDB/Internal/Bindings.chs" #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE CPP #-}

-- NOTE: to check the code generated by c2hs, run
-- c2hs --cppopts='-Iinclude/' --cppopts='-DFDB_API_VERSION=630' src/FoundationDB/Internal/Bindings.chs

-- | Raw bindings to the underlying C client API. These are not memory safe.
-- For documentation, see <https://apple.github.io/foundationdb/api-c.html>.
module FoundationDB.Internal.Bindings (
  -- * API versioning
  currentAPIVersion
  , selectAPIVersion
  -- * Network
  , setupNetwork
  , runNetwork
  , stopNetwork
  , networkSetOption
  -- * Future
  , Future (..)
  , futureCancel
  , futureDestroy
  , futureDestroyPtr
  , futureBlockUntilReady
  , futureIsReady
  , futureReleaseMemory
  , futureGetError
  , futureGetInt64
  , futureGetKey
  , futureGetValue
  , futureGetStringArray
  , FDBKeyValue (..)
  , futureGetKeyValueArray
  -- * Database
  , DatabasePtr
  , createDatabase
  , databaseDestroy
  , databaseSetOption
  , databaseCreateTransaction
  -- * Transaction
  , Transaction (..)
  , KeySelector (..)
  , keySelectorBytes
  , keySelectorTuple
  , tupleKeySelector
  , transactionDestroy
  , transactionDestroyPtr
  , transactionSetOption
  , transactionSetReadVersion
  , transactionGetReadVersion
  , transactionGet
  , transactionGetKey
  , transactionGetAddressesForKey
  , transactionGetRange
  , FDBStreamingMode (..)
  , transactionSet
  , transactionClear
  , transactionClearRange
  , transactionAtomicOp
  , transactionCommit
  , transactionGetCommittedVersion
  , transactionGetApproximateSize
  , transactionGetVersionstamp
  , transactionWatch
  , transactionOnError
  , transactionReset
  , transactionCancel
  , transactionAddConflictRange
  , FDBConflictRangeType (..)
  -- * Error
  , CFDBError (..)
  , isError
  , getError
  , errorPredicate
  , FDBErrorPredicate (..)
  , MappedKeyValue(..)
  , getMappedRangeResult
  , transactionGetMappedRange
) where
import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp



import FoundationDB.Options.DatabaseOption (DatabaseOption(..))
import FoundationDB.Options.MutationType
import FoundationDB.Options.NetworkOption (NetworkOption(..))
import FoundationDB.Options.TransactionOption (TransactionOption(..))

import qualified Data.ByteString.Char8 as B
import Data.Int (Int64)

import Foreign.C.String
import Foreign.C.Types
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Array (peekArray)
import Foreign.Ptr
import Foreign.Storable



{-# LINE 113 "src/FoundationDB/Internal/Bindings.chs" #-}


newtype CFDBError = CFDBError {CFDBError -> CInt
getCFDBError :: CInt}
  deriving (Int -> CFDBError -> ShowS
[CFDBError] -> ShowS
CFDBError -> String
(Int -> CFDBError -> ShowS)
-> (CFDBError -> String)
-> ([CFDBError] -> ShowS)
-> Show CFDBError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CFDBError] -> ShowS
$cshowList :: [CFDBError] -> ShowS
show :: CFDBError -> String
$cshow :: CFDBError -> String
showsPrec :: Int -> CFDBError -> ShowS
$cshowsPrec :: Int -> CFDBError -> ShowS
Show, CFDBError -> CFDBError -> Bool
(CFDBError -> CFDBError -> Bool)
-> (CFDBError -> CFDBError -> Bool) -> Eq CFDBError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CFDBError -> CFDBError -> Bool
$c/= :: CFDBError -> CFDBError -> Bool
== :: CFDBError -> CFDBError -> Bool
$c== :: CFDBError -> CFDBError -> Bool
Eq, Eq CFDBError
Eq CFDBError
-> (CFDBError -> CFDBError -> Ordering)
-> (CFDBError -> CFDBError -> Bool)
-> (CFDBError -> CFDBError -> Bool)
-> (CFDBError -> CFDBError -> Bool)
-> (CFDBError -> CFDBError -> Bool)
-> (CFDBError -> CFDBError -> CFDBError)
-> (CFDBError -> CFDBError -> CFDBError)
-> Ord CFDBError
CFDBError -> CFDBError -> Bool
CFDBError -> CFDBError -> Ordering
CFDBError -> CFDBError -> CFDBError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CFDBError -> CFDBError -> CFDBError
$cmin :: CFDBError -> CFDBError -> CFDBError
max :: CFDBError -> CFDBError -> CFDBError
$cmax :: CFDBError -> CFDBError -> CFDBError
>= :: CFDBError -> CFDBError -> Bool
$c>= :: CFDBError -> CFDBError -> Bool
> :: CFDBError -> CFDBError -> Bool
$c> :: CFDBError -> CFDBError -> Bool
<= :: CFDBError -> CFDBError -> Bool
$c<= :: CFDBError -> CFDBError -> Bool
< :: CFDBError -> CFDBError -> Bool
$c< :: CFDBError -> CFDBError -> Bool
compare :: CFDBError -> CFDBError -> Ordering
$ccompare :: CFDBError -> CFDBError -> Ordering
$cp1Ord :: Eq CFDBError
Ord, Integer -> CFDBError
CFDBError -> CFDBError
CFDBError -> CFDBError -> CFDBError
(CFDBError -> CFDBError -> CFDBError)
-> (CFDBError -> CFDBError -> CFDBError)
-> (CFDBError -> CFDBError -> CFDBError)
-> (CFDBError -> CFDBError)
-> (CFDBError -> CFDBError)
-> (CFDBError -> CFDBError)
-> (Integer -> CFDBError)
-> Num CFDBError
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> CFDBError
$cfromInteger :: Integer -> CFDBError
signum :: CFDBError -> CFDBError
$csignum :: CFDBError -> CFDBError
abs :: CFDBError -> CFDBError
$cabs :: CFDBError -> CFDBError
negate :: CFDBError -> CFDBError
$cnegate :: CFDBError -> CFDBError
* :: CFDBError -> CFDBError -> CFDBError
$c* :: CFDBError -> CFDBError -> CFDBError
- :: CFDBError -> CFDBError -> CFDBError
$c- :: CFDBError -> CFDBError -> CFDBError
+ :: CFDBError -> CFDBError -> CFDBError
$c+ :: CFDBError -> CFDBError -> CFDBError
Num)

-- | Return 'True' iff 'CFDBError' value is an error (non-zero).
isError :: CFDBError -> Bool
isError :: CFDBError -> Bool
isError = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/=CInt
0) (CInt -> Bool) -> (CFDBError -> CInt) -> CFDBError -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CFDBError -> CInt
getCFDBError

-- | Current version of the installed FDB library. For example, returns
-- 630 if you are using FoundationDB client 6.3.x.
currentAPIVersion :: Int
currentAPIVersion :: Int
currentAPIVersion = Int
710
{-# LINE 125 "src/FoundationDB/Internal/Bindings.chs" #-}


selectAPIVersion :: (Int) -> IO ((CFDBError))
selectAPIVersion :: Int -> IO CFDBError
selectAPIVersion Int
a1 =
  let {a1' :: CInt
a1' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a1} in 
  CInt -> IO CInt
selectAPIVersion'_ CInt
a1' IO CInt -> (CInt -> IO CFDBError) -> IO CFDBError
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: CFDBError
res' = CInt -> CFDBError
CFDBError CInt
res} in
  CFDBError -> IO CFDBError
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError
res')

{-# LINE 128 "src/FoundationDB/Internal/Bindings.chs" #-}


setupNetwork :: IO ((CFDBError))
setupNetwork =
  setupNetwork'_ >>= \res ->
  let {res' = CFDBError res} in
  return (res')

{-# LINE 130 "src/FoundationDB/Internal/Bindings.chs" #-}


runNetwork :: IO ((CFDBError))
runNetwork =
  runNetwork'_ >>= \res ->
  let {res' = CFDBError res} in
  return (res')

{-# LINE 132 "src/FoundationDB/Internal/Bindings.chs" #-}


stopNetwork :: IO ((CFDBError))
stopNetwork =
  stopNetwork'_ >>= \res ->
  let {res' = CFDBError res} in
  return (res')

{-# LINE 134 "src/FoundationDB/Internal/Bindings.chs" #-}


networkSetOption_ :: (Int) -> (Ptr CUChar) -> (Int) -> IO ((CFDBError))
networkSetOption_ a1 a2 a3 =
  let {a1' = fromIntegral a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  networkSetOption_'_ a1' a2' a3' >>= \res ->
  let {res' = CFDBError res} in
  return (res')

{-# LINE 138 "src/FoundationDB/Internal/Bindings.chs" #-}


networkSetOption :: NetworkOption -> IO CFDBError
networkSetOption (NetworkOptionString enum str) =
  withCStringLen str $ \(arr, len) ->
    networkSetOption_ enum (castPtr arr) len
networkSetOption (NetworkOptionInt enum i) = alloca $ \iptr -> do
  poke iptr i
  networkSetOption_ enum (castPtr iptr) (sizeOf i)
networkSetOption (NetworkOptionBytes Int
enum ByteString
bs) =
  ByteString -> (CStringLen -> IO CFDBError) -> IO CFDBError
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
bs ((CStringLen -> IO CFDBError) -> IO CFDBError)
-> (CStringLen -> IO CFDBError) -> IO CFDBError
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
arr, Int
len) ->
    Int -> Ptr CUChar -> Int -> IO CFDBError
networkSetOption_ Int
enum (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
arr) Int
len
networkSetOption (NetworkOptionFlag Int
enum) =
  Int -> Ptr CUChar -> Int -> IO CFDBError
networkSetOption_ Int
enum Ptr CUChar
forall a. Ptr a
nullPtr Int
0

newtype Future a = Future (C2HSImp.Ptr (Future a))

deriving instance Show (Future a)
deriving instance Storable (Future a)

inFuture :: Future a -> Ptr ()
inFuture :: Future a -> Ptr ()
inFuture (Future Ptr (Future a)
x) = Ptr (Future a) -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr (Future a)
x

outFuture ::Ptr () -> Future a
outFuture :: Ptr () -> Future a
outFuture Ptr ()
p = Ptr (Future a) -> Future a
forall a. Ptr (Future a) -> Future a
Future (Ptr () -> Ptr (Future a)
forall a b. Ptr a -> Ptr b
castPtr Ptr ()
p)

futureCancel :: (Future a) -> IO ()
futureCancel :: Future a -> IO ()
futureCancel Future a
a1 =
  let {a1' :: Ptr ()
a1' = Future a -> Ptr ()
forall a. Future a -> Ptr ()
inFuture Future a
a1} in 
  futureCancel'_ a1' >>
  return ()

{-# LINE 164 "src/FoundationDB/Internal/Bindings.chs" #-}


futureDestroy :: (Future a) -> IO ()
futureDestroy a1 =
  let {a1' = inFuture a1} in 
  futureDestroy'_ a1' >>
  return ()

{-# LINE 166 "src/FoundationDB/Internal/Bindings.chs" #-}


foreign import capi "fdbc_wrapper.h &fdb_future_destroy"
  futureDestroyPtr :: FunPtr (Ptr a -> IO ())

futureBlockUntilReady :: (Future a) -> IO ((CFDBError))
futureBlockUntilReady a1 =
  let {a1' = inFuture a1} in 
  futureBlockUntilReady'_ a1' >>= \res ->
  let {res' = CFDBError res} in
  return (res')

{-# LINE 172 "src/FoundationDB/Internal/Bindings.chs" #-}


futureIsReady :: (Future a) -> IO ((Bool))
futureIsReady a1 =
  let {a1' = inFuture a1} in 
  futureIsReady'_ a1' >>= \res ->
  let {res' = C2HSImp.toBool res} in
  return (res')

{-# LINE 174 "src/FoundationDB/Internal/Bindings.chs" #-}


futureReleaseMemory :: (Future a) -> IO ()
futureReleaseMemory a1 =
  let {a1' = inFuture a1} in 
  futureReleaseMemory'_ a1' >>
  return ()

{-# LINE 176 "src/FoundationDB/Internal/Bindings.chs" #-}


futureGetError :: (Future a) -> IO ((CFDBError))
futureGetError a1 =
  let {a1' = inFuture a1} in 
  futureGetError'_ a1' >>= \res ->
  let {res' = CFDBError res} in
  return (res')

peekBool :: Ptr CInt -> IO Bool
{-# LINE 179 "src/FoundationDB/Internal/Bindings.chs" #-}


peekIntegral :: (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral x = fmap fromIntegral $ peek x

peekBool :: Ptr CInt -> IO Bool
peekBool x = fmap (/= 0) $ peek x

futureGetInt64 :: (Future Int64) -> IO ((CFDBError), (Int64))
futureGetInt64 :: Future Int64 -> IO (CFDBError, Int64)
futureGetInt64 Future Int64
a1 =
  let {a1' :: Ptr ()
a1' = Future Int64 -> Ptr ()
forall a. Future a -> Ptr ()
inFuture Future Int64
a1} in 
  (Ptr CLong -> IO (CFDBError, Int64)) -> IO (CFDBError, Int64)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CLong -> IO (CFDBError, Int64)) -> IO (CFDBError, Int64))
-> (Ptr CLong -> IO (CFDBError, Int64)) -> IO (CFDBError, Int64)
forall a b. (a -> b) -> a -> b
$ \Ptr CLong
a2' -> 
  Ptr () -> Ptr CLong -> IO CInt
futureGetInt64'_ Ptr ()
a1' Ptr CLong
a2' IO CInt -> (CInt -> IO (CFDBError, Int64)) -> IO (CFDBError, Int64)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: CFDBError
res' = CInt -> CFDBError
CFDBError CInt
res} in
  Ptr CLong -> IO Int64
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CLong
a2'IO Int64
-> (Int64 -> IO (CFDBError, Int64)) -> IO (CFDBError, Int64)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int64
a2'' -> 
  (CFDBError, Int64) -> IO (CFDBError, Int64)
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError
res', Int64
a2'')

{-# LINE 195 "src/FoundationDB/Internal/Bindings.chs" #-}


futureGetKey_ :: (Future a) -> IO ((CFDBError), (Ptr CUChar), (Int))
futureGetKey_ :: Future a -> IO (CFDBError, Ptr CUChar, Int)
futureGetKey_ Future a
a1 =
  let {a1' :: Ptr ()
a1' = Future a -> Ptr ()
forall a. Future a -> Ptr ()
inFuture Future a
a1} in 
  (Ptr (Ptr CUChar) -> IO (CFDBError, Ptr CUChar, Int))
-> IO (CFDBError, Ptr CUChar, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CUChar) -> IO (CFDBError, Ptr CUChar, Int))
 -> IO (CFDBError, Ptr CUChar, Int))
-> (Ptr (Ptr CUChar) -> IO (CFDBError, Ptr CUChar, Int))
-> IO (CFDBError, Ptr CUChar, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CUChar)
a2' -> 
  (Ptr CInt -> IO (CFDBError, Ptr CUChar, Int))
-> IO (CFDBError, Ptr CUChar, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (CFDBError, Ptr CUChar, Int))
 -> IO (CFDBError, Ptr CUChar, Int))
-> (Ptr CInt -> IO (CFDBError, Ptr CUChar, Int))
-> IO (CFDBError, Ptr CUChar, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a3' -> 
  Ptr () -> Ptr (Ptr CUChar) -> Ptr CInt -> IO CInt
futureGetKey_'_ Ptr ()
a1' Ptr (Ptr CUChar)
a2' Ptr CInt
a3' IO CInt
-> (CInt -> IO (CFDBError, Ptr CUChar, Int))
-> IO (CFDBError, Ptr CUChar, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: CFDBError
res' = CInt -> CFDBError
CFDBError CInt
res} in
  Ptr (Ptr CUChar) -> IO (Ptr CUChar)
forall a. Storable a => Ptr a -> IO a
peek  Ptr (Ptr CUChar)
a2'IO (Ptr CUChar)
-> (Ptr CUChar -> IO (CFDBError, Ptr CUChar, Int))
-> IO (CFDBError, Ptr CUChar, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CUChar
a2'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a3'IO Int
-> (Int -> IO (CFDBError, Ptr CUChar, Int))
-> IO (CFDBError, Ptr CUChar, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a3'' -> 
  (CFDBError, Ptr CUChar, Int) -> IO (CFDBError, Ptr CUChar, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError
res', Ptr CUChar
a2'', Int
a3'')

{-# LINE 199 "src/FoundationDB/Internal/Bindings.chs" #-}


-- Retrying is provided by a helper function:
-- https://apple.github.io/foundationdb/api-c.html#c.fdb_transaction_on_error
futureGetKey :: Future B.ByteString -> IO (Either CFDBError B.ByteString)
futureGetKey f = do
  (err, cs, l) <- futureGetKey_ f
  if isError err
    then return $ Left err
    else do bs <- B.packCStringLen (castPtr cs, l)
            return $ Right bs

-- | Handle to the underlying C API client state.
newtype DatabasePtr = DatabasePtr (C2HSImp.Ptr (DatabasePtr))
{-# LINE 212 "src/FoundationDB/Internal/Bindings.chs" #-}


deriving instance Eq DatabasePtr
deriving instance Show DatabasePtr
deriving instance Storable DatabasePtr

futureGetValue_ :: (Future a) -> IO ((CFDBError), (Bool), (Ptr CUChar), (Int))
futureGetValue_ :: Future a -> IO (CFDBError, Bool, Ptr CUChar, Int)
futureGetValue_ Future a
a1 =
  let {a1' :: Ptr ()
a1' = Future a -> Ptr ()
forall a. Future a -> Ptr ()
inFuture Future a
a1} in 
  (Ptr CInt -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (CFDBError, Bool, Ptr CUChar, Int))
 -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> (Ptr CInt -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a2' -> 
  (Ptr (Ptr CUChar) -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CUChar) -> IO (CFDBError, Bool, Ptr CUChar, Int))
 -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> (Ptr (Ptr CUChar) -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CUChar)
a3' -> 
  (Ptr CInt -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (CFDBError, Bool, Ptr CUChar, Int))
 -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> (Ptr CInt -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a4' -> 
  Ptr () -> Ptr CInt -> Ptr (Ptr CUChar) -> Ptr CInt -> IO CInt
futureGetValue_'_ Ptr ()
a1' Ptr CInt
a2' Ptr (Ptr CUChar)
a3' Ptr CInt
a4' IO CInt
-> (CInt -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: CFDBError
res' = CInt -> CFDBError
CFDBError CInt
res} in
  Ptr CInt -> IO Bool
peekBool  Ptr CInt
a2'IO Bool
-> (Bool -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
a2'' -> 
  Ptr (Ptr CUChar) -> IO (Ptr CUChar)
forall a. Storable a => Ptr a -> IO a
peek  Ptr (Ptr CUChar)
a3'IO (Ptr CUChar)
-> (Ptr CUChar -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CUChar
a3'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a4'IO Int
-> (Int -> IO (CFDBError, Bool, Ptr CUChar, Int))
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a4'' -> 
  (CFDBError, Bool, Ptr CUChar, Int)
-> IO (CFDBError, Bool, Ptr CUChar, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError
res', Bool
a2'', Ptr CUChar
a3'', Int
a4'')

{-# LINE 223 "src/FoundationDB/Internal/Bindings.chs" #-}


futureGetValue :: Future (Maybe B.ByteString)
               -> IO (Either CFDBError (Maybe B.ByteString))
futureGetValue f = do
  (err, present, outstr, outlen) <- futureGetValue_ f
  case (isError err, present) of
    (True, _) -> return $ Left err
    (False, False) -> return $ Right Nothing
    (False, True) -> do bstr <- B.packCStringLen (castPtr outstr, outlen)
                        return $ Right $ Just bstr

futureGetStringArray_ :: (Future a) -> IO ((CFDBError), (Ptr (Ptr CChar)), (Int))
futureGetStringArray_ :: Future a -> IO (CFDBError, Ptr (Ptr CChar), Int)
futureGetStringArray_ Future a
a1 =
  let {a1' :: Ptr ()
a1' = Future a -> Ptr ()
forall a. Future a -> Ptr ()
inFuture Future a
a1} in 
  (Ptr (Ptr (Ptr CChar)) -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> IO (CFDBError, Ptr (Ptr CChar), Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr (Ptr CChar)) -> IO (CFDBError, Ptr (Ptr CChar), Int))
 -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> (Ptr (Ptr (Ptr CChar)) -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> IO (CFDBError, Ptr (Ptr CChar), Int)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr (Ptr CChar))
a2' -> 
  (Ptr CInt -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> IO (CFDBError, Ptr (Ptr CChar), Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (CFDBError, Ptr (Ptr CChar), Int))
 -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> (Ptr CInt -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> IO (CFDBError, Ptr (Ptr CChar), Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a3' -> 
  Ptr () -> Ptr (Ptr (Ptr CChar)) -> Ptr CInt -> IO CInt
futureGetStringArray_'_ Ptr ()
a1' Ptr (Ptr (Ptr CChar))
a2' Ptr CInt
a3' IO CInt
-> (CInt -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> IO (CFDBError, Ptr (Ptr CChar), Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: CFDBError
res' = CInt -> CFDBError
CFDBError CInt
res} in
  Ptr (Ptr (Ptr CChar)) -> IO (Ptr (Ptr CChar))
forall a. Storable a => Ptr a -> IO a
peek  Ptr (Ptr (Ptr CChar))
a2'IO (Ptr (Ptr CChar))
-> (Ptr (Ptr CChar) -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> IO (CFDBError, Ptr (Ptr CChar), Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr (Ptr CChar)
a2'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a3'IO Int
-> (Int -> IO (CFDBError, Ptr (Ptr CChar), Int))
-> IO (CFDBError, Ptr (Ptr CChar), Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a3'' -> 
  (CFDBError, Ptr (Ptr CChar), Int)
-> IO (CFDBError, Ptr (Ptr CChar), Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError
res', Ptr (Ptr CChar)
a2'', Int
a3'')

{-# LINE 239 "src/FoundationDB/Internal/Bindings.chs" #-}


futureGetStringArray :: Future [B.ByteString]
                     -> IO (Either CFDBError [B.ByteString])
futureGetStringArray f = do
  (err, strs, numStrs) <- futureGetStringArray_ f
  if isError err
    then return $ Left err
    else do strList <- peekArray numStrs strs
            bstrs <- mapM B.packCString strList
            return $ Right bstrs

data FDBKeyValue = FDBKeyValue
  { FDBKeyValue -> Ptr ()
key :: Ptr ()
  , FDBKeyValue -> Int
key_length :: Int
  , FDBKeyValue -> Ptr ()
value :: Ptr ()
  , FDBKeyValue -> Int
value_length :: Int}
  deriving (Int -> FDBKeyValue -> ShowS
[FDBKeyValue] -> ShowS
FDBKeyValue -> String
(Int -> FDBKeyValue -> ShowS)
-> (FDBKeyValue -> String)
-> ([FDBKeyValue] -> ShowS)
-> Show FDBKeyValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FDBKeyValue] -> ShowS
$cshowList :: [FDBKeyValue] -> ShowS
show :: FDBKeyValue -> String
$cshow :: FDBKeyValue -> String
showsPrec :: Int -> FDBKeyValue -> ShowS
$cshowsPrec :: Int -> FDBKeyValue -> ShowS
Show, FDBKeyValue -> FDBKeyValue -> Bool
(FDBKeyValue -> FDBKeyValue -> Bool)
-> (FDBKeyValue -> FDBKeyValue -> Bool) -> Eq FDBKeyValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FDBKeyValue -> FDBKeyValue -> Bool
$c/= :: FDBKeyValue -> FDBKeyValue -> Bool
== :: FDBKeyValue -> FDBKeyValue -> Bool
$c== :: FDBKeyValue -> FDBKeyValue -> Bool
Eq)

instance Storable FDBKeyValue where
  sizeOf :: FDBKeyValue -> Int
sizeOf FDBKeyValue
_ = Int
24
  alignment :: FDBKeyValue -> Int
alignment FDBKeyValue
_ = Int
4
  peek :: Ptr FDBKeyValue -> IO FDBKeyValue
peek Ptr FDBKeyValue
p = do
    Ptr ()
key <- Ptr FDBKeyValue -> Int -> IO (Ptr ())
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr FDBKeyValue
p Int
0 :: IO (Ptr ())
    Int
key_length <- CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr FDBKeyValue -> Int -> IO CInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr FDBKeyValue
p Int
8 :: IO CInt)
    Ptr ()
value <- Ptr FDBKeyValue -> Int -> IO (Ptr ())
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr FDBKeyValue
p Int
12 :: IO (C2HSImp.Ptr ())
    Int
value_length <- CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr FDBKeyValue -> Int -> IO CInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr FDBKeyValue
p Int
20 :: IO C2HSImp.CInt)
    FDBKeyValue -> IO FDBKeyValue
forall (m :: * -> *) a. Monad m => a -> m a
return FDBKeyValue :: Ptr () -> Int -> Ptr () -> Int -> FDBKeyValue
FDBKeyValue{Int
Ptr ()
value_length :: Int
value :: Ptr ()
key_length :: Int
key :: Ptr ()
value_length :: Int
value :: Ptr ()
key_length :: Int
key :: Ptr ()
..}
  poke :: Ptr FDBKeyValue -> FDBKeyValue -> IO ()
poke Ptr FDBKeyValue
p FDBKeyValue{Int
Ptr ()
value_length :: Int
value :: Ptr ()
key_length :: Int
key :: Ptr ()
value_length :: FDBKeyValue -> Int
value :: FDBKeyValue -> Ptr ()
key_length :: FDBKeyValue -> Int
key :: FDBKeyValue -> Ptr ()
..} = do
    Ptr FDBKeyValue -> Int -> Ptr () -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr FDBKeyValue
p Int
0 (Ptr ()
key :: (C2HSImp.Ptr ()))
    Ptr FDBKeyValue -> Int -> CInt -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr FDBKeyValue
p Int
8 (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
key_length :: C2HSImp.CInt)
    Ptr FDBKeyValue -> Int -> Ptr () -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr FDBKeyValue
p Int
12 (Ptr ()
value :: C2HSImp.Ptr ())
    Ptr FDBKeyValue -> Int -> CInt -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr FDBKeyValue
p Int
20 (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
value_length :: C2HSImp.CInt)

packKeyValue :: FDBKeyValue -> IO (B.ByteString, B.ByteString)
packKeyValue :: FDBKeyValue -> IO (ByteString, ByteString)
packKeyValue FDBKeyValue{Int
Ptr ()
value_length :: Int
value :: Ptr ()
key_length :: Int
key :: Ptr ()
value_length :: FDBKeyValue -> Int
value :: FDBKeyValue -> Ptr ()
key_length :: FDBKeyValue -> Int
key :: FDBKeyValue -> Ptr ()
..} = do
  ByteString
k <- CStringLen -> IO ByteString
B.packCStringLen (Ptr () -> Ptr CChar
forall a b. Ptr a -> Ptr b
castPtr Ptr ()
key, Int
key_length)
  ByteString
v <- CStringLen -> IO ByteString
B.packCStringLen (Ptr () -> Ptr CChar
forall a b. Ptr a -> Ptr b
castPtr Ptr ()
value, Int
value_length)
  (ByteString, ByteString) -> IO (ByteString, ByteString)
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString
k,ByteString
v)

peekCastFDBKeyValue :: Ptr (Ptr FDBKeyValue) -> IO (Ptr FDBKeyValue)
peekCastFDBKeyValue :: Ptr (Ptr FDBKeyValue) -> IO (Ptr FDBKeyValue)
peekCastFDBKeyValue Ptr (Ptr FDBKeyValue)
p = do
  Ptr FDBKeyValue
p' <- Ptr (Ptr FDBKeyValue) -> IO (Ptr FDBKeyValue)
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr FDBKeyValue)
p
  Ptr FDBKeyValue -> IO (Ptr FDBKeyValue)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr FDBKeyValue
p'

peekCastFDBKeyValue' :: Ptr (Ptr ()) -> IO (Ptr FDBKeyValue)
peekCastFDBKeyValue' :: Ptr (Ptr ()) -> IO (Ptr FDBKeyValue)
peekCastFDBKeyValue' Ptr (Ptr ())
p = do
  Ptr ()
p' <- Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr ())
p
  Ptr FDBKeyValue -> IO (Ptr FDBKeyValue)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr () -> Ptr FDBKeyValue
forall a b. Ptr a -> Ptr b
castPtr Ptr ()
p')

peekFDBBool :: Ptr CInt -> IO Bool
peekFDBBool :: Ptr CInt -> IO Bool
peekFDBBool Ptr CInt
p = Ptr Bool -> IO Bool
forall a. Storable a => Ptr a -> IO a
peek (Ptr CInt -> Ptr Bool
forall a b. Ptr a -> Ptr b
castPtr Ptr CInt
p)

foreign import capi unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_get_keyvalue_array"
  futureGetKeyValueArray_'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr FDBKeyValue)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO C2HSImp.CInt)))))

futureGetKeyValueArray_ :: (Future a) -> IO ((CFDBError), (Ptr FDBKeyValue), (Int), (Bool))
futureGetKeyValueArray_ :: Future a -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
futureGetKeyValueArray_ Future a
a1 =
  let {a1' :: Ptr ()
a1' = Future a -> Ptr ()
forall a. Future a -> Ptr ()
inFuture Future a
a1} in
  (Ptr (Ptr FDBKeyValue)
 -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr FDBKeyValue)
  -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
 -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> (Ptr (Ptr FDBKeyValue)
    -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr FDBKeyValue)
a2' ->
  (Ptr CInt -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
 -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> (Ptr CInt -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a3' ->
  (Ptr CInt -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
 -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> (Ptr CInt -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a4' ->
  Ptr () -> Ptr (Ptr FDBKeyValue) -> Ptr CInt -> Ptr CInt -> IO CInt
futureGetKeyValueArray_'_ Ptr ()
a1' Ptr (Ptr FDBKeyValue)
a2' Ptr CInt
a3' Ptr CInt
a4' IO CInt
-> (CInt -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: CFDBError
res' = CInt -> CFDBError
CFDBError CInt
res} in
  Ptr (Ptr FDBKeyValue) -> IO (Ptr FDBKeyValue)
peekCastFDBKeyValue  Ptr (Ptr FDBKeyValue)
a2'IO (Ptr FDBKeyValue)
-> (Ptr FDBKeyValue -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr FDBKeyValue
a2'' ->
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a3'IO Int
-> (Int -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a3'' ->
  Ptr CInt -> IO Bool
peekFDBBool  Ptr CInt
a4'IO Bool
-> (Bool -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool))
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
a4'' ->
  (CFDBError, Ptr FDBKeyValue, Int, Bool)
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError
res', Ptr FDBKeyValue
a2'', Int
a3'', Bool
a4'')

futureGetKeyValueArray :: Future [(B.ByteString, B.ByteString)]
                       -> IO (Either CFDBError
                                     ([(B.ByteString, B.ByteString)], Bool))
futureGetKeyValueArray :: Future [(ByteString, ByteString)]
-> IO (Either CFDBError ([(ByteString, ByteString)], Bool))
futureGetKeyValueArray Future [(ByteString, ByteString)]
f = do
  (CFDBError
err, Ptr FDBKeyValue
arr, Int
n, Bool
more) <- Future [(ByteString, ByteString)]
-> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
forall a. Future a -> IO (CFDBError, Ptr FDBKeyValue, Int, Bool)
futureGetKeyValueArray_ Future [(ByteString, ByteString)]
f
  if CFDBError -> Bool
isError CFDBError
err
    then Either CFDBError ([(ByteString, ByteString)], Bool)
-> IO (Either CFDBError ([(ByteString, ByteString)], Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either CFDBError ([(ByteString, ByteString)], Bool)
 -> IO (Either CFDBError ([(ByteString, ByteString)], Bool)))
-> Either CFDBError ([(ByteString, ByteString)], Bool)
-> IO (Either CFDBError ([(ByteString, ByteString)], Bool))
forall a b. (a -> b) -> a -> b
$ CFDBError -> Either CFDBError ([(ByteString, ByteString)], Bool)
forall a b. a -> Either a b
Left CFDBError
err
    else do [(ByteString, ByteString)]
kvs <- Int -> Ptr FDBKeyValue -> IO [FDBKeyValue]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
n Ptr FDBKeyValue
arr IO [FDBKeyValue]
-> ([FDBKeyValue] -> IO [(ByteString, ByteString)])
-> IO [(ByteString, ByteString)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (FDBKeyValue -> IO (ByteString, ByteString))
-> [FDBKeyValue] -> IO [(ByteString, ByteString)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM FDBKeyValue -> IO (ByteString, ByteString)
packKeyValue
            Either CFDBError ([(ByteString, ByteString)], Bool)
-> IO (Either CFDBError ([(ByteString, ByteString)], Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either CFDBError ([(ByteString, ByteString)], Bool)
 -> IO (Either CFDBError ([(ByteString, ByteString)], Bool)))
-> Either CFDBError ([(ByteString, ByteString)], Bool)
-> IO (Either CFDBError ([(ByteString, ByteString)], Bool))
forall a b. (a -> b) -> a -> b
$ ([(ByteString, ByteString)], Bool)
-> Either CFDBError ([(ByteString, ByteString)], Bool)
forall a b. b -> Either a b
Right (([(ByteString, ByteString)], Bool)
 -> Either CFDBError ([(ByteString, ByteString)], Bool))
-> ([(ByteString, ByteString)], Bool)
-> Either CFDBError ([(ByteString, ByteString)], Bool)
forall a b. (a -> b) -> a -> b
$ ([(ByteString, ByteString)]
kvs, Bool
more)



-- | The result of a mapped key value query, containing the
-- parent key and value (i.e., the key and value in the secondary index),
-- and the range of key-value pairs retrieved based on the range query
-- generated from the mapper's operation on the parent key and value.
--
-- WARNING: FDB's docs warn that the returned KeySelector fields have not yet
-- been tested. Use them at your own risk!
data MappedKeyValue = MappedKeyValue
  {
    MappedKeyValue -> ByteString
parentKey :: B.ByteString,
    MappedKeyValue -> ByteString
parentValue :: B.ByteString,
    MappedKeyValue -> KeySelector
mappedKeySelectorBegin :: KeySelector,
    MappedKeyValue -> KeySelector
mappedKeySelectorEnd :: KeySelector,
    MappedKeyValue -> [(ByteString, ByteString)]
mappedKeyValues :: [(B.ByteString, B.ByteString)]
  } deriving (Int -> MappedKeyValue -> ShowS
[MappedKeyValue] -> ShowS
MappedKeyValue -> String
(Int -> MappedKeyValue -> ShowS)
-> (MappedKeyValue -> String)
-> ([MappedKeyValue] -> ShowS)
-> Show MappedKeyValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MappedKeyValue] -> ShowS
$cshowList :: [MappedKeyValue] -> ShowS
show :: MappedKeyValue -> String
$cshow :: MappedKeyValue -> String
showsPrec :: Int -> MappedKeyValue -> ShowS
$cshowsPrec :: Int -> MappedKeyValue -> ShowS
Show, MappedKeyValue -> MappedKeyValue -> Bool
(MappedKeyValue -> MappedKeyValue -> Bool)
-> (MappedKeyValue -> MappedKeyValue -> Bool) -> Eq MappedKeyValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MappedKeyValue -> MappedKeyValue -> Bool
$c/= :: MappedKeyValue -> MappedKeyValue -> Bool
== :: MappedKeyValue -> MappedKeyValue -> Bool
$c== :: MappedKeyValue -> MappedKeyValue -> Bool
Eq)

-- GHC's C FFI doesn't support nested structs, so we have a function in
-- fdbc_wrapper.h and fdbc_wrapper.c that fetches
-- everything we need to construct the above value.
--
-- This also means we can't define a Storable instance for MappedKeyValue.

newtype MappedKeyValuePtr = MappedKeyValuePtr (C2HSImp.Ptr (MappedKeyValuePtr))
{-# LINE 343 "src/FoundationDB/Internal/Bindings.chs" #-}


deriving instance Eq MappedKeyValuePtr
deriving instance Show MappedKeyValuePtr
deriving instance Storable MappedKeyValuePtr

getMappedRangeResult_ :: (MappedKeyValuePtr) -> IO ((Ptr CUChar), (Int), (Ptr CUChar), (Int), (Ptr CUChar), (Int), (Bool), (Int), (Ptr CUChar), (Int), (Bool), (Int), (Ptr FDBKeyValue), (Int))
getMappedRangeResult_ :: MappedKeyValuePtr
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
getMappedRangeResult_ MappedKeyValuePtr
a1 =
  let {a1' :: MappedKeyValuePtr
a1' = MappedKeyValuePtr -> MappedKeyValuePtr
forall a. a -> a
id MappedKeyValuePtr
a1} in 
  (Ptr (Ptr CUChar)
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CUChar)
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr (Ptr CUChar)
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CUChar)
a2' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a3' -> 
  (Ptr (Ptr CUChar)
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CUChar)
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr (Ptr CUChar)
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CUChar)
a4' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a5' -> 
  (Ptr (Ptr CUChar)
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CUChar)
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr (Ptr CUChar)
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CUChar)
a6' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a7' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a8' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a9' -> 
  (Ptr (Ptr CUChar)
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CUChar)
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr (Ptr CUChar)
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CUChar)
a10' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a11' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a12' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a13' -> 
  (Ptr (Ptr ())
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr ())
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr (Ptr ())
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a14' -> 
  (Ptr CInt
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr CInt
  -> IO
       (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
        Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
 -> IO
      (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
       Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> (Ptr CInt
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a15' -> 
  MappedKeyValuePtr
-> Ptr (Ptr CUChar)
-> Ptr CInt
-> Ptr (Ptr CUChar)
-> Ptr CInt
-> Ptr (Ptr CUChar)
-> Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr (Ptr CUChar)
-> Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr (Ptr ())
-> Ptr CInt
-> IO ()
getMappedRangeResult_'_ MappedKeyValuePtr
a1' Ptr (Ptr CUChar)
a2' Ptr CInt
a3' Ptr (Ptr CUChar)
a4' Ptr CInt
a5' Ptr (Ptr CUChar)
a6' Ptr CInt
a7' Ptr CInt
a8' Ptr CInt
a9' Ptr (Ptr CUChar)
a10' Ptr CInt
a11' Ptr CInt
a12' Ptr CInt
a13' Ptr (Ptr ())
a14' Ptr CInt
a15' IO () -> IO (Ptr CUChar) -> IO (Ptr CUChar)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Ptr (Ptr CUChar) -> IO (Ptr CUChar)
forall a. Storable a => Ptr a -> IO a
peek  Ptr (Ptr CUChar)
a2'IO (Ptr CUChar)
-> (Ptr CUChar
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CUChar
a2'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a3'IO Int
-> (Int
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a3'' -> 
  Ptr (Ptr CUChar) -> IO (Ptr CUChar)
forall a. Storable a => Ptr a -> IO a
peek  Ptr (Ptr CUChar)
a4'IO (Ptr CUChar)
-> (Ptr CUChar
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CUChar
a4'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a5'IO Int
-> (Int
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a5'' -> 
  Ptr (Ptr CUChar) -> IO (Ptr CUChar)
forall a. Storable a => Ptr a -> IO a
peek  Ptr (Ptr CUChar)
a6'IO (Ptr CUChar)
-> (Ptr CUChar
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CUChar
a6'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a7'IO Int
-> (Int
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a7'' -> 
  Ptr CInt -> IO Bool
peekBool  Ptr CInt
a8'IO Bool
-> (Bool
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
a8'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a9'IO Int
-> (Int
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a9'' -> 
  Ptr (Ptr CUChar) -> IO (Ptr CUChar)
forall a. Storable a => Ptr a -> IO a
peek  Ptr (Ptr CUChar)
a10'IO (Ptr CUChar)
-> (Ptr CUChar
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CUChar
a10'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a11'IO Int
-> (Int
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a11'' -> 
  Ptr CInt -> IO Bool
peekBool  Ptr CInt
a12'IO Bool
-> (Bool
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
a12'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a13'IO Int
-> (Int
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
a13'' -> 
  Ptr (Ptr ()) -> IO (Ptr FDBKeyValue)
peekCastFDBKeyValue'  Ptr (Ptr ())
a14'IO (Ptr FDBKeyValue)
-> (Ptr FDBKeyValue
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr FDBKeyValue
a14'' -> 
  Ptr CInt -> IO Int
forall a b. (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral  Ptr CInt
a15'IO Int
-> (Int
    -> IO
         (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
          Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int))
-> IO
     (Ptr CUChar, Int, Ptr CUChar, Int, Ptr CUChar, Int, Bool, Int,
      Ptr CUChar, Int, Bool, Int, Ptr FDBKeyValue, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a15'' -> 
  return (a2'', a3'', a4'', a5'', a6'', a7'', a8'', a9'', a10'', a11'', a12'', a13'', a14'', a15'')

{-# LINE 365 "src/FoundationDB/Internal/Bindings.chs" #-}


futureGetMappedkeyvalueArray :: (Future [MappedKeyValue]) -> IO ((CFDBError), (MappedKeyValuePtr), (Int), (Bool))
futureGetMappedkeyvalueArray a1 =
  let {a1' = inFuture a1} in 
  alloca $ \a2' -> 
  alloca $ \a3' -> 
  alloca $ \a4' -> 
  futureGetMappedkeyvalueArray'_ a1' a2' a3' a4' >>= \res ->
  let {res' = CFDBError res} in
  peek  a2'>>= \a2'' -> 
  peekIntegral  a3'>>= \a3'' -> 
  peekBool  a4'>>= \a4'' -> 
  return (res', a2'', a3'', a4'')

{-# LINE 373 "src/FoundationDB/Internal/Bindings.chs" #-}


getMappedKeyValueSize :: IO ((Int))
getMappedKeyValueSize =
  getMappedKeyValueSize'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 377 "src/FoundationDB/Internal/Bindings.chs" #-}


packMappedKeyValue :: MappedKeyValuePtr -> IO MappedKeyValue
packMappedKeyValue mappedKVPtr = do
  ( parentKeyPtr
    , parentKeyLen

    , parentValuePtr
    , parentValueLen

    , beginKeySelKeyPtr
    , beginKeySelKeyLen
    , beginKeySelOrEqual
    , beginKeySelOffset

    , endKeySelKeyPtr
    , endKeySelKeyLen
    , endKeySelOrEqual
    , endKeySelOffset

    , kvsPtr
    , kvsLen) <- getMappedRangeResult_ mappedKVPtr
  parentKey <- B.packCStringLen (castPtr parentKeyPtr, parentKeyLen)
  parentValue <- B.packCStringLen (castPtr parentValuePtr, Int
parentValueLen)

  ByteString
beginKeySelKey <- CStringLen -> IO ByteString
B.packCStringLen (Ptr CUChar -> Ptr CChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CUChar
beginKeySelKeyPtr, Int
beginKeySelKeyLen)
  let mappedKeySelectorBegin :: KeySelector
mappedKeySelectorBegin = (ByteString, Bool, Int) -> KeySelector
tupleKeySelector (ByteString
beginKeySelKey, Bool
beginKeySelOrEqual, Int
beginKeySelOffset)

  ByteString
endKeySelKey <- CStringLen -> IO ByteString
B.packCStringLen (Ptr CUChar -> Ptr CChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CUChar
endKeySelKeyPtr, Int
endKeySelKeyLen)
  let mappedKeySelectorEnd :: KeySelector
mappedKeySelectorEnd = (ByteString, Bool, Int) -> KeySelector
tupleKeySelector (ByteString
endKeySelKey, Bool
endKeySelOrEqual, Int
endKeySelOffset)
  [(ByteString, ByteString)]
mappedKeyValues <- Int -> Ptr FDBKeyValue -> IO [FDBKeyValue]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
kvsLen Ptr FDBKeyValue
kvsPtr IO [FDBKeyValue]
-> ([FDBKeyValue] -> IO [(ByteString, ByteString)])
-> IO [(ByteString, ByteString)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (FDBKeyValue -> IO (ByteString, ByteString))
-> [FDBKeyValue] -> IO [(ByteString, ByteString)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM FDBKeyValue -> IO (ByteString, ByteString)
packKeyValue
  MappedKeyValue -> IO MappedKeyValue
forall (m :: * -> *) a. Monad m => a -> m a
return MappedKeyValue :: ByteString
-> ByteString
-> KeySelector
-> KeySelector
-> [(ByteString, ByteString)]
-> MappedKeyValue
MappedKeyValue{[(ByteString, ByteString)]
ByteString
KeySelector
mappedKeyValues :: [(ByteString, ByteString)]
mappedKeySelectorEnd :: KeySelector
mappedKeySelectorBegin :: KeySelector
parentValue :: ByteString
parentKey :: ByteString
mappedKeyValues :: [(ByteString, ByteString)]
mappedKeySelectorEnd :: KeySelector
mappedKeySelectorBegin :: KeySelector
parentValue :: ByteString
parentKey :: ByteString
..}


-- | Extracts the mappedKeyValue results from the future, along with a bool
-- indicating whether more results are available.
getMappedRangeResult :: Future [MappedKeyValue] -> IO (Either CFDBError ([MappedKeyValue], Bool))
getMappedRangeResult :: Future [MappedKeyValue]
-> IO (Either CFDBError ([MappedKeyValue], Bool))
getMappedRangeResult Future [MappedKeyValue]
future = do
  (CFDBError
err, (MappedKeyValuePtr Ptr MappedKeyValuePtr
mappedKVPtr), Int
len, Bool
more) <- Future [MappedKeyValue]
-> IO (CFDBError, MappedKeyValuePtr, Int, Bool)
futureGetMappedkeyvalueArray Future [MappedKeyValue]
future
  if CFDBError
err CFDBError -> CFDBError -> Bool
forall a. Eq a => a -> a -> Bool
== CFDBError
0
    then do
      Int
size <- IO Int
getMappedKeyValueSize
      -- If we could define Storable for MappedKeyValue, we could use
      -- peekArray here, but it's a weird nested struct.
      let ptrs :: [MappedKeyValuePtr]
ptrs = [ Ptr MappedKeyValuePtr -> MappedKeyValuePtr
MappedKeyValuePtr (Ptr MappedKeyValuePtr -> Int -> Ptr MappedKeyValuePtr
forall a b. Ptr a -> Int -> Ptr b
plusPtr Ptr MappedKeyValuePtr
mappedKVPtr (Int
size Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
i))
                 | Int
i <- [Int
0..Int
len Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]]
      [MappedKeyValue]
mappedKVs <- (MappedKeyValuePtr -> IO MappedKeyValue)
-> [MappedKeyValuePtr] -> IO [MappedKeyValue]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM MappedKeyValuePtr -> IO MappedKeyValue
packMappedKeyValue [MappedKeyValuePtr]
ptrs
      Either CFDBError ([MappedKeyValue], Bool)
-> IO (Either CFDBError ([MappedKeyValue], Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return (([MappedKeyValue], Bool)
-> Either CFDBError ([MappedKeyValue], Bool)
forall a b. b -> Either a b
Right ([MappedKeyValue]
mappedKVs, Bool
more))
    else Either CFDBError ([MappedKeyValue], Bool)
-> IO (Either CFDBError ([MappedKeyValue], Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError -> Either CFDBError ([MappedKeyValue], Bool)
forall a b. a -> Either a b
Left CFDBError
err)

-- NOTE: c2hs was generating incorrect code by somehow not figuring out the
-- correct marshallers automatically like it did for transactionGetRange,
-- so I ran
-- c2hs --cppopts='-Iinclude/' --cppopts='-DFDB_API_VERSION=710' src/FoundationDB/Internal/Bindings.chs
-- grabbed the broken output from the Bindings.hs it generated, then pasted it
-- here and fixed it manually. I needed to manually write the
-- {a14' = (fromIntegral . fromEnum) a14}
-- because it wasn't generating the (fromIntegral . fromEnum) that it does for
-- transactionGetRange. Very odd.

foreign import ccall unsafe "src/FoundationDB/Internal/Bindings.chs.h fdb_transaction_get_mapped_range"
  transactionGetMappedRange_'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ())))))))))))))))))))

transactionGetMappedRange_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> (Bool) -> (Int) -> (Ptr CUChar) -> (Int) -> (Bool) -> (Int) -> (Ptr CUChar) -> (Int) -> (Int) -> (Int) -> (FDBStreamingMode) -> (Int) -> (Bool) -> (Bool) -> IO ((Future a))
transactionGetMappedRange_ :: Transaction
-> Ptr CUChar
-> Int
-> Bool
-> Int
-> Ptr CUChar
-> Int
-> Bool
-> Int
-> Ptr CUChar
-> Int
-> Int
-> Int
-> FDBStreamingMode
-> Int
-> Bool
-> Bool
-> IO (Future a)
transactionGetMappedRange_ (Transaction Ptr Transaction
a1) Ptr CUChar
a2 Int
a3 Bool
a4 Int
a5 Ptr CUChar
a6 Int
a7 Bool
a8 Int
a9 Ptr CUChar
a10 Int
a11 Int
a12 Int
a13 FDBStreamingMode
a14 Int
a15 Bool
a16 Bool
a17 =
  let {a2' :: Ptr CUChar
a2' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a2} in
  let {a3' :: CInt
a3' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in
  let {a4' :: CInt
a4' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a4} in
  let {a5' :: CInt
a5' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a5} in
  let {a6' :: Ptr CUChar
a6' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a6} in
  let {a7' :: CInt
a7' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a7} in
  let {a8' :: CInt
a8' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a8} in
  let {a9' :: CInt
a9' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a9} in
  let {a10' :: Ptr CUChar
a10' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a10} in
  let {a11' :: CInt
a11' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a11} in
  let {a12' :: CInt
a12' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a12} in
  let {a13' :: CInt
a13' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a13} in
  let {a14' :: CInt
a14' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt)
-> (FDBStreamingMode -> Int) -> FDBStreamingMode -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FDBStreamingMode -> Int
forall a. Enum a => a -> Int
fromEnum) FDBStreamingMode
a14} in
  let {a15' :: CInt
a15' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a15} in
  let {a16' :: CInt
a16' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a16} in
  let {a17' :: CInt
a17' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a17} in
  Ptr ()
-> Ptr CUChar
-> CInt
-> CInt
-> CInt
-> Ptr CUChar
-> CInt
-> CInt
-> CInt
-> Ptr CUChar
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> CInt
-> IO (Ptr ())
transactionGetMappedRange_'_ (Ptr Transaction -> Ptr ()
forall a b. Ptr a -> Ptr b
castPtr Ptr Transaction
a1) Ptr CUChar
a2' CInt
a3' CInt
a4' CInt
a5' Ptr CUChar
a6' CInt
a7' CInt
a8' CInt
a9' Ptr CUChar
a10' CInt
a11' CInt
a12' CInt
a13' CInt
a14' CInt
a15' CInt
a16' CInt
a17' IO (Ptr ()) -> (Ptr () -> IO (Future a)) -> IO (Future a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr ()
res ->
  let {res' :: Future a
res' = Ptr () -> Future a
forall a. Ptr () -> Future a
outFuture Ptr ()
res} in
  Future a -> IO (Future a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Future a
forall a. Future a
res')

transactionGetMappedRange
  :: Transaction
  -> KeySelector
  -- ^ begin
  -> KeySelector
  -- ^ end
  -> B.ByteString
  -- ^ Mapper name
  -> Int
  -- ^ max number of pairs to return
  -> Int
  -- ^ max number of bytes to return
  -> FDBStreamingMode
  -> Int
  -- ^ if FDBStreamingMode is FdbStreamingModeIterator,
  -- start this at 1 and increment by for each successive
  -- call reading this range. Otherwise, ignored.
  -> Bool
  -- ^ isSnapshotRead
  -> Bool
  -- ^ whether to return pairs in reverse order
  -> IO (Future [MappedKeyValue])
transactionGetMappedRange :: Transaction
-> KeySelector
-> KeySelector
-> ByteString
-> Int
-> Int
-> FDBStreamingMode
-> Int
-> Bool
-> Bool
-> IO (Future [MappedKeyValue])
transactionGetMappedRange
  Transaction
t
  KeySelector
rangeBegin
  KeySelector
rangeEnd
  ByteString
mapper
  Int
pairLimit
  Int
byteLimit
  FDBStreamingMode
streamMode
  Int
iteratorI
  Bool
isSnapshotRead
  Bool
isReverse =
  let (ByteString
bk, Bool
bOrEqual, Int
bOffset) = KeySelector -> (ByteString, Bool, Int)
keySelectorTuple KeySelector
rangeBegin
      (ByteString
ek, Bool
eOrEqual, Int
eOffset) = KeySelector -> (ByteString, Bool, Int)
keySelectorTuple KeySelector
rangeEnd
  in
  ByteString
-> (CStringLen -> IO (Future [MappedKeyValue]))
-> IO (Future [MappedKeyValue])
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
bk ((CStringLen -> IO (Future [MappedKeyValue]))
 -> IO (Future [MappedKeyValue]))
-> (CStringLen -> IO (Future [MappedKeyValue]))
-> IO (Future [MappedKeyValue])
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
bstr, Int
blen) ->
  ByteString
-> (CStringLen -> IO (Future [MappedKeyValue]))
-> IO (Future [MappedKeyValue])
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
ek ((CStringLen -> IO (Future [MappedKeyValue]))
 -> IO (Future [MappedKeyValue]))
-> (CStringLen -> IO (Future [MappedKeyValue]))
-> IO (Future [MappedKeyValue])
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
estr, Int
elen) ->
  ByteString
-> (CStringLen -> IO (Future [MappedKeyValue]))
-> IO (Future [MappedKeyValue])
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
mapper ((CStringLen -> IO (Future [MappedKeyValue]))
 -> IO (Future [MappedKeyValue]))
-> (CStringLen -> IO (Future [MappedKeyValue]))
-> IO (Future [MappedKeyValue])
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
mapperstr, Int
mapperlen) ->
    Transaction
-> Ptr CUChar
-> Int
-> Bool
-> Int
-> Ptr CUChar
-> Int
-> Bool
-> Int
-> Ptr CUChar
-> Int
-> Int
-> Int
-> FDBStreamingMode
-> Int
-> Bool
-> Bool
-> IO (Future [MappedKeyValue])
forall a.
Transaction
-> Ptr CUChar
-> Int
-> Bool
-> Int
-> Ptr CUChar
-> Int
-> Bool
-> Int
-> Ptr CUChar
-> Int
-> Int
-> Int
-> FDBStreamingMode
-> Int
-> Bool
-> Bool
-> IO (Future a)
transactionGetMappedRange_
      Transaction
t
      (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
bstr) Int
blen Bool
bOrEqual Int
bOffset
      (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
estr) Int
elen Bool
eOrEqual Int
eOffset
      (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
mapperstr) Int
mapperlen
      Int
pairLimit
      Int
byteLimit
      FDBStreamingMode
streamMode
      Int
iteratorI
      Bool
isSnapshotRead
      Bool
isReverse


createDatabase :: (String) -> IO ((CFDBError), (DatabasePtr))
createDatabase :: String -> IO (CFDBError, DatabasePtr)
createDatabase String
a1 =
  String
-> (Ptr CChar -> IO (CFDBError, DatabasePtr))
-> IO (CFDBError, DatabasePtr)
forall a. String -> (Ptr CChar -> IO a) -> IO a
C2HSImp.withCString String
a1 ((Ptr CChar -> IO (CFDBError, DatabasePtr))
 -> IO (CFDBError, DatabasePtr))
-> (Ptr CChar -> IO (CFDBError, DatabasePtr))
-> IO (CFDBError, DatabasePtr)
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
a1' -> 
  (Ptr DatabasePtr -> IO (CFDBError, DatabasePtr))
-> IO (CFDBError, DatabasePtr)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr DatabasePtr -> IO (CFDBError, DatabasePtr))
 -> IO (CFDBError, DatabasePtr))
-> (Ptr DatabasePtr -> IO (CFDBError, DatabasePtr))
-> IO (CFDBError, DatabasePtr)
forall a b. (a -> b) -> a -> b
$ \Ptr DatabasePtr
a2' -> 
  Ptr CChar -> Ptr DatabasePtr -> IO CInt
createDatabase'_ Ptr CChar
a1' Ptr DatabasePtr
a2' IO CInt
-> (CInt -> IO (CFDBError, DatabasePtr))
-> IO (CFDBError, DatabasePtr)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: CFDBError
res' = CInt -> CFDBError
CFDBError CInt
res} in
  Ptr DatabasePtr -> IO DatabasePtr
forall a. Storable a => Ptr a -> IO a
peek  Ptr DatabasePtr
a2'IO DatabasePtr
-> (DatabasePtr -> IO (CFDBError, DatabasePtr))
-> IO (CFDBError, DatabasePtr)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \DatabasePtr
a2'' -> 
  (CFDBError, DatabasePtr) -> IO (CFDBError, DatabasePtr)
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError
res', DatabasePtr
a2'')

{-# LINE 517 "src/FoundationDB/Internal/Bindings.chs" #-}


databaseDestroy :: (DatabasePtr) -> IO ()
databaseDestroy a1 =
  let {a1' = id a1} in 
  databaseDestroy'_ a1' >>
  return ()

{-# LINE 519 "src/FoundationDB/Internal/Bindings.chs" #-}


databaseSetOption_ :: (DatabasePtr) -> (Int) -> (Ptr CUChar) -> (Int) -> IO ((CFDBError))
databaseSetOption_ a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  let {a4' = fromIntegral a4} in 
  databaseSetOption_'_ a1' a2' a3' a4' >>= \res ->
  let {res' = CFDBError res} in
  return (res')

{-# LINE 523 "src/FoundationDB/Internal/Bindings.chs" #-}


databaseSetOption :: DatabasePtr -> DatabaseOption -> IO CFDBError
databaseSetOption db (DatabaseOptionString enum str) =
  withCStringLen str $ \(arr,len) ->
    databaseSetOption_ db enum (castPtr arr) len
databaseSetOption db (DatabaseOptionInt enum i) = alloca $ \iptr -> do
  poke iptr i
  databaseSetOption_ db enum (castPtr iptr) 8
databaseSetOption DatabasePtr
db (DatabaseOptionBytes Int
enum ByteString
bs) =
  ByteString -> (CStringLen -> IO CFDBError) -> IO CFDBError
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
bs ((CStringLen -> IO CFDBError) -> IO CFDBError)
-> (CStringLen -> IO CFDBError) -> IO CFDBError
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
arr, Int
len) ->
    DatabasePtr -> Int -> Ptr CUChar -> Int -> IO CFDBError
databaseSetOption_ DatabasePtr
db Int
enum (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
arr) Int
len
databaseSetOption DatabasePtr
db (DatabaseOptionFlag Int
enum) =
  DatabasePtr -> Int -> Ptr CUChar -> Int -> IO CFDBError
databaseSetOption_ DatabasePtr
db Int
enum Ptr CUChar
forall a. Ptr a
nullPtr Int
0

newtype Transaction = Transaction (C2HSImp.Ptr (Transaction))
{-# LINE 538 "src/FoundationDB/Internal/Bindings.chs" #-}


deriving instance Show Transaction
deriving instance Storable Transaction

databaseCreateTransaction :: (DatabasePtr) -> IO ((CFDBError), (Transaction))
databaseCreateTransaction :: DatabasePtr -> IO (CFDBError, Transaction)
databaseCreateTransaction DatabasePtr
a1 =
  let {a1' :: DatabasePtr
a1' = DatabasePtr -> DatabasePtr
forall a. a -> a
id DatabasePtr
a1} in 
  (Ptr Transaction -> IO (CFDBError, Transaction))
-> IO (CFDBError, Transaction)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr Transaction -> IO (CFDBError, Transaction))
 -> IO (CFDBError, Transaction))
-> (Ptr Transaction -> IO (CFDBError, Transaction))
-> IO (CFDBError, Transaction)
forall a b. (a -> b) -> a -> b
$ \Ptr Transaction
a2' -> 
  DatabasePtr -> Ptr Transaction -> IO CInt
databaseCreateTransaction'_ DatabasePtr
a1' Ptr Transaction
a2' IO CInt
-> (CInt -> IO (CFDBError, Transaction))
-> IO (CFDBError, Transaction)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: CFDBError
res' = CInt -> CFDBError
CFDBError CInt
res} in
  Ptr Transaction -> IO Transaction
forall a. Storable a => Ptr a -> IO a
peek  Ptr Transaction
a2'IO Transaction
-> (Transaction -> IO (CFDBError, Transaction))
-> IO (CFDBError, Transaction)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Transaction
a2'' -> 
  (CFDBError, Transaction) -> IO (CFDBError, Transaction)
forall (m :: * -> *) a. Monad m => a -> m a
return (CFDBError
res', Transaction
a2'')

{-# LINE 544 "src/FoundationDB/Internal/Bindings.chs" #-}



foreign import capi "fdbc_wrapper.h &fdb_transaction_destroy"
  transactionDestroyPtr :: FunPtr (Ptr a -> IO ())

transactionDestroy :: (Transaction) -> IO ()
transactionDestroy a1 =
  let {a1' = id a1} in 
  transactionDestroy'_ a1' >>
  return ()

{-# LINE 550 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionSetOption_ :: (Transaction) -> (Int) -> (Ptr CUChar) -> (Int) -> IO ((CFDBError))
transactionSetOption_ a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = id a3} in 
  let {a4' = fromIntegral a4} in 
  transactionSetOption_'_ a1' a2' a3' a4' >>= \res ->
  let {res' = CFDBError res} in
  return (res')

{-# LINE 554 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionSetOption :: Transaction -> TransactionOption -> IO CFDBError
transactionSetOption t (TransactionOptionString enum str) =
  withCStringLen str $ \(arr, len) ->
    transactionSetOption_ t enum (castPtr arr) len
transactionSetOption t (TransactionOptionInt enum i) = alloca $ \iptr ->
  do poke iptr i
     transactionSetOption_ t enum (castPtr iptr) (sizeOf i)
transactionSetOption Transaction
t (TransactionOptionBytes Int
enum ByteString
bs) =
  ByteString -> (CStringLen -> IO CFDBError) -> IO CFDBError
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
bs ((CStringLen -> IO CFDBError) -> IO CFDBError)
-> (CStringLen -> IO CFDBError) -> IO CFDBError
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
arr, Int
len) ->
    Transaction -> Int -> Ptr CUChar -> Int -> IO CFDBError
transactionSetOption_ Transaction
t Int
enum (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
arr) Int
len
transactionSetOption Transaction
t (TransactionOptionFlag Int
enum) =
  Transaction -> Int -> Ptr CUChar -> Int -> IO CFDBError
transactionSetOption_ Transaction
t Int
enum Ptr CUChar
forall a. Ptr a
nullPtr Int
0

transactionGetReadVersion :: (Transaction) -> IO ((Future Int64))
transactionGetReadVersion :: Transaction -> IO (Future Int64)
transactionGetReadVersion Transaction
a1 =
  let {a1' :: Transaction
a1' = Transaction -> Transaction
forall a. a -> a
id Transaction
a1} in 
  Transaction -> IO (Ptr ())
transactionGetReadVersion'_ Transaction
a1' IO (Ptr ()) -> (Ptr () -> IO (Future Int64)) -> IO (Future Int64)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr ()
res ->
  let {res' :: Future a
res' = Ptr () -> Future a
forall a. Ptr () -> Future a
outFuture Ptr ()
res} in
  Future Int64 -> IO (Future Int64)
forall (m :: * -> *) a. Monad m => a -> m a
return (Future Int64
forall a. Future a
res')

{-# LINE 570 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionSetReadVersion :: (Transaction) -> (Int64) -> IO ()
transactionSetReadVersion a1 a2 =
  let {a1' = id a1} in 
  let {a2' = fromIntegral a2} in 
  transactionSetReadVersion'_ a1' a2' >>
  return ()

{-# LINE 573 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionGet_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> (Bool) -> IO ((Future a))
transactionGet_ a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = C2HSImp.fromBool a4} in 
  transactionGet_'_ a1' a2' a3' a4' >>= \res ->
  let {res' = outFuture res} in
  return (res')

{-# LINE 576 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionGet :: Transaction
               -> B.ByteString
               -> Bool
               -> IO (Future (Maybe B.ByteString))
transactionGet t k isSnapshotRead = B.useAsCStringLen k $ \(kstr,klen) ->
  transactionGet_ t (castPtr kstr) klen isSnapshotRead

transactionGetKey_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> (Bool) -> (Int) -> (Bool) -> IO ((Future a))
transactionGetKey_ :: Transaction
-> Ptr CUChar -> Int -> Bool -> Int -> Bool -> IO (Future a)
transactionGetKey_ Transaction
a1 Ptr CUChar
a2 Int
a3 Bool
a4 Int
a5 Bool
a6 =
  let {a1' :: Transaction
a1' = Transaction -> Transaction
forall a. a -> a
id Transaction
a1} in 
  let {a2' :: Ptr CUChar
a2' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a2} in 
  let {a3' :: CInt
a3' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  let {a4' :: CInt
a4' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a4} in 
  let {a5' :: CInt
a5' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a5} in 
  let {a6' :: CInt
a6' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a6} in 
  Transaction
-> Ptr CUChar -> CInt -> CInt -> CInt -> CInt -> IO (Ptr ())
transactionGetKey_'_ Transaction
a1' Ptr CUChar
a2' CInt
a3' CInt
a4' CInt
a5' CInt
a6' IO (Ptr ()) -> (Ptr () -> IO (Future a)) -> IO (Future a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr ()
res ->
  let {res' :: Future a
res' = Ptr () -> Future a
forall a. Ptr () -> Future a
outFuture Ptr ()
res} in
  Future a -> IO (Future a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Future a
forall a. Future a
res')

{-# LINE 587 "src/FoundationDB/Internal/Bindings.chs" #-}


-- | Specifies a key in the database. See the official
-- <https://apple.github.io/foundationdb/developer-guide.html#key-selectors docs>
-- for more information. These can be supplied to 'getKey' or used to build a
-- 'Range'.
data KeySelector =
  LastLessThan B.ByteString
  -- ^ Selects the lexicographically greatest key less than the specified key.
  | LastLessOrEq B.ByteString
  -- ^ Selects the lexicographically greatest less than or equal to the
  -- specified key.
  | FirstGreaterThan B.ByteString
  -- ^ Selects the lexicographically least key greater than the specified key.
  | FirstGreaterOrEq B.ByteString
  -- ^ Selects the lexicographically least key greater than or equal to the
  -- specified key.
  | WithOffset Int KeySelector
  -- ^ offsets a key selector. Using 'offset' is preferred, since it handles
  -- normalization to prevent nested 'WithOffset's.
  deriving (Int -> KeySelector -> ShowS
[KeySelector] -> ShowS
KeySelector -> String
(Int -> KeySelector -> ShowS)
-> (KeySelector -> String)
-> ([KeySelector] -> ShowS)
-> Show KeySelector
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KeySelector] -> ShowS
$cshowList :: [KeySelector] -> ShowS
show :: KeySelector -> String
$cshow :: KeySelector -> String
showsPrec :: Int -> KeySelector -> ShowS
$cshowsPrec :: Int -> KeySelector -> ShowS
Show, KeySelector -> KeySelector -> Bool
(KeySelector -> KeySelector -> Bool)
-> (KeySelector -> KeySelector -> Bool) -> Eq KeySelector
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KeySelector -> KeySelector -> Bool
$c/= :: KeySelector -> KeySelector -> Bool
== :: KeySelector -> KeySelector -> Bool
$c== :: KeySelector -> KeySelector -> Bool
Eq, Eq KeySelector
Eq KeySelector
-> (KeySelector -> KeySelector -> Ordering)
-> (KeySelector -> KeySelector -> Bool)
-> (KeySelector -> KeySelector -> Bool)
-> (KeySelector -> KeySelector -> Bool)
-> (KeySelector -> KeySelector -> Bool)
-> (KeySelector -> KeySelector -> KeySelector)
-> (KeySelector -> KeySelector -> KeySelector)
-> Ord KeySelector
KeySelector -> KeySelector -> Bool
KeySelector -> KeySelector -> Ordering
KeySelector -> KeySelector -> KeySelector
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: KeySelector -> KeySelector -> KeySelector
$cmin :: KeySelector -> KeySelector -> KeySelector
max :: KeySelector -> KeySelector -> KeySelector
$cmax :: KeySelector -> KeySelector -> KeySelector
>= :: KeySelector -> KeySelector -> Bool
$c>= :: KeySelector -> KeySelector -> Bool
> :: KeySelector -> KeySelector -> Bool
$c> :: KeySelector -> KeySelector -> Bool
<= :: KeySelector -> KeySelector -> Bool
$c<= :: KeySelector -> KeySelector -> Bool
< :: KeySelector -> KeySelector -> Bool
$c< :: KeySelector -> KeySelector -> Bool
compare :: KeySelector -> KeySelector -> Ordering
$ccompare :: KeySelector -> KeySelector -> Ordering
$cp1Ord :: Eq KeySelector
Ord)

keySelectorBytes :: KeySelector -> B.ByteString
keySelectorBytes :: KeySelector -> ByteString
keySelectorBytes (LastLessThan ByteString
bs) = ByteString
bs
keySelectorBytes (LastLessOrEq ByteString
bs) = ByteString
bs
keySelectorBytes (FirstGreaterThan ByteString
bs) = ByteString
bs
keySelectorBytes (FirstGreaterOrEq ByteString
bs) = ByteString
bs
keySelectorBytes (WithOffset Int
_ KeySelector
ks) = KeySelector -> ByteString
keySelectorBytes KeySelector
ks

-- | Convert a 'KeySelector' to its or_equal, offset settings. Equivalent to
-- the macros @FDB_KEYSEL_LAST_LESS_THAN@ etc.
keySelectorTuple :: KeySelector -> (B.ByteString, Bool, Int)
keySelectorTuple :: KeySelector -> (ByteString, Bool, Int)
keySelectorTuple (LastLessThan ByteString
bs) = (ByteString
bs, Bool
False, Int
0)
keySelectorTuple (LastLessOrEq ByteString
bs) = (ByteString
bs, Bool
True, Int
0)
keySelectorTuple (FirstGreaterThan ByteString
bs) = (ByteString
bs, Bool
True, Int
1)
keySelectorTuple (FirstGreaterOrEq ByteString
bs) = (ByteString
bs, Bool
False, Int
1)
keySelectorTuple (WithOffset Int
n KeySelector
ks) =
  (\(ByteString
x,Bool
y,Int
z) -> (ByteString
x, Bool
y, Int
zInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
n)) (KeySelector -> (ByteString, Bool, Int)
keySelectorTuple KeySelector
ks)

-- | Inverse of 'keySelectorTuple'
tupleKeySelector :: (B.ByteString, Bool, Int) -> KeySelector
tupleKeySelector :: (ByteString, Bool, Int) -> KeySelector
tupleKeySelector (ByteString
bs, Bool
False, Int
0) = ByteString -> KeySelector
LastLessThan ByteString
bs
tupleKeySelector (ByteString
bs, Bool
True, Int
0) = ByteString -> KeySelector
LastLessOrEq ByteString
bs
tupleKeySelector (ByteString
bs, Bool
True, Int
1) = ByteString -> KeySelector
FirstGreaterThan ByteString
bs
tupleKeySelector (ByteString
bs, Bool
False, Int
1) = ByteString -> KeySelector
FirstGreaterOrEq ByteString
bs
tupleKeySelector (ByteString
bs, Bool
b, Int
n) = Int -> KeySelector -> KeySelector
WithOffset Int
n (KeySelector -> KeySelector) -> KeySelector -> KeySelector
forall a b. (a -> b) -> a -> b
$ (ByteString, Bool, Int) -> KeySelector
tupleKeySelector (ByteString
bs, Bool
b, Int
0)

transactionGetKey :: Transaction
                  -> B.ByteString
                  -> Bool
                  -> Int
                  -> Bool
                  -> IO (Future B.ByteString)
transactionGetKey :: Transaction
-> ByteString -> Bool -> Int -> Bool -> IO (Future ByteString)
transactionGetKey Transaction
t ByteString
k Bool
orEqual Int
offset Bool
isSnapshotRead =
  ByteString
-> (CStringLen -> IO (Future ByteString)) -> IO (Future ByteString)
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
k ((CStringLen -> IO (Future ByteString)) -> IO (Future ByteString))
-> (CStringLen -> IO (Future ByteString)) -> IO (Future ByteString)
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
kstr, Int
klen) ->
    Transaction
-> Ptr CUChar
-> Int
-> Bool
-> Int
-> Bool
-> IO (Future ByteString)
forall a.
Transaction
-> Ptr CUChar -> Int -> Bool -> Int -> Bool -> IO (Future a)
transactionGetKey_ Transaction
t (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
kstr) Int
klen Bool
orEqual Int
offset Bool
isSnapshotRead

transactionGetAddressForKey_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> IO ((Future a))
transactionGetAddressForKey_ :: Transaction -> Ptr CUChar -> Int -> IO (Future a)
transactionGetAddressForKey_ Transaction
a1 Ptr CUChar
a2 Int
a3 =
  let {a1' :: Transaction
a1' = Transaction -> Transaction
forall a. a -> a
id Transaction
a1} in 
  let {a2' :: Ptr CUChar
a2' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a2} in 
  let {a3' :: CInt
a3' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  Transaction -> Ptr CUChar -> CInt -> IO (Ptr ())
transactionGetAddressForKey_'_ Transaction
a1' Ptr CUChar
a2' CInt
a3' IO (Ptr ()) -> (Ptr () -> IO (Future a)) -> IO (Future a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr ()
res ->
  let {res' :: Future a
res' = Ptr () -> Future a
forall a. Ptr () -> Future a
outFuture Ptr ()
res} in
  Future a -> IO (Future a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Future a
forall a. Future a
res')

{-# LINE 647 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionGetAddressesForKey :: Transaction
                              -> B.ByteString
                              -> IO (Future [B.ByteString])
transactionGetAddressesForKey t k = B.useAsCStringLen k $ \(kstr, klen) ->
  transactionGetAddressForKey_ t (castPtr kstr) klen

data FDBStreamingMode = StreamingModeWantAll
                      | StreamingModeIterator
                      | StreamingModeExact
                      | StreamingModeSmall
                      | StreamingModeMedium
                      | StreamingModeLarge
                      | StreamingModeSerial
instance Enum FDBStreamingMode where
  succ StreamingModeWantAll = StreamingModeIterator
  succ StreamingModeIterator = StreamingModeExact
  succ StreamingModeExact = StreamingModeSmall
  succ StreamingModeSmall = StreamingModeMedium
  succ StreamingModeMedium = StreamingModeLarge
  succ StreamingModeLarge = StreamingModeSerial
  succ StreamingModeSerial = error "FDBStreamingMode.succ: StreamingModeSerial has no successor"

  pred StreamingModeIterator = StreamingModeWantAll
  pred StreamingModeExact = StreamingModeIterator
  pred StreamingModeSmall = StreamingModeExact
  pred StreamingModeMedium = StreamingModeSmall
  pred StreamingModeLarge = StreamingModeMedium
  pred StreamingModeSerial = StreamingModeLarge
  pred StreamingModeWantAll = error "FDBStreamingMode.pred: StreamingModeWantAll 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 :: FDBStreamingMode -> [FDBStreamingMode]
enumFrom FDBStreamingMode
from = FDBStreamingMode -> FDBStreamingMode -> [FDBStreamingMode]
forall a. Enum a => a -> a -> [a]
enumFromTo FDBStreamingMode
from FDBStreamingMode
StreamingModeSerial

  fromEnum :: FDBStreamingMode -> Int
fromEnum FDBStreamingMode
StreamingModeWantAll = (-Int
2)
  fromEnum FDBStreamingMode
StreamingModeIterator = (-Int
1)
  fromEnum FDBStreamingMode
StreamingModeExact = Int
0
  fromEnum FDBStreamingMode
StreamingModeSmall = Int
1
  fromEnum FDBStreamingMode
StreamingModeMedium = Int
2
  fromEnum FDBStreamingMode
StreamingModeLarge = Int
3
  fromEnum FDBStreamingMode
StreamingModeSerial = Int
4

  toEnum :: Int -> FDBStreamingMode
toEnum (-2) = FDBStreamingMode
StreamingModeWantAll
  toEnum (-1) = FDBStreamingMode
StreamingModeIterator
  toEnum Int
0 = FDBStreamingMode
StreamingModeExact
  toEnum Int
1 = FDBStreamingMode
StreamingModeSmall
  toEnum Int
2 = FDBStreamingMode
StreamingModeMedium
  toEnum Int
3 = FDBStreamingMode
StreamingModeLarge
  toEnum Int
4 = FDBStreamingMode
StreamingModeSerial
  toEnum Int
unmatched = String -> FDBStreamingMode
forall a. HasCallStack => String -> a
error (String
"FDBStreamingMode.toEnum: Cannot match " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
unmatched)

{-# LINE 655 "src/FoundationDB/Internal/Bindings.chs" #-}


deriving instance Eq FDBStreamingMode
deriving instance Ord FDBStreamingMode
deriving instance Bounded FDBStreamingMode
deriving instance Show FDBStreamingMode

transactionGetRange_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> (Bool) -> (Int) -> (Ptr CUChar) -> (Int) -> (Bool) -> (Int) -> (Int) -> (Int) -> (FDBStreamingMode) -> (Int) -> (Bool) -> (Bool) -> IO ((Future a))
transactionGetRange_ a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = C2HSImp.fromBool a4} in 
  let {a5' = fromIntegral a5} in 
  let {a6' = id a6} in 
  let {a7' = fromIntegral a7} in 
  let {a8' = C2HSImp.fromBool a8} in 
  let {a9' = fromIntegral a9} in 
  let {a10' = fromIntegral a10} in 
  let {a11' = fromIntegral a11} in 
  let {a12' = (fromIntegral . fromEnum) a12} in 
  let {a13' = fromIntegral a13} in 
  let {a14' = C2HSImp.fromBool a14} in 
  let {a15' = C2HSImp.fromBool a15} in 
  transactionGetRange_'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' a13' a14' a15' >>= \res ->
  let {res' = outFuture res} in
  return (res')

{-# LINE 672 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionGetRange :: Transaction
                    -> KeySelector
                    -- ^ begin
                    -> KeySelector
                    -- ^ end
                    -> Int
                    -- ^ max number of pairs to return
                    -> Int
                    -- ^ max number of bytes to return
                    -> FDBStreamingMode
                    -> Int
                    -- ^ if FDBStreamingMode is FdbStreamingModeIterator,
                    -- start this at 1 and increment by for each successive
                    -- call reading this range. Otherwise, ignored.
                    -> Bool
                    -- ^ isSnapshotRead
                    -> Bool
                    -- ^ whether to return pairs in reverse order
                    -> IO (Future [(B.ByteString, B.ByteString)])
transactionGetRange t rangeBegin
                      rangeEnd
                      pairLimit byteLimit
                      streamMode iteratorI
                      isSnapshotRead isReverse =
  let (bk, bOrEqual, bOffset) = keySelectorTuple rangeBegin
      (ek, eOrEqual, eOffset) = keySelectorTuple rangeEnd
  in
  B.useAsCStringLen bk $ \(bstr, blen) ->
  B.useAsCStringLen ek $ \(estr, elen) ->
  transactionGetRange_ t
                       (castPtr bstr) blen bOrEqual bOffset
                       (castPtr estr) elen eOrEqual eOffset
                       pairLimit byteLimit
                       streamMode iteratorI
                       isSnapshotRead isReverse

transactionSet_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> (Ptr CUChar) -> (Int) -> IO ()
transactionSet_ :: Transaction -> Ptr CUChar -> Int -> Ptr CUChar -> Int -> IO ()
transactionSet_ Transaction
a1 Ptr CUChar
a2 Int
a3 Ptr CUChar
a4 Int
a5 =
  let {a1' :: Transaction
a1' = Transaction -> Transaction
forall a. a -> a
id Transaction
a1} in 
  let {a2' :: Ptr CUChar
a2' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a2} in 
  let {a3' :: CInt
a3' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  let {a4' :: Ptr CUChar
a4' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a4} in 
  let {a5' :: CInt
a5' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a5} in 
  transactionSet_'_ a1' a2' a3' a4' a5' >>
  return ()

{-# LINE 714 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionSet :: Transaction -> B.ByteString -> B.ByteString -> IO ()
transactionSet t k v =
  B.useAsCStringLen k $ \(kstr, klen) ->
  B.useAsCStringLen v $ \(vstr, vlen) ->
  transactionSet_ t (castPtr kstr) klen (castPtr vstr) vlen

transactionClear_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> IO ()
transactionClear_ :: Transaction -> Ptr CUChar -> Int -> IO ()
transactionClear_ Transaction
a1 Ptr CUChar
a2 Int
a3 =
  let {a1' :: Transaction
a1' = Transaction -> Transaction
forall a. a -> a
id Transaction
a1} in 
  let {a2' :: Ptr CUChar
a2' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a2} in 
  let {a3' :: CInt
a3' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  Transaction -> Ptr CUChar -> CInt -> IO ()
transactionClear_'_ Transaction
a1' Ptr CUChar
a2' CInt
a3' IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

{-# LINE 724 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionClear :: Transaction -> B.ByteString -> IO ()
transactionClear t k = B.useAsCStringLen k $ \(kstr, klen) ->
  transactionClear_ t (castPtr kstr) klen

transactionClearRange_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> (Ptr CUChar) -> (Int) -> IO ()
transactionClearRange_ :: Transaction -> Ptr CUChar -> Int -> Ptr CUChar -> Int -> IO ()
transactionClearRange_ Transaction
a1 Ptr CUChar
a2 Int
a3 Ptr CUChar
a4 Int
a5 =
  let {a1' :: Transaction
a1' = Transaction -> Transaction
forall a. a -> a
id Transaction
a1} in 
  let {a2' :: Ptr CUChar
a2' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a2} in 
  let {a3' :: CInt
a3' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  let {a4' :: Ptr CUChar
a4' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a4} in 
  let {a5' :: CInt
a5' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a5} in 
  transactionClearRange_'_ a1' a2' a3' a4' a5' >>
  return ()

{-# LINE 734 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionClearRange :: Transaction -> B.ByteString -> B.ByteString -> IO ()
transactionClearRange t greaterOrEqBound lessThanBound =
  B.useAsCStringLen greaterOrEqBound $ \(minstr, minlen) ->
  B.useAsCStringLen lessThanBound $ \(maxstr, maxlen) ->
  transactionClearRange_ t (castPtr minstr) minlen (castPtr maxstr) maxlen

transactionAtomicOp_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> (Ptr CUChar) -> (Int) -> (Int) -> IO ()
transactionAtomicOp_ :: Transaction
-> Ptr CUChar -> Int -> Ptr CUChar -> Int -> Int -> IO ()
transactionAtomicOp_ Transaction
a1 Ptr CUChar
a2 Int
a3 Ptr CUChar
a4 Int
a5 Int
a6 =
  let {a1' :: Transaction
a1' = Transaction -> Transaction
forall a. a -> a
id Transaction
a1} in 
  let {a2' :: Ptr CUChar
a2' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a2} in 
  let {a3' :: CInt
a3' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  let {a4' :: Ptr CUChar
a4' = Ptr CUChar -> Ptr CUChar
forall a. a -> a
id Ptr CUChar
a4} in 
  let {a5' :: CInt
a5' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a5} in 
  let {a6' :: CInt
a6' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a6} in 
  Transaction
-> Ptr CUChar -> CInt -> Ptr CUChar -> CInt -> CInt -> IO ()
transactionAtomicOp_'_ Transaction
a1' Ptr CUChar
a2' CInt
a3' Ptr CUChar
a4' CInt
a5' CInt
a6' IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

{-# LINE 747 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionAtomicOp :: Transaction
                    -> B.ByteString
                    -- ^ key
                    -> MutationType
                    -> IO ()
transactionAtomicOp :: Transaction -> ByteString -> MutationType -> IO ()
transactionAtomicOp Transaction
t ByteString
k (MutationTypeBytes Int
i ByteString
arg) =
  ByteString -> (CStringLen -> IO ()) -> IO ()
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
k ((CStringLen -> IO ()) -> IO ()) -> (CStringLen -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
kstr, Int
klen) ->
  ByteString -> (CStringLen -> IO ()) -> IO ()
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
arg ((CStringLen -> IO ()) -> IO ()) -> (CStringLen -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \(Ptr CChar
argstr, Int
arglen) ->
  Transaction
-> Ptr CUChar -> Int -> Ptr CUChar -> Int -> Int -> IO ()
transactionAtomicOp_ Transaction
t
                       (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
kstr)
                       Int
klen
                       (Ptr CChar -> Ptr CUChar
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
argstr)
                       Int
arglen
                       Int
i
transactionAtomicOp Transaction
_ ByteString
_ MutationType
_ = String -> IO ()
forall a. HasCallStack => String -> a
error String
"impossible case in transactionAtomicOp"

transactionCommit :: (Transaction) -> IO ((Future ()))
transactionCommit :: Transaction -> IO (Future ())
transactionCommit Transaction
a1 =
  let {a1' :: Transaction
a1' = Transaction -> Transaction
forall a. a -> a
id Transaction
a1} in 
  Transaction -> IO (Ptr ())
transactionCommit'_ Transaction
a1' IO (Ptr ()) -> (Ptr () -> IO (Future ())) -> IO (Future ())
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr ()
res ->
  let {res' :: Future a
res' = Ptr () -> Future a
forall a. Ptr () -> Future a
outFuture Ptr ()
res} in
  Future () -> IO (Future ())
forall (m :: * -> *) a. Monad m => a -> m a
return (Future ()
forall a. Future a
res')

{-# LINE 766 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionGetCommittedVersion :: (Transaction) -> IO ((CFDBError), (Int))
transactionGetCommittedVersion a1 =
  let {a1' = id a1} in 
  alloca $ \a2' -> 
  transactionGetCommittedVersion'_ a1' a2' >>= \res ->
  let {res' = CFDBError res} in
  peekIntegral  a2'>>= \a2'' -> 
  return (res', a2'')

{-# LINE 769 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionGetApproximateSize :: (Transaction) -> IO ((Future Int64))
transactionGetApproximateSize a1 =
  let {a1' = id a1} in 
  transactionGetApproximateSize'_ a1' >>= \res ->
  let {res' = outFuture res} in
  return (res')

{-# LINE 774 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionGetVersionstamp :: (Transaction) -> IO ((Future B.ByteString))
transactionGetVersionstamp a1 =
  let {a1' = id a1} in 
  transactionGetVersionstamp'_ a1' >>= \res ->
  let {res' = outFuture res} in
  return (res')

{-# LINE 777 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionWatch_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> IO ((Future a))
transactionWatch_ a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  transactionWatch_'_ a1' a2' a3' >>= \Ptr ()
res ->
  let {res' :: Future a
res' = Ptr () -> Future a
forall a. Ptr () -> Future a
outFuture Ptr ()
res} in
  Future a -> IO (Future a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Future a
forall a. Future a
res')

{-# LINE 781 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionWatch :: Transaction -> B.ByteString -> IO (Future ())
transactionWatch t k = B.useAsCStringLen k $ \(kstr, klen) ->
  transactionWatch_ t (castPtr kstr) klen

transactionOnError :: (Transaction) -> (CFDBError) -> IO ((Future ()))
transactionOnError a1 a2 =
  let {a1' = id a1} in 
  let {a2' = getCFDBError a2} in 
  transactionOnError'_ a1' a2' >>= \res ->
  let {res' = outFuture res} in
  return (res')

{-# LINE 789 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionReset :: (Transaction) -> IO ()
transactionReset a1 =
  let {a1' = id a1} in 
  transactionReset'_ a1' >>
  return ()

{-# LINE 792 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionCancel :: (Transaction) -> IO ()
transactionCancel a1 =
  let {a1' = id a1} in 
  transactionCancel'_ a1' >>
  return ()

{-# LINE 795 "src/FoundationDB/Internal/Bindings.chs" #-}


data FDBConflictRangeType = ConflictRangeTypeRead
                          | ConflictRangeTypeWrite
instance Enum FDBConflictRangeType where
  succ ConflictRangeTypeRead = ConflictRangeTypeWrite
  succ ConflictRangeTypeWrite = error "FDBConflictRangeType.succ: ConflictRangeTypeWrite has no successor"

  pred ConflictRangeTypeWrite = ConflictRangeTypeRead
  pred ConflictRangeTypeRead = error "FDBConflictRangeType.pred: ConflictRangeTypeRead 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 ConflictRangeTypeWrite

  fromEnum ConflictRangeTypeRead = 0
  fromEnum ConflictRangeTypeWrite = 1

  toEnum 0 = ConflictRangeTypeRead
  toEnum 1 = ConflictRangeTypeWrite
  toEnum unmatched = error ("FDBConflictRangeType.toEnum: Cannot match " ++ show unmatched)

{-# LINE 797 "src/FoundationDB/Internal/Bindings.chs" #-}


deriving instance Eq FDBConflictRangeType
deriving instance Ord FDBConflictRangeType
deriving instance Show FDBConflictRangeType

transactionAddConflictRange_ :: (Transaction) -> (Ptr CUChar) -> (Int) -> (Ptr CUChar) -> (Int) -> (FDBConflictRangeType) -> IO ((CFDBError))
transactionAddConflictRange_ a1 a2 a3 a4 a5 a6 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = id a4} in 
  let {a5' = fromIntegral a5} in 
  let {a6' = (fromIntegral . fromEnum) a6} in 
  transactionAddConflictRange_'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  let {res' = CFDBError res} in
  return (res')

{-# LINE 808 "src/FoundationDB/Internal/Bindings.chs" #-}


transactionAddConflictRange :: Transaction
                            -> B.ByteString
                            -> B.ByteString
                            -> FDBConflictRangeType
                            -> IO CFDBError
transactionAddConflictRange t begin end conflictRangeType =
  B.useAsCStringLen begin $ \(beginstr, beginlen) ->
  B.useAsCStringLen end $ \(endstr, endlen) ->
  transactionAddConflictRange_ t
                               (castPtr beginstr) beginlen
                               (castPtr endstr) endlen
                               conflictRangeType

getError :: (CFDBError) -> IO ((String))
getError :: CFDBError -> IO String
getError CFDBError
a1 =
  let {a1' :: CInt
a1' = CFDBError -> CInt
getCFDBError CFDBError
a1} in 
  CInt -> IO (Ptr CChar)
getError'_ CInt
a1' IO (Ptr CChar) -> (Ptr CChar -> IO String) -> IO String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CChar
res ->
  Ptr CChar -> IO String
C2HSImp.peekCString Ptr CChar
res IO String -> (String -> IO String) -> IO String
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \String
res' ->
  String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return (String
res')

{-# LINE 823 "src/FoundationDB/Internal/Bindings.chs" #-}


data FDBErrorPredicate = ErrorPredicateRetryable
                       | ErrorPredicateMaybeCommitted
                       | ErrorPredicateRetryableNotCommitted
instance Enum FDBErrorPredicate where
  succ ErrorPredicateRetryable = ErrorPredicateMaybeCommitted
  succ ErrorPredicateMaybeCommitted = ErrorPredicateRetryableNotCommitted
  succ ErrorPredicateRetryableNotCommitted = error "FDBErrorPredicate.succ: ErrorPredicateRetryableNotCommitted has no successor"

  pred ErrorPredicateMaybeCommitted = ErrorPredicateRetryable
  pred ErrorPredicateRetryableNotCommitted = ErrorPredicateMaybeCommitted
  pred ErrorPredicateRetryable = error "FDBErrorPredicate.pred: ErrorPredicateRetryable has no predecessor"

  enumFromTo :: FDBErrorPredicate -> FDBErrorPredicate -> [FDBErrorPredicate]
enumFromTo FDBErrorPredicate
from FDBErrorPredicate
to = FDBErrorPredicate -> [FDBErrorPredicate]
forall t. Enum t => t -> [t]
go FDBErrorPredicate
from
    where
      end :: Int
end = FDBErrorPredicate -> Int
forall a. Enum a => a -> Int
fromEnum FDBErrorPredicate
to
      go :: t -> [t]
go t
v = case Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (t -> Int
forall a. Enum a => a -> Int
fromEnum t
v) Int
end of
                 Ordering
LT -> t
v t -> [t] -> [t]
forall a. a -> [a] -> [a]
: t -> [t]
go (t -> t
forall a. Enum a => a -> a
succ t
v)
                 Ordering
EQ -> [t
v]
                 Ordering
GT -> []

  enumFrom :: FDBErrorPredicate -> [FDBErrorPredicate]
enumFrom FDBErrorPredicate
from = FDBErrorPredicate -> FDBErrorPredicate -> [FDBErrorPredicate]
forall a. Enum a => a -> a -> [a]
enumFromTo FDBErrorPredicate
from FDBErrorPredicate
ErrorPredicateRetryableNotCommitted

  fromEnum :: FDBErrorPredicate -> Int
fromEnum FDBErrorPredicate
ErrorPredicateRetryable = Int
50000
  fromEnum FDBErrorPredicate
ErrorPredicateMaybeCommitted = Int
50001
  fromEnum FDBErrorPredicate
ErrorPredicateRetryableNotCommitted = Int
50002

  toEnum :: Int -> FDBErrorPredicate
toEnum Int
50000 = FDBErrorPredicate
ErrorPredicateRetryable
  toEnum Int
50001 = FDBErrorPredicate
ErrorPredicateMaybeCommitted
  toEnum Int
50002 = FDBErrorPredicate
ErrorPredicateRetryableNotCommitted
  toEnum Int
unmatched = String -> FDBErrorPredicate
forall a. HasCallStack => String -> a
error (String
"FDBErrorPredicate.toEnum: Cannot match " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
unmatched)

{-# LINE 825 "src/FoundationDB/Internal/Bindings.chs" #-}


deriving instance Eq FDBErrorPredicate
deriving instance Ord FDBErrorPredicate
deriving instance Show FDBErrorPredicate

errorPredicate :: (FDBErrorPredicate) -> (CFDBError) -> (Bool)
errorPredicate a1 a2 =
  C2HSImp.unsafePerformIO $
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = getCFDBError a2} in 
  errorPredicate'_ a1' a2' >>= \res ->
  let {res' = C2HSImp.toBool res} in
  return (res')

{-# LINE 833 "src/FoundationDB/Internal/Bindings.chs" #-}


-- NOTE: Pre 6.1.x, there was an intermediate cluster type we had to create
-- before we could create a database object.


foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h select_api_version"
  selectAPIVersion'_ :: (C2HSImp.CInt -> (IO C2HSImp.CInt))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_setup_network"
  setupNetwork'_ :: (IO C2HSImp.CInt)

foreign import ccall safe "FoundationDB/Internal/Bindings.chs.h fdb_run_network"
  runNetwork'_ :: (IO C2HSImp.CInt)

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_stop_network"
  stopNetwork'_ :: (IO C2HSImp.CInt)

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_network_set_option"
  networkSetOption_'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_cancel"
  futureCancel'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_destroy"
  futureDestroy'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall safe "FoundationDB/Internal/Bindings.chs.h fdb_future_block_until_ready"
  futureBlockUntilReady'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_is_ready"
  futureIsReady'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_release_memory"
  futureReleaseMemory'_ :: ((C2HSImp.Ptr ()) -> (IO ()))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_get_error"
  futureGetError'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_get_int64"
  futureGetInt64'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CLong) -> (IO C2HSImp.CInt)))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_get_key"
  futureGetKey_'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CUChar)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO C2HSImp.CInt))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_get_value"
  futureGetValue_'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CUChar)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO C2HSImp.CInt)))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_get_string_array"
  futureGetStringArray_'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar))) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO C2HSImp.CInt))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h get_mapped_range_result"
  getMappedRangeResult_'_ :: ((MappedKeyValuePtr) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CUChar)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CUChar)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CUChar)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CUChar)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO ()))))))))))))))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_future_get_mappedkeyvalue_array"
  futureGetMappedkeyvalueArray'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (MappedKeyValuePtr)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO C2HSImp.CInt)))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h get_mapped_key_value_size"
  getMappedKeyValueSize'_ :: (IO C2HSImp.CInt)

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_create_database"
  createDatabase'_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (DatabasePtr)) -> (IO C2HSImp.CInt)))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_database_destroy"
  databaseDestroy'_ :: ((DatabasePtr) -> (IO ()))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_database_set_option"
  databaseSetOption_'_ :: ((DatabasePtr) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_database_create_transaction"
  databaseCreateTransaction'_ :: ((DatabasePtr) -> ((C2HSImp.Ptr (Transaction)) -> (IO C2HSImp.CInt)))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_destroy"
  transactionDestroy'_ :: ((Transaction) -> (IO ()))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_set_option"
  transactionSetOption_'_ :: ((Transaction) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_get_read_version"
  transactionGetReadVersion'_ :: ((Transaction) -> (IO (C2HSImp.Ptr ())))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_set_read_version"
  transactionSetReadVersion'_ :: ((Transaction) -> (C2HSImp.CLong -> (IO ())))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_get"
  transactionGet_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ()))))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_get_key"
  transactionGetKey_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ()))))))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_get_addresses_for_key"
  transactionGetAddressForKey_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ())))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_get_range"
  transactionGetRange_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ())))))))))))))))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_set"
  transactionSet_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (IO ()))))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_clear"
  transactionClear_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (IO ()))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_clear_range"
  transactionClearRange_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (IO ()))))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_atomic_op"
  transactionAtomicOp_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO ())))))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_commit"
  transactionCommit'_ :: ((Transaction) -> (IO (C2HSImp.Ptr ())))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_get_committed_version"
  transactionGetCommittedVersion'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CLong) -> (IO C2HSImp.CInt)))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_get_approximate_size"
  transactionGetApproximateSize'_ :: ((Transaction) -> (IO (C2HSImp.Ptr ())))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_get_versionstamp"
  transactionGetVersionstamp'_ :: ((Transaction) -> (IO (C2HSImp.Ptr ())))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_watch"
  transactionWatch_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ())))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_on_error"
  transactionOnError'_ :: ((Transaction) -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr ()))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_reset"
  transactionReset'_ :: ((Transaction) -> (IO ()))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_cancel"
  transactionCancel'_ :: ((Transaction) -> (IO ()))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_transaction_add_conflict_range"
  transactionAddConflictRange_'_ :: ((Transaction) -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CUChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_get_error"
  getError'_ :: (C2HSImp.CInt -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

foreign import ccall unsafe "FoundationDB/Internal/Bindings.chs.h fdb_error_predicate"
  errorPredicate'_ :: (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))