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


{-# LINE 1 "src/Kafka/Internal/RdKafka.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE EmptyDataDecls #-}

module Kafka.Internal.RdKafka where
import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Storable as C2HSImp
import qualified System.IO.Unsafe as C2HSImp



import Data.Text (Text)
import qualified Data.Text as Text
import Control.Monad (liftM)
import Data.Int (Int32, Int64)
import Data.Word (Word8)
import Foreign.Marshal.Alloc (alloca, allocaBytes)
import Foreign.Marshal.Array (peekArray, allocaArray)
import Foreign.Storable (Storable(..))
import Foreign.Ptr (Ptr, FunPtr, castPtr, nullPtr)
import Foreign.ForeignPtr (FinalizerPtr, addForeignPtrFinalizer, withForeignPtr, newForeignPtr, newForeignPtr_)
import Foreign.C.Error (Errno(..), getErrno)
import Foreign.C.String (CString, newCString, withCAString, peekCAString, peekCAStringLen, peekCString)
import Foreign.C.Types (CFile, CInt(..), CSize, CChar)
import System.IO (Handle, stdin, stdout, stderr)
import System.Posix.IO (handleToFd)
import System.Posix.Types (Fd(..))



type CInt64T = (C2HSImp.CLLong)
{-# LINE 25 "src/Kafka/Internal/RdKafka.chs" #-}

type CInt32T = (C2HSImp.CInt)
{-# LINE 26 "src/Kafka/Internal/RdKafka.chs" #-}


type CFilePtr = C2HSImp.Ptr (CFile)
{-# LINE 28 "src/Kafka/Internal/RdKafka.chs" #-}

type CSizePtr = C2HSImp.Ptr (CSize)
{-# LINE 29 "src/Kafka/Internal/RdKafka.chs" #-}


type Word8Ptr = Ptr Word8
type CCharBufPointer  = Ptr CChar

data RdKafkaTypeT = RdKafkaProducer
                  | RdKafkaConsumer
  deriving (Enum,Show,Eq)

{-# LINE 34 "src/Kafka/Internal/RdKafka.chs" #-}

data RdKafkaConfResT = RdKafkaConfUnknown
                     | RdKafkaConfInvalid
                     | RdKafkaConfOk
  deriving (Show,Eq)
instance Enum RdKafkaConfResT where
  succ RdKafkaConfUnknown = RdKafkaConfInvalid
  succ RdKafkaConfInvalid = RdKafkaConfOk
  succ RdKafkaConfOk = error "RdKafkaConfResT.succ: RdKafkaConfOk has no successor"

  pred RdKafkaConfInvalid = RdKafkaConfUnknown
  pred RdKafkaConfOk = RdKafkaConfInvalid
  pred RdKafkaConfUnknown = error "RdKafkaConfResT.pred: RdKafkaConfUnknown 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 RdKafkaConfOk

  fromEnum RdKafkaConfUnknown = (-2)
  fromEnum RdKafkaConfInvalid = (-1)
  fromEnum RdKafkaConfOk = 0

  toEnum (-2) = RdKafkaConfUnknown
  toEnum (-1) = RdKafkaConfInvalid
  toEnum 0 = RdKafkaConfOk
  toEnum unmatched = error ("RdKafkaConfResT.toEnum: Cannot match " ++ show unmatched)

{-# LINE 35 "src/Kafka/Internal/RdKafka.chs" #-}

data RdKafkaRespErrT = RdKafkaRespErrBegin
                     | RdKafkaRespErrBadMsg
                     | RdKafkaRespErrBadCompression
                     | RdKafkaRespErrDestroy
                     | RdKafkaRespErrFail
                     | RdKafkaRespErrTransport
                     | RdKafkaRespErrCritSysResource
                     | RdKafkaRespErrResolve
                     | RdKafkaRespErrMsgTimedOut
                     | RdKafkaRespErrPartitionEof
                     | RdKafkaRespErrUnknownPartition
                     | RdKafkaRespErrFs
                     | RdKafkaRespErrUnknownTopic
                     | RdKafkaRespErrAllBrokersDown
                     | RdKafkaRespErrInvalidArg
                     | RdKafkaRespErrTimedOut
                     | RdKafkaRespErrQueueFull
                     | RdKafkaRespErrIsrInsuff
                     | RdKafkaRespErrNodeUpdate
                     | RdKafkaRespErrSsl
                     | RdKafkaRespErrWaitCoord
                     | RdKafkaRespErrUnknownGroup
                     | RdKafkaRespErrInProgress
                     | RdKafkaRespErrPrevInProgress
                     | RdKafkaRespErrExistingSubscription
                     | RdKafkaRespErrAssignPartitions
                     | RdKafkaRespErrRevokePartitions
                     | RdKafkaRespErrConflict
                     | RdKafkaRespErrState
                     | RdKafkaRespErrUnknownProtocol
                     | RdKafkaRespErrNotImplemented
                     | RdKafkaRespErrAuthentication
                     | RdKafkaRespErrNoOffset
                     | RdKafkaRespErrOutdated
                     | RdKafkaRespErrTimedOutQueue
                     | RdKafkaRespErrUnsupportedFeature
                     | RdKafkaRespErrWaitCache
                     | RdKafkaRespErrIntr
                     | RdKafkaRespErrKeySerialization
                     | RdKafkaRespErrValueSerialization
                     | RdKafkaRespErrKeyDeserialization
                     | RdKafkaRespErrValueDeserialization
                     | RdKafkaRespErrPartial
                     | RdKafkaRespErrReadOnly
                     | RdKafkaRespErrNoent
                     | RdKafkaRespErrUnderflow
                     | RdKafkaRespErrInvalidType
                     | RdKafkaRespErrRetry
                     | RdKafkaRespErrPurgeQueue
                     | RdKafkaRespErrPurgeInflight
                     | RdKafkaRespErrFatal
                     | RdKafkaRespErrInconsistent
                     | RdKafkaRespErrGaplessGuarantee
                     | RdKafkaRespErrMaxPollExceeded
                     | RdKafkaRespErrUnknownBroker
                     | RdKafkaRespErrEnd
                     | RdKafkaRespErrUnknown
                     | RdKafkaRespErrNoError
                     | RdKafkaRespErrOffsetOutOfRange
                     | RdKafkaRespErrInvalidMsg
                     | RdKafkaRespErrUnknownTopicOrPart
                     | RdKafkaRespErrInvalidMsgSize
                     | RdKafkaRespErrLeaderNotAvailable
                     | RdKafkaRespErrNotLeaderForPartition
                     | RdKafkaRespErrRequestTimedOut
                     | RdKafkaRespErrBrokerNotAvailable
                     | RdKafkaRespErrReplicaNotAvailable
                     | RdKafkaRespErrMsgSizeTooLarge
                     | RdKafkaRespErrStaleCtrlEpoch
                     | RdKafkaRespErrOffsetMetadataTooLarge
                     | RdKafkaRespErrNetworkException
                     | RdKafkaRespErrCoordinatorLoadInProgress
                     | RdKafkaRespErrCoordinatorNotAvailable
                     | RdKafkaRespErrNotCoordinator
                     | RdKafkaRespErrTopicException
                     | RdKafkaRespErrRecordListTooLarge
                     | RdKafkaRespErrNotEnoughReplicas
                     | RdKafkaRespErrNotEnoughReplicasAfterAppend
                     | RdKafkaRespErrInvalidRequiredAcks
                     | RdKafkaRespErrIllegalGeneration
                     | RdKafkaRespErrInconsistentGroupProtocol
                     | RdKafkaRespErrInvalidGroupId
                     | RdKafkaRespErrUnknownMemberId
                     | RdKafkaRespErrInvalidSessionTimeout
                     | RdKafkaRespErrRebalanceInProgress
                     | RdKafkaRespErrInvalidCommitOffsetSize
                     | RdKafkaRespErrTopicAuthorizationFailed
                     | RdKafkaRespErrGroupAuthorizationFailed
                     | RdKafkaRespErrClusterAuthorizationFailed
                     | RdKafkaRespErrInvalidTimestamp
                     | RdKafkaRespErrUnsupportedSaslMechanism
                     | RdKafkaRespErrIllegalSaslState
                     | RdKafkaRespErrUnsupportedVersion
                     | RdKafkaRespErrTopicAlreadyExists
                     | RdKafkaRespErrInvalidPartitions
                     | RdKafkaRespErrInvalidReplicationFactor
                     | RdKafkaRespErrInvalidReplicaAssignment
                     | RdKafkaRespErrInvalidConfig
                     | RdKafkaRespErrNotController
                     | RdKafkaRespErrInvalidRequest
                     | RdKafkaRespErrUnsupportedForMessageFormat
                     | RdKafkaRespErrPolicyViolation
                     | RdKafkaRespErrOutOfOrderSequenceNumber
                     | RdKafkaRespErrDuplicateSequenceNumber
                     | RdKafkaRespErrInvalidProducerEpoch
                     | RdKafkaRespErrInvalidTxnState
                     | RdKafkaRespErrInvalidProducerIdMapping
                     | RdKafkaRespErrInvalidTransactionTimeout
                     | RdKafkaRespErrConcurrentTransactions
                     | RdKafkaRespErrTransactionCoordinatorFenced
                     | RdKafkaRespErrTransactionalIdAuthorizationFailed
                     | RdKafkaRespErrSecurityDisabled
                     | RdKafkaRespErrOperationNotAttempted
                     | RdKafkaRespErrKafkaStorageError
                     | RdKafkaRespErrLogDirNotFound
                     | RdKafkaRespErrSaslAuthenticationFailed
                     | RdKafkaRespErrUnknownProducerId
                     | RdKafkaRespErrReassignmentInProgress
                     | RdKafkaRespErrDelegationTokenAuthDisabled
                     | RdKafkaRespErrDelegationTokenNotFound
                     | RdKafkaRespErrDelegationTokenOwnerMismatch
                     | RdKafkaRespErrDelegationTokenRequestNotAllowed
                     | RdKafkaRespErrDelegationTokenAuthorizationFailed
                     | RdKafkaRespErrDelegationTokenExpired
                     | RdKafkaRespErrInvalidPrincipalType
                     | RdKafkaRespErrNonEmptyGroup
                     | RdKafkaRespErrGroupIdNotFound
                     | RdKafkaRespErrFetchSessionIdNotFound
                     | RdKafkaRespErrInvalidFetchSessionEpoch
                     | RdKafkaRespErrListenerNotFound
                     | RdKafkaRespErrTopicDeletionDisabled
                     | RdKafkaRespErrFencedLeaderEpoch
                     | RdKafkaRespErrUnknownLeaderEpoch
                     | RdKafkaRespErrUnsupportedCompressionType
                     | RdKafkaRespErrStaleBrokerEpoch
                     | RdKafkaRespErrOffsetNotAvailable
                     | RdKafkaRespErrMemberIdRequired
                     | RdKafkaRespErrPreferredLeaderNotAvailable
                     | RdKafkaRespErrGroupMaxSizeReached
                     | RdKafkaRespErrEndAll
  deriving (Show,Eq,Bounded)
instance Enum RdKafkaRespErrT where
  succ RdKafkaRespErrBegin = RdKafkaRespErrBadMsg
  succ RdKafkaRespErrBadMsg = RdKafkaRespErrBadCompression
  succ RdKafkaRespErrBadCompression = RdKafkaRespErrDestroy
  succ RdKafkaRespErrDestroy = RdKafkaRespErrFail
  succ RdKafkaRespErrFail = RdKafkaRespErrTransport
  succ RdKafkaRespErrTransport = RdKafkaRespErrCritSysResource
  succ RdKafkaRespErrCritSysResource = RdKafkaRespErrResolve
  succ RdKafkaRespErrResolve = RdKafkaRespErrMsgTimedOut
  succ RdKafkaRespErrMsgTimedOut = RdKafkaRespErrPartitionEof
  succ RdKafkaRespErrPartitionEof = RdKafkaRespErrUnknownPartition
  succ RdKafkaRespErrUnknownPartition = RdKafkaRespErrFs
  succ RdKafkaRespErrFs = RdKafkaRespErrUnknownTopic
  succ RdKafkaRespErrUnknownTopic = RdKafkaRespErrAllBrokersDown
  succ RdKafkaRespErrAllBrokersDown = RdKafkaRespErrInvalidArg
  succ RdKafkaRespErrInvalidArg = RdKafkaRespErrTimedOut
  succ RdKafkaRespErrTimedOut = RdKafkaRespErrQueueFull
  succ RdKafkaRespErrQueueFull = RdKafkaRespErrIsrInsuff
  succ RdKafkaRespErrIsrInsuff = RdKafkaRespErrNodeUpdate
  succ RdKafkaRespErrNodeUpdate = RdKafkaRespErrSsl
  succ RdKafkaRespErrSsl = RdKafkaRespErrWaitCoord
  succ RdKafkaRespErrWaitCoord = RdKafkaRespErrUnknownGroup
  succ RdKafkaRespErrUnknownGroup = RdKafkaRespErrInProgress
  succ RdKafkaRespErrInProgress = RdKafkaRespErrPrevInProgress
  succ RdKafkaRespErrPrevInProgress = RdKafkaRespErrExistingSubscription
  succ RdKafkaRespErrExistingSubscription = RdKafkaRespErrAssignPartitions
  succ RdKafkaRespErrAssignPartitions = RdKafkaRespErrRevokePartitions
  succ RdKafkaRespErrRevokePartitions = RdKafkaRespErrConflict
  succ RdKafkaRespErrConflict = RdKafkaRespErrState
  succ RdKafkaRespErrState = RdKafkaRespErrUnknownProtocol
  succ RdKafkaRespErrUnknownProtocol = RdKafkaRespErrNotImplemented
  succ RdKafkaRespErrNotImplemented = RdKafkaRespErrAuthentication
  succ RdKafkaRespErrAuthentication = RdKafkaRespErrNoOffset
  succ RdKafkaRespErrNoOffset = RdKafkaRespErrOutdated
  succ RdKafkaRespErrOutdated = RdKafkaRespErrTimedOutQueue
  succ RdKafkaRespErrTimedOutQueue = RdKafkaRespErrUnsupportedFeature
  succ RdKafkaRespErrUnsupportedFeature = RdKafkaRespErrWaitCache
  succ RdKafkaRespErrWaitCache = RdKafkaRespErrIntr
  succ RdKafkaRespErrIntr = RdKafkaRespErrKeySerialization
  succ RdKafkaRespErrKeySerialization = RdKafkaRespErrValueSerialization
  succ RdKafkaRespErrValueSerialization = RdKafkaRespErrKeyDeserialization
  succ RdKafkaRespErrKeyDeserialization = RdKafkaRespErrValueDeserialization
  succ RdKafkaRespErrValueDeserialization = RdKafkaRespErrPartial
  succ RdKafkaRespErrPartial = RdKafkaRespErrReadOnly
  succ RdKafkaRespErrReadOnly = RdKafkaRespErrNoent
  succ RdKafkaRespErrNoent = RdKafkaRespErrUnderflow
  succ RdKafkaRespErrUnderflow = RdKafkaRespErrInvalidType
  succ RdKafkaRespErrInvalidType = RdKafkaRespErrRetry
  succ RdKafkaRespErrRetry = RdKafkaRespErrPurgeQueue
  succ RdKafkaRespErrPurgeQueue = RdKafkaRespErrPurgeInflight
  succ RdKafkaRespErrPurgeInflight = RdKafkaRespErrFatal
  succ RdKafkaRespErrFatal = RdKafkaRespErrInconsistent
  succ RdKafkaRespErrInconsistent = RdKafkaRespErrGaplessGuarantee
  succ RdKafkaRespErrGaplessGuarantee = RdKafkaRespErrMaxPollExceeded
  succ RdKafkaRespErrMaxPollExceeded = RdKafkaRespErrUnknownBroker
  succ RdKafkaRespErrUnknownBroker = RdKafkaRespErrEnd
  succ RdKafkaRespErrEnd = RdKafkaRespErrUnknown
  succ RdKafkaRespErrUnknown = RdKafkaRespErrNoError
  succ RdKafkaRespErrNoError = RdKafkaRespErrOffsetOutOfRange
  succ RdKafkaRespErrOffsetOutOfRange = RdKafkaRespErrInvalidMsg
  succ RdKafkaRespErrInvalidMsg = RdKafkaRespErrUnknownTopicOrPart
  succ RdKafkaRespErrUnknownTopicOrPart = RdKafkaRespErrInvalidMsgSize
  succ RdKafkaRespErrInvalidMsgSize = RdKafkaRespErrLeaderNotAvailable
  succ RdKafkaRespErrLeaderNotAvailable = RdKafkaRespErrNotLeaderForPartition
  succ RdKafkaRespErrNotLeaderForPartition = RdKafkaRespErrRequestTimedOut
  succ RdKafkaRespErrRequestTimedOut = RdKafkaRespErrBrokerNotAvailable
  succ RdKafkaRespErrBrokerNotAvailable = RdKafkaRespErrReplicaNotAvailable
  succ RdKafkaRespErrReplicaNotAvailable = RdKafkaRespErrMsgSizeTooLarge
  succ RdKafkaRespErrMsgSizeTooLarge = RdKafkaRespErrStaleCtrlEpoch
  succ RdKafkaRespErrStaleCtrlEpoch = RdKafkaRespErrOffsetMetadataTooLarge
  succ RdKafkaRespErrOffsetMetadataTooLarge = RdKafkaRespErrNetworkException
  succ RdKafkaRespErrNetworkException = RdKafkaRespErrCoordinatorLoadInProgress
  succ RdKafkaRespErrCoordinatorLoadInProgress = RdKafkaRespErrCoordinatorNotAvailable
  succ RdKafkaRespErrCoordinatorNotAvailable = RdKafkaRespErrNotCoordinator
  succ RdKafkaRespErrNotCoordinator = RdKafkaRespErrTopicException
  succ RdKafkaRespErrTopicException = RdKafkaRespErrRecordListTooLarge
  succ RdKafkaRespErrRecordListTooLarge = RdKafkaRespErrNotEnoughReplicas
  succ RdKafkaRespErrNotEnoughReplicas = RdKafkaRespErrNotEnoughReplicasAfterAppend
  succ RdKafkaRespErrNotEnoughReplicasAfterAppend = RdKafkaRespErrInvalidRequiredAcks
  succ RdKafkaRespErrInvalidRequiredAcks = RdKafkaRespErrIllegalGeneration
  succ RdKafkaRespErrIllegalGeneration = RdKafkaRespErrInconsistentGroupProtocol
  succ RdKafkaRespErrInconsistentGroupProtocol = RdKafkaRespErrInvalidGroupId
  succ RdKafkaRespErrInvalidGroupId = RdKafkaRespErrUnknownMemberId
  succ RdKafkaRespErrUnknownMemberId = RdKafkaRespErrInvalidSessionTimeout
  succ RdKafkaRespErrInvalidSessionTimeout = RdKafkaRespErrRebalanceInProgress
  succ RdKafkaRespErrRebalanceInProgress = RdKafkaRespErrInvalidCommitOffsetSize
  succ RdKafkaRespErrInvalidCommitOffsetSize = RdKafkaRespErrTopicAuthorizationFailed
  succ RdKafkaRespErrTopicAuthorizationFailed = RdKafkaRespErrGroupAuthorizationFailed
  succ RdKafkaRespErrGroupAuthorizationFailed = RdKafkaRespErrClusterAuthorizationFailed
  succ RdKafkaRespErrClusterAuthorizationFailed = RdKafkaRespErrInvalidTimestamp
  succ RdKafkaRespErrInvalidTimestamp = RdKafkaRespErrUnsupportedSaslMechanism
  succ RdKafkaRespErrUnsupportedSaslMechanism = RdKafkaRespErrIllegalSaslState
  succ RdKafkaRespErrIllegalSaslState = RdKafkaRespErrUnsupportedVersion
  succ RdKafkaRespErrUnsupportedVersion = RdKafkaRespErrTopicAlreadyExists
  succ RdKafkaRespErrTopicAlreadyExists = RdKafkaRespErrInvalidPartitions
  succ RdKafkaRespErrInvalidPartitions = RdKafkaRespErrInvalidReplicationFactor
  succ RdKafkaRespErrInvalidReplicationFactor = RdKafkaRespErrInvalidReplicaAssignment
  succ RdKafkaRespErrInvalidReplicaAssignment = RdKafkaRespErrInvalidConfig
  succ RdKafkaRespErrInvalidConfig = RdKafkaRespErrNotController
  succ RdKafkaRespErrNotController = RdKafkaRespErrInvalidRequest
  succ RdKafkaRespErrInvalidRequest = RdKafkaRespErrUnsupportedForMessageFormat
  succ RdKafkaRespErrUnsupportedForMessageFormat = RdKafkaRespErrPolicyViolation
  succ RdKafkaRespErrPolicyViolation = RdKafkaRespErrOutOfOrderSequenceNumber
  succ RdKafkaRespErrOutOfOrderSequenceNumber = RdKafkaRespErrDuplicateSequenceNumber
  succ RdKafkaRespErrDuplicateSequenceNumber = RdKafkaRespErrInvalidProducerEpoch
  succ RdKafkaRespErrInvalidProducerEpoch = RdKafkaRespErrInvalidTxnState
  succ RdKafkaRespErrInvalidTxnState = RdKafkaRespErrInvalidProducerIdMapping
  succ RdKafkaRespErrInvalidProducerIdMapping = RdKafkaRespErrInvalidTransactionTimeout
  succ RdKafkaRespErrInvalidTransactionTimeout = RdKafkaRespErrConcurrentTransactions
  succ RdKafkaRespErrConcurrentTransactions = RdKafkaRespErrTransactionCoordinatorFenced
  succ RdKafkaRespErrTransactionCoordinatorFenced = RdKafkaRespErrTransactionalIdAuthorizationFailed
  succ RdKafkaRespErrTransactionalIdAuthorizationFailed = RdKafkaRespErrSecurityDisabled
  succ RdKafkaRespErrSecurityDisabled = RdKafkaRespErrOperationNotAttempted
  succ RdKafkaRespErrOperationNotAttempted = RdKafkaRespErrKafkaStorageError
  succ RdKafkaRespErrKafkaStorageError = RdKafkaRespErrLogDirNotFound
  succ RdKafkaRespErrLogDirNotFound = RdKafkaRespErrSaslAuthenticationFailed
  succ RdKafkaRespErrSaslAuthenticationFailed = RdKafkaRespErrUnknownProducerId
  succ RdKafkaRespErrUnknownProducerId = RdKafkaRespErrReassignmentInProgress
  succ RdKafkaRespErrReassignmentInProgress = RdKafkaRespErrDelegationTokenAuthDisabled
  succ RdKafkaRespErrDelegationTokenAuthDisabled = RdKafkaRespErrDelegationTokenNotFound
  succ RdKafkaRespErrDelegationTokenNotFound = RdKafkaRespErrDelegationTokenOwnerMismatch
  succ RdKafkaRespErrDelegationTokenOwnerMismatch = RdKafkaRespErrDelegationTokenRequestNotAllowed
  succ RdKafkaRespErrDelegationTokenRequestNotAllowed = RdKafkaRespErrDelegationTokenAuthorizationFailed
  succ RdKafkaRespErrDelegationTokenAuthorizationFailed = RdKafkaRespErrDelegationTokenExpired
  succ RdKafkaRespErrDelegationTokenExpired = RdKafkaRespErrInvalidPrincipalType
  succ RdKafkaRespErrInvalidPrincipalType = RdKafkaRespErrNonEmptyGroup
  succ RdKafkaRespErrNonEmptyGroup = RdKafkaRespErrGroupIdNotFound
  succ RdKafkaRespErrGroupIdNotFound = RdKafkaRespErrFetchSessionIdNotFound
  succ RdKafkaRespErrFetchSessionIdNotFound = RdKafkaRespErrInvalidFetchSessionEpoch
  succ RdKafkaRespErrInvalidFetchSessionEpoch = RdKafkaRespErrListenerNotFound
  succ RdKafkaRespErrListenerNotFound = RdKafkaRespErrTopicDeletionDisabled
  succ RdKafkaRespErrTopicDeletionDisabled = RdKafkaRespErrFencedLeaderEpoch
  succ RdKafkaRespErrFencedLeaderEpoch = RdKafkaRespErrUnknownLeaderEpoch
  succ RdKafkaRespErrUnknownLeaderEpoch = RdKafkaRespErrUnsupportedCompressionType
  succ RdKafkaRespErrUnsupportedCompressionType = RdKafkaRespErrStaleBrokerEpoch
  succ RdKafkaRespErrStaleBrokerEpoch = RdKafkaRespErrOffsetNotAvailable
  succ RdKafkaRespErrOffsetNotAvailable = RdKafkaRespErrMemberIdRequired
  succ RdKafkaRespErrMemberIdRequired = RdKafkaRespErrPreferredLeaderNotAvailable
  succ RdKafkaRespErrPreferredLeaderNotAvailable = RdKafkaRespErrGroupMaxSizeReached
  succ RdKafkaRespErrGroupMaxSizeReached = RdKafkaRespErrEndAll
  succ RdKafkaRespErrEndAll = error "RdKafkaRespErrT.succ: RdKafkaRespErrEndAll has no successor"

  pred RdKafkaRespErrBadMsg = RdKafkaRespErrBegin
  pred RdKafkaRespErrBadCompression = RdKafkaRespErrBadMsg
  pred RdKafkaRespErrDestroy = RdKafkaRespErrBadCompression
  pred RdKafkaRespErrFail = RdKafkaRespErrDestroy
  pred RdKafkaRespErrTransport = RdKafkaRespErrFail
  pred RdKafkaRespErrCritSysResource = RdKafkaRespErrTransport
  pred RdKafkaRespErrResolve = RdKafkaRespErrCritSysResource
  pred RdKafkaRespErrMsgTimedOut = RdKafkaRespErrResolve
  pred RdKafkaRespErrPartitionEof = RdKafkaRespErrMsgTimedOut
  pred RdKafkaRespErrUnknownPartition = RdKafkaRespErrPartitionEof
  pred RdKafkaRespErrFs = RdKafkaRespErrUnknownPartition
  pred RdKafkaRespErrUnknownTopic = RdKafkaRespErrFs
  pred RdKafkaRespErrAllBrokersDown = RdKafkaRespErrUnknownTopic
  pred RdKafkaRespErrInvalidArg = RdKafkaRespErrAllBrokersDown
  pred RdKafkaRespErrTimedOut = RdKafkaRespErrInvalidArg
  pred RdKafkaRespErrQueueFull = RdKafkaRespErrTimedOut
  pred RdKafkaRespErrIsrInsuff = RdKafkaRespErrQueueFull
  pred RdKafkaRespErrNodeUpdate = RdKafkaRespErrIsrInsuff
  pred RdKafkaRespErrSsl = RdKafkaRespErrNodeUpdate
  pred RdKafkaRespErrWaitCoord = RdKafkaRespErrSsl
  pred RdKafkaRespErrUnknownGroup = RdKafkaRespErrWaitCoord
  pred RdKafkaRespErrInProgress = RdKafkaRespErrUnknownGroup
  pred RdKafkaRespErrPrevInProgress = RdKafkaRespErrInProgress
  pred RdKafkaRespErrExistingSubscription = RdKafkaRespErrPrevInProgress
  pred RdKafkaRespErrAssignPartitions = RdKafkaRespErrExistingSubscription
  pred RdKafkaRespErrRevokePartitions = RdKafkaRespErrAssignPartitions
  pred RdKafkaRespErrConflict = RdKafkaRespErrRevokePartitions
  pred RdKafkaRespErrState = RdKafkaRespErrConflict
  pred RdKafkaRespErrUnknownProtocol = RdKafkaRespErrState
  pred RdKafkaRespErrNotImplemented = RdKafkaRespErrUnknownProtocol
  pred RdKafkaRespErrAuthentication = RdKafkaRespErrNotImplemented
  pred RdKafkaRespErrNoOffset = RdKafkaRespErrAuthentication
  pred RdKafkaRespErrOutdated = RdKafkaRespErrNoOffset
  pred RdKafkaRespErrTimedOutQueue = RdKafkaRespErrOutdated
  pred RdKafkaRespErrUnsupportedFeature = RdKafkaRespErrTimedOutQueue
  pred RdKafkaRespErrWaitCache = RdKafkaRespErrUnsupportedFeature
  pred RdKafkaRespErrIntr = RdKafkaRespErrWaitCache
  pred RdKafkaRespErrKeySerialization = RdKafkaRespErrIntr
  pred RdKafkaRespErrValueSerialization = RdKafkaRespErrKeySerialization
  pred RdKafkaRespErrKeyDeserialization = RdKafkaRespErrValueSerialization
  pred RdKafkaRespErrValueDeserialization = RdKafkaRespErrKeyDeserialization
  pred RdKafkaRespErrPartial = RdKafkaRespErrValueDeserialization
  pred RdKafkaRespErrReadOnly = RdKafkaRespErrPartial
  pred RdKafkaRespErrNoent = RdKafkaRespErrReadOnly
  pred RdKafkaRespErrUnderflow = RdKafkaRespErrNoent
  pred RdKafkaRespErrInvalidType = RdKafkaRespErrUnderflow
  pred RdKafkaRespErrRetry = RdKafkaRespErrInvalidType
  pred RdKafkaRespErrPurgeQueue = RdKafkaRespErrRetry
  pred RdKafkaRespErrPurgeInflight = RdKafkaRespErrPurgeQueue
  pred RdKafkaRespErrFatal = RdKafkaRespErrPurgeInflight
  pred RdKafkaRespErrInconsistent = RdKafkaRespErrFatal
  pred RdKafkaRespErrGaplessGuarantee = RdKafkaRespErrInconsistent
  pred RdKafkaRespErrMaxPollExceeded = RdKafkaRespErrGaplessGuarantee
  pred RdKafkaRespErrUnknownBroker = RdKafkaRespErrMaxPollExceeded
  pred RdKafkaRespErrEnd = RdKafkaRespErrUnknownBroker
  pred RdKafkaRespErrUnknown = RdKafkaRespErrEnd
  pred RdKafkaRespErrNoError = RdKafkaRespErrUnknown
  pred RdKafkaRespErrOffsetOutOfRange = RdKafkaRespErrNoError
  pred RdKafkaRespErrInvalidMsg = RdKafkaRespErrOffsetOutOfRange
  pred RdKafkaRespErrUnknownTopicOrPart = RdKafkaRespErrInvalidMsg
  pred RdKafkaRespErrInvalidMsgSize = RdKafkaRespErrUnknownTopicOrPart
  pred RdKafkaRespErrLeaderNotAvailable = RdKafkaRespErrInvalidMsgSize
  pred RdKafkaRespErrNotLeaderForPartition = RdKafkaRespErrLeaderNotAvailable
  pred RdKafkaRespErrRequestTimedOut = RdKafkaRespErrNotLeaderForPartition
  pred RdKafkaRespErrBrokerNotAvailable = RdKafkaRespErrRequestTimedOut
  pred RdKafkaRespErrReplicaNotAvailable = RdKafkaRespErrBrokerNotAvailable
  pred RdKafkaRespErrMsgSizeTooLarge = RdKafkaRespErrReplicaNotAvailable
  pred RdKafkaRespErrStaleCtrlEpoch = RdKafkaRespErrMsgSizeTooLarge
  pred RdKafkaRespErrOffsetMetadataTooLarge = RdKafkaRespErrStaleCtrlEpoch
  pred RdKafkaRespErrNetworkException = RdKafkaRespErrOffsetMetadataTooLarge
  pred RdKafkaRespErrCoordinatorLoadInProgress = RdKafkaRespErrNetworkException
  pred RdKafkaRespErrCoordinatorNotAvailable = RdKafkaRespErrCoordinatorLoadInProgress
  pred RdKafkaRespErrNotCoordinator = RdKafkaRespErrCoordinatorNotAvailable
  pred RdKafkaRespErrTopicException = RdKafkaRespErrNotCoordinator
  pred RdKafkaRespErrRecordListTooLarge = RdKafkaRespErrTopicException
  pred RdKafkaRespErrNotEnoughReplicas = RdKafkaRespErrRecordListTooLarge
  pred RdKafkaRespErrNotEnoughReplicasAfterAppend = RdKafkaRespErrNotEnoughReplicas
  pred RdKafkaRespErrInvalidRequiredAcks = RdKafkaRespErrNotEnoughReplicasAfterAppend
  pred RdKafkaRespErrIllegalGeneration = RdKafkaRespErrInvalidRequiredAcks
  pred RdKafkaRespErrInconsistentGroupProtocol = RdKafkaRespErrIllegalGeneration
  pred RdKafkaRespErrInvalidGroupId = RdKafkaRespErrInconsistentGroupProtocol
  pred RdKafkaRespErrUnknownMemberId = RdKafkaRespErrInvalidGroupId
  pred RdKafkaRespErrInvalidSessionTimeout = RdKafkaRespErrUnknownMemberId
  pred RdKafkaRespErrRebalanceInProgress = RdKafkaRespErrInvalidSessionTimeout
  pred RdKafkaRespErrInvalidCommitOffsetSize = RdKafkaRespErrRebalanceInProgress
  pred RdKafkaRespErrTopicAuthorizationFailed = RdKafkaRespErrInvalidCommitOffsetSize
  pred RdKafkaRespErrGroupAuthorizationFailed = RdKafkaRespErrTopicAuthorizationFailed
  pred RdKafkaRespErrClusterAuthorizationFailed = RdKafkaRespErrGroupAuthorizationFailed
  pred RdKafkaRespErrInvalidTimestamp = RdKafkaRespErrClusterAuthorizationFailed
  pred RdKafkaRespErrUnsupportedSaslMechanism = RdKafkaRespErrInvalidTimestamp
  pred RdKafkaRespErrIllegalSaslState = RdKafkaRespErrUnsupportedSaslMechanism
  pred RdKafkaRespErrUnsupportedVersion = RdKafkaRespErrIllegalSaslState
  pred RdKafkaRespErrTopicAlreadyExists = RdKafkaRespErrUnsupportedVersion
  pred RdKafkaRespErrInvalidPartitions = RdKafkaRespErrTopicAlreadyExists
  pred RdKafkaRespErrInvalidReplicationFactor = RdKafkaRespErrInvalidPartitions
  pred RdKafkaRespErrInvalidReplicaAssignment = RdKafkaRespErrInvalidReplicationFactor
  pred RdKafkaRespErrInvalidConfig = RdKafkaRespErrInvalidReplicaAssignment
  pred RdKafkaRespErrNotController = RdKafkaRespErrInvalidConfig
  pred RdKafkaRespErrInvalidRequest = RdKafkaRespErrNotController
  pred RdKafkaRespErrUnsupportedForMessageFormat = RdKafkaRespErrInvalidRequest
  pred RdKafkaRespErrPolicyViolation = RdKafkaRespErrUnsupportedForMessageFormat
  pred RdKafkaRespErrOutOfOrderSequenceNumber = RdKafkaRespErrPolicyViolation
  pred RdKafkaRespErrDuplicateSequenceNumber = RdKafkaRespErrOutOfOrderSequenceNumber
  pred RdKafkaRespErrInvalidProducerEpoch = RdKafkaRespErrDuplicateSequenceNumber
  pred RdKafkaRespErrInvalidTxnState = RdKafkaRespErrInvalidProducerEpoch
  pred RdKafkaRespErrInvalidProducerIdMapping = RdKafkaRespErrInvalidTxnState
  pred RdKafkaRespErrInvalidTransactionTimeout = RdKafkaRespErrInvalidProducerIdMapping
  pred RdKafkaRespErrConcurrentTransactions = RdKafkaRespErrInvalidTransactionTimeout
  pred RdKafkaRespErrTransactionCoordinatorFenced = RdKafkaRespErrConcurrentTransactions
  pred RdKafkaRespErrTransactionalIdAuthorizationFailed = RdKafkaRespErrTransactionCoordinatorFenced
  pred RdKafkaRespErrSecurityDisabled = RdKafkaRespErrTransactionalIdAuthorizationFailed
  pred RdKafkaRespErrOperationNotAttempted = RdKafkaRespErrSecurityDisabled
  pred RdKafkaRespErrKafkaStorageError = RdKafkaRespErrOperationNotAttempted
  pred RdKafkaRespErrLogDirNotFound = RdKafkaRespErrKafkaStorageError
  pred RdKafkaRespErrSaslAuthenticationFailed = RdKafkaRespErrLogDirNotFound
  pred RdKafkaRespErrUnknownProducerId = RdKafkaRespErrSaslAuthenticationFailed
  pred RdKafkaRespErrReassignmentInProgress = RdKafkaRespErrUnknownProducerId
  pred RdKafkaRespErrDelegationTokenAuthDisabled = RdKafkaRespErrReassignmentInProgress
  pred RdKafkaRespErrDelegationTokenNotFound = RdKafkaRespErrDelegationTokenAuthDisabled
  pred RdKafkaRespErrDelegationTokenOwnerMismatch = RdKafkaRespErrDelegationTokenNotFound
  pred RdKafkaRespErrDelegationTokenRequestNotAllowed = RdKafkaRespErrDelegationTokenOwnerMismatch
  pred RdKafkaRespErrDelegationTokenAuthorizationFailed = RdKafkaRespErrDelegationTokenRequestNotAllowed
  pred RdKafkaRespErrDelegationTokenExpired = RdKafkaRespErrDelegationTokenAuthorizationFailed
  pred RdKafkaRespErrInvalidPrincipalType = RdKafkaRespErrDelegationTokenExpired
  pred RdKafkaRespErrNonEmptyGroup = RdKafkaRespErrInvalidPrincipalType
  pred RdKafkaRespErrGroupIdNotFound = RdKafkaRespErrNonEmptyGroup
  pred RdKafkaRespErrFetchSessionIdNotFound = RdKafkaRespErrGroupIdNotFound
  pred RdKafkaRespErrInvalidFetchSessionEpoch = RdKafkaRespErrFetchSessionIdNotFound
  pred RdKafkaRespErrListenerNotFound = RdKafkaRespErrInvalidFetchSessionEpoch
  pred RdKafkaRespErrTopicDeletionDisabled = RdKafkaRespErrListenerNotFound
  pred RdKafkaRespErrFencedLeaderEpoch = RdKafkaRespErrTopicDeletionDisabled
  pred RdKafkaRespErrUnknownLeaderEpoch = RdKafkaRespErrFencedLeaderEpoch
  pred RdKafkaRespErrUnsupportedCompressionType = RdKafkaRespErrUnknownLeaderEpoch
  pred RdKafkaRespErrStaleBrokerEpoch = RdKafkaRespErrUnsupportedCompressionType
  pred RdKafkaRespErrOffsetNotAvailable = RdKafkaRespErrStaleBrokerEpoch
  pred RdKafkaRespErrMemberIdRequired = RdKafkaRespErrOffsetNotAvailable
  pred RdKafkaRespErrPreferredLeaderNotAvailable = RdKafkaRespErrMemberIdRequired
  pred RdKafkaRespErrGroupMaxSizeReached = RdKafkaRespErrPreferredLeaderNotAvailable
  pred RdKafkaRespErrEndAll = RdKafkaRespErrGroupMaxSizeReached
  pred RdKafkaRespErrBegin = error "RdKafkaRespErrT.pred: RdKafkaRespErrBegin 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 RdKafkaRespErrEndAll

  fromEnum RdKafkaRespErrBegin = (-200)
  fromEnum RdKafkaRespErrBadMsg = (-199)
  fromEnum RdKafkaRespErrBadCompression = (-198)
  fromEnum RdKafkaRespErrDestroy = (-197)
  fromEnum RdKafkaRespErrFail = (-196)
  fromEnum RdKafkaRespErrTransport = (-195)
  fromEnum RdKafkaRespErrCritSysResource = (-194)
  fromEnum RdKafkaRespErrResolve = (-193)
  fromEnum RdKafkaRespErrMsgTimedOut = (-192)
  fromEnum RdKafkaRespErrPartitionEof = (-191)
  fromEnum RdKafkaRespErrUnknownPartition = (-190)
  fromEnum RdKafkaRespErrFs = (-189)
  fromEnum RdKafkaRespErrUnknownTopic = (-188)
  fromEnum RdKafkaRespErrAllBrokersDown = (-187)
  fromEnum RdKafkaRespErrInvalidArg = (-186)
  fromEnum RdKafkaRespErrTimedOut = (-185)
  fromEnum RdKafkaRespErrQueueFull = (-184)
  fromEnum RdKafkaRespErrIsrInsuff = (-183)
  fromEnum RdKafkaRespErrNodeUpdate = (-182)
  fromEnum RdKafkaRespErrSsl = (-181)
  fromEnum RdKafkaRespErrWaitCoord = (-180)
  fromEnum RdKafkaRespErrUnknownGroup = (-179)
  fromEnum RdKafkaRespErrInProgress = (-178)
  fromEnum RdKafkaRespErrPrevInProgress = (-177)
  fromEnum RdKafkaRespErrExistingSubscription = (-176)
  fromEnum RdKafkaRespErrAssignPartitions = (-175)
  fromEnum RdKafkaRespErrRevokePartitions = (-174)
  fromEnum RdKafkaRespErrConflict = (-173)
  fromEnum RdKafkaRespErrState = (-172)
  fromEnum RdKafkaRespErrUnknownProtocol = (-171)
  fromEnum RdKafkaRespErrNotImplemented = (-170)
  fromEnum RdKafkaRespErrAuthentication = (-169)
  fromEnum RdKafkaRespErrNoOffset = (-168)
  fromEnum RdKafkaRespErrOutdated = (-167)
  fromEnum RdKafkaRespErrTimedOutQueue = (-166)
  fromEnum RdKafkaRespErrUnsupportedFeature = (-165)
  fromEnum RdKafkaRespErrWaitCache = (-164)
  fromEnum RdKafkaRespErrIntr = (-163)
  fromEnum RdKafkaRespErrKeySerialization = (-162)
  fromEnum RdKafkaRespErrValueSerialization = (-161)
  fromEnum RdKafkaRespErrKeyDeserialization = (-160)
  fromEnum RdKafkaRespErrValueDeserialization = (-159)
  fromEnum RdKafkaRespErrPartial = (-158)
  fromEnum RdKafkaRespErrReadOnly = (-157)
  fromEnum RdKafkaRespErrNoent = (-156)
  fromEnum RdKafkaRespErrUnderflow = (-155)
  fromEnum RdKafkaRespErrInvalidType = (-154)
  fromEnum RdKafkaRespErrRetry = (-153)
  fromEnum RdKafkaRespErrPurgeQueue = (-152)
  fromEnum RdKafkaRespErrPurgeInflight = (-151)
  fromEnum RdKafkaRespErrFatal = (-150)
  fromEnum RdKafkaRespErrInconsistent = (-149)
  fromEnum RdKafkaRespErrGaplessGuarantee = (-148)
  fromEnum RdKafkaRespErrMaxPollExceeded = (-147)
  fromEnum RdKafkaRespErrUnknownBroker = (-146)
  fromEnum RdKafkaRespErrEnd = (-100)
  fromEnum RdKafkaRespErrUnknown = (-1)
  fromEnum RdKafkaRespErrNoError = 0
  fromEnum RdKafkaRespErrOffsetOutOfRange = 1
  fromEnum RdKafkaRespErrInvalidMsg = 2
  fromEnum RdKafkaRespErrUnknownTopicOrPart = 3
  fromEnum RdKafkaRespErrInvalidMsgSize = 4
  fromEnum RdKafkaRespErrLeaderNotAvailable = 5
  fromEnum RdKafkaRespErrNotLeaderForPartition = 6
  fromEnum RdKafkaRespErrRequestTimedOut = 7
  fromEnum RdKafkaRespErrBrokerNotAvailable = 8
  fromEnum RdKafkaRespErrReplicaNotAvailable = 9
  fromEnum RdKafkaRespErrMsgSizeTooLarge = 10
  fromEnum RdKafkaRespErrStaleCtrlEpoch = 11
  fromEnum RdKafkaRespErrOffsetMetadataTooLarge = 12
  fromEnum RdKafkaRespErrNetworkException = 13
  fromEnum RdKafkaRespErrCoordinatorLoadInProgress = 14
  fromEnum RdKafkaRespErrCoordinatorNotAvailable = 15
  fromEnum RdKafkaRespErrNotCoordinator = 16
  fromEnum RdKafkaRespErrTopicException = 17
  fromEnum RdKafkaRespErrRecordListTooLarge = 18
  fromEnum RdKafkaRespErrNotEnoughReplicas = 19
  fromEnum RdKafkaRespErrNotEnoughReplicasAfterAppend = 20
  fromEnum RdKafkaRespErrInvalidRequiredAcks = 21
  fromEnum RdKafkaRespErrIllegalGeneration = 22
  fromEnum RdKafkaRespErrInconsistentGroupProtocol = 23
  fromEnum RdKafkaRespErrInvalidGroupId = 24
  fromEnum RdKafkaRespErrUnknownMemberId = 25
  fromEnum RdKafkaRespErrInvalidSessionTimeout = 26
  fromEnum RdKafkaRespErrRebalanceInProgress = 27
  fromEnum RdKafkaRespErrInvalidCommitOffsetSize = 28
  fromEnum RdKafkaRespErrTopicAuthorizationFailed = 29
  fromEnum RdKafkaRespErrGroupAuthorizationFailed = 30
  fromEnum RdKafkaRespErrClusterAuthorizationFailed = 31
  fromEnum RdKafkaRespErrInvalidTimestamp = 32
  fromEnum RdKafkaRespErrUnsupportedSaslMechanism = 33
  fromEnum RdKafkaRespErrIllegalSaslState = 34
  fromEnum RdKafkaRespErrUnsupportedVersion = 35
  fromEnum RdKafkaRespErrTopicAlreadyExists = 36
  fromEnum RdKafkaRespErrInvalidPartitions = 37
  fromEnum RdKafkaRespErrInvalidReplicationFactor = 38
  fromEnum RdKafkaRespErrInvalidReplicaAssignment = 39
  fromEnum RdKafkaRespErrInvalidConfig = 40
  fromEnum RdKafkaRespErrNotController = 41
  fromEnum RdKafkaRespErrInvalidRequest = 42
  fromEnum RdKafkaRespErrUnsupportedForMessageFormat = 43
  fromEnum RdKafkaRespErrPolicyViolation = 44
  fromEnum RdKafkaRespErrOutOfOrderSequenceNumber = 45
  fromEnum RdKafkaRespErrDuplicateSequenceNumber = 46
  fromEnum RdKafkaRespErrInvalidProducerEpoch = 47
  fromEnum RdKafkaRespErrInvalidTxnState = 48
  fromEnum RdKafkaRespErrInvalidProducerIdMapping = 49
  fromEnum RdKafkaRespErrInvalidTransactionTimeout = 50
  fromEnum RdKafkaRespErrConcurrentTransactions = 51
  fromEnum RdKafkaRespErrTransactionCoordinatorFenced = 52
  fromEnum RdKafkaRespErrTransactionalIdAuthorizationFailed = 53
  fromEnum RdKafkaRespErrSecurityDisabled = 54
  fromEnum RdKafkaRespErrOperationNotAttempted = 55
  fromEnum RdKafkaRespErrKafkaStorageError = 56
  fromEnum RdKafkaRespErrLogDirNotFound = 57
  fromEnum RdKafkaRespErrSaslAuthenticationFailed = 58
  fromEnum RdKafkaRespErrUnknownProducerId = 59
  fromEnum RdKafkaRespErrReassignmentInProgress = 60
  fromEnum RdKafkaRespErrDelegationTokenAuthDisabled = 61
  fromEnum RdKafkaRespErrDelegationTokenNotFound = 62
  fromEnum RdKafkaRespErrDelegationTokenOwnerMismatch = 63
  fromEnum RdKafkaRespErrDelegationTokenRequestNotAllowed = 64
  fromEnum RdKafkaRespErrDelegationTokenAuthorizationFailed = 65
  fromEnum RdKafkaRespErrDelegationTokenExpired = 66
  fromEnum RdKafkaRespErrInvalidPrincipalType = 67
  fromEnum RdKafkaRespErrNonEmptyGroup = 68
  fromEnum RdKafkaRespErrGroupIdNotFound = 69
  fromEnum RdKafkaRespErrFetchSessionIdNotFound = 70
  fromEnum RdKafkaRespErrInvalidFetchSessionEpoch = 71
  fromEnum RdKafkaRespErrListenerNotFound = 72
  fromEnum RdKafkaRespErrTopicDeletionDisabled = 73
  fromEnum RdKafkaRespErrFencedLeaderEpoch = 74
  fromEnum RdKafkaRespErrUnknownLeaderEpoch = 75
  fromEnum RdKafkaRespErrUnsupportedCompressionType = 76
  fromEnum RdKafkaRespErrStaleBrokerEpoch = 77
  fromEnum RdKafkaRespErrOffsetNotAvailable = 78
  fromEnum RdKafkaRespErrMemberIdRequired = 79
  fromEnum RdKafkaRespErrPreferredLeaderNotAvailable = 80
  fromEnum RdKafkaRespErrGroupMaxSizeReached = 81
  fromEnum RdKafkaRespErrEndAll = 82

  toEnum (-200) = RdKafkaRespErrBegin
  toEnum (-199) = RdKafkaRespErrBadMsg
  toEnum (-198) = RdKafkaRespErrBadCompression
  toEnum (-197) = RdKafkaRespErrDestroy
  toEnum (-196) = RdKafkaRespErrFail
  toEnum (-195) = RdKafkaRespErrTransport
  toEnum (-194) = RdKafkaRespErrCritSysResource
  toEnum (-193) = RdKafkaRespErrResolve
  toEnum (-192) = RdKafkaRespErrMsgTimedOut
  toEnum (-191) = RdKafkaRespErrPartitionEof
  toEnum (-190) = RdKafkaRespErrUnknownPartition
  toEnum (-189) = RdKafkaRespErrFs
  toEnum (-188) = RdKafkaRespErrUnknownTopic
  toEnum (-187) = RdKafkaRespErrAllBrokersDown
  toEnum (-186) = RdKafkaRespErrInvalidArg
  toEnum (-185) = RdKafkaRespErrTimedOut
  toEnum (-184) = RdKafkaRespErrQueueFull
  toEnum (-183) = RdKafkaRespErrIsrInsuff
  toEnum (-182) = RdKafkaRespErrNodeUpdate
  toEnum (-181) = RdKafkaRespErrSsl
  toEnum (-180) = RdKafkaRespErrWaitCoord
  toEnum (-179) = RdKafkaRespErrUnknownGroup
  toEnum (-178) = RdKafkaRespErrInProgress
  toEnum (-177) = RdKafkaRespErrPrevInProgress
  toEnum (-176) = RdKafkaRespErrExistingSubscription
  toEnum (-175) = RdKafkaRespErrAssignPartitions
  toEnum (-174) = RdKafkaRespErrRevokePartitions
  toEnum (-173) = RdKafkaRespErrConflict
  toEnum (-172) = RdKafkaRespErrState
  toEnum (-171) = RdKafkaRespErrUnknownProtocol
  toEnum (-170) = RdKafkaRespErrNotImplemented
  toEnum (-169) = RdKafkaRespErrAuthentication
  toEnum (-168) = RdKafkaRespErrNoOffset
  toEnum (-167) = RdKafkaRespErrOutdated
  toEnum (-166) = RdKafkaRespErrTimedOutQueue
  toEnum (-165) = RdKafkaRespErrUnsupportedFeature
  toEnum (-164) = RdKafkaRespErrWaitCache
  toEnum (-163) = RdKafkaRespErrIntr
  toEnum (-162) = RdKafkaRespErrKeySerialization
  toEnum (-161) = RdKafkaRespErrValueSerialization
  toEnum (-160) = RdKafkaRespErrKeyDeserialization
  toEnum (-159) = RdKafkaRespErrValueDeserialization
  toEnum (-158) = RdKafkaRespErrPartial
  toEnum (-157) = RdKafkaRespErrReadOnly
  toEnum (-156) = RdKafkaRespErrNoent
  toEnum (-155) = RdKafkaRespErrUnderflow
  toEnum (-154) = RdKafkaRespErrInvalidType
  toEnum (-153) = RdKafkaRespErrRetry
  toEnum (-152) = RdKafkaRespErrPurgeQueue
  toEnum (-151) = RdKafkaRespErrPurgeInflight
  toEnum (-150) = RdKafkaRespErrFatal
  toEnum (-149) = RdKafkaRespErrInconsistent
  toEnum (-148) = RdKafkaRespErrGaplessGuarantee
  toEnum (-147) = RdKafkaRespErrMaxPollExceeded
  toEnum (-146) = RdKafkaRespErrUnknownBroker
  toEnum (-100) = RdKafkaRespErrEnd
  toEnum (-1) = RdKafkaRespErrUnknown
  toEnum 0 = RdKafkaRespErrNoError
  toEnum 1 = RdKafkaRespErrOffsetOutOfRange
  toEnum 2 = RdKafkaRespErrInvalidMsg
  toEnum 3 = RdKafkaRespErrUnknownTopicOrPart
  toEnum 4 = RdKafkaRespErrInvalidMsgSize
  toEnum 5 = RdKafkaRespErrLeaderNotAvailable
  toEnum 6 = RdKafkaRespErrNotLeaderForPartition
  toEnum 7 = RdKafkaRespErrRequestTimedOut
  toEnum 8 = RdKafkaRespErrBrokerNotAvailable
  toEnum 9 = RdKafkaRespErrReplicaNotAvailable
  toEnum 10 = RdKafkaRespErrMsgSizeTooLarge
  toEnum 11 = RdKafkaRespErrStaleCtrlEpoch
  toEnum 12 = RdKafkaRespErrOffsetMetadataTooLarge
  toEnum 13 = RdKafkaRespErrNetworkException
  toEnum 14 = RdKafkaRespErrCoordinatorLoadInProgress
  toEnum 15 = RdKafkaRespErrCoordinatorNotAvailable
  toEnum 16 = RdKafkaRespErrNotCoordinator
  toEnum 17 = RdKafkaRespErrTopicException
  toEnum 18 = RdKafkaRespErrRecordListTooLarge
  toEnum 19 = RdKafkaRespErrNotEnoughReplicas
  toEnum 20 = RdKafkaRespErrNotEnoughReplicasAfterAppend
  toEnum 21 = RdKafkaRespErrInvalidRequiredAcks
  toEnum 22 = RdKafkaRespErrIllegalGeneration
  toEnum 23 = RdKafkaRespErrInconsistentGroupProtocol
  toEnum 24 = RdKafkaRespErrInvalidGroupId
  toEnum 25 = RdKafkaRespErrUnknownMemberId
  toEnum 26 = RdKafkaRespErrInvalidSessionTimeout
  toEnum 27 = RdKafkaRespErrRebalanceInProgress
  toEnum 28 = RdKafkaRespErrInvalidCommitOffsetSize
  toEnum 29 = RdKafkaRespErrTopicAuthorizationFailed
  toEnum 30 = RdKafkaRespErrGroupAuthorizationFailed
  toEnum 31 = RdKafkaRespErrClusterAuthorizationFailed
  toEnum 32 = RdKafkaRespErrInvalidTimestamp
  toEnum 33 = RdKafkaRespErrUnsupportedSaslMechanism
  toEnum 34 = RdKafkaRespErrIllegalSaslState
  toEnum 35 = RdKafkaRespErrUnsupportedVersion
  toEnum 36 = RdKafkaRespErrTopicAlreadyExists
  toEnum 37 = RdKafkaRespErrInvalidPartitions
  toEnum 38 = RdKafkaRespErrInvalidReplicationFactor
  toEnum 39 = RdKafkaRespErrInvalidReplicaAssignment
  toEnum 40 = RdKafkaRespErrInvalidConfig
  toEnum 41 = RdKafkaRespErrNotController
  toEnum 42 = RdKafkaRespErrInvalidRequest
  toEnum 43 = RdKafkaRespErrUnsupportedForMessageFormat
  toEnum 44 = RdKafkaRespErrPolicyViolation
  toEnum 45 = RdKafkaRespErrOutOfOrderSequenceNumber
  toEnum 46 = RdKafkaRespErrDuplicateSequenceNumber
  toEnum 47 = RdKafkaRespErrInvalidProducerEpoch
  toEnum 48 = RdKafkaRespErrInvalidTxnState
  toEnum 49 = RdKafkaRespErrInvalidProducerIdMapping
  toEnum 50 = RdKafkaRespErrInvalidTransactionTimeout
  toEnum 51 = RdKafkaRespErrConcurrentTransactions
  toEnum 52 = RdKafkaRespErrTransactionCoordinatorFenced
  toEnum 53 = RdKafkaRespErrTransactionalIdAuthorizationFailed
  toEnum 54 = RdKafkaRespErrSecurityDisabled
  toEnum 55 = RdKafkaRespErrOperationNotAttempted
  toEnum 56 = RdKafkaRespErrKafkaStorageError
  toEnum 57 = RdKafkaRespErrLogDirNotFound
  toEnum 58 = RdKafkaRespErrSaslAuthenticationFailed
  toEnum 59 = RdKafkaRespErrUnknownProducerId
  toEnum 60 = RdKafkaRespErrReassignmentInProgress
  toEnum 61 = RdKafkaRespErrDelegationTokenAuthDisabled
  toEnum 62 = RdKafkaRespErrDelegationTokenNotFound
  toEnum 63 = RdKafkaRespErrDelegationTokenOwnerMismatch
  toEnum 64 = RdKafkaRespErrDelegationTokenRequestNotAllowed
  toEnum 65 = RdKafkaRespErrDelegationTokenAuthorizationFailed
  toEnum 66 = RdKafkaRespErrDelegationTokenExpired
  toEnum 67 = RdKafkaRespErrInvalidPrincipalType
  toEnum 68 = RdKafkaRespErrNonEmptyGroup
  toEnum 69 = RdKafkaRespErrGroupIdNotFound
  toEnum 70 = RdKafkaRespErrFetchSessionIdNotFound
  toEnum 71 = RdKafkaRespErrInvalidFetchSessionEpoch
  toEnum 72 = RdKafkaRespErrListenerNotFound
  toEnum 73 = RdKafkaRespErrTopicDeletionDisabled
  toEnum 74 = RdKafkaRespErrFencedLeaderEpoch
  toEnum 75 = RdKafkaRespErrUnknownLeaderEpoch
  toEnum 76 = RdKafkaRespErrUnsupportedCompressionType
  toEnum 77 = RdKafkaRespErrStaleBrokerEpoch
  toEnum 78 = RdKafkaRespErrOffsetNotAvailable
  toEnum 79 = RdKafkaRespErrMemberIdRequired
  toEnum 80 = RdKafkaRespErrPreferredLeaderNotAvailable
  toEnum 81 = RdKafkaRespErrGroupMaxSizeReached
  toEnum 82 = RdKafkaRespErrEndAll
  toEnum unmatched = error ("RdKafkaRespErrT.toEnum: Cannot match " ++ show unmatched)

{-# LINE 36 "src/Kafka/Internal/RdKafka.chs" #-}

data RdKafkaTimestampTypeT = RdKafkaTimestampNotAvailable
                           | RdKafkaTimestampCreateTime
                           | RdKafkaTimestampLogAppendTime
  deriving (Enum,Show,Eq)

{-# LINE 37 "src/Kafka/Internal/RdKafka.chs" #-}


type RdKafkaMsgFlag = Int
rdKafkaMsgFlagFree :: RdKafkaMsgFlag
rdKafkaMsgFlagFree = 0x1
rdKafkaMsgFlagCopy :: RdKafkaMsgFlag
rdKafkaMsgFlagCopy = 0x2

-- Number of bytes allocated for an error buffer
nErrorBytes ::  Int
nErrorBytes = 1024 * 8

-- Helper functions
rdKafkaVersion :: (Int)
rdKafkaVersion =
  C2HSImp.unsafePerformIO $
  rdKafkaVersion'_ >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 51 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaVersionStr :: (String)
rdKafkaVersionStr =
  C2HSImp.unsafePerformIO $
  rdKafkaVersionStr'_ >>= \res ->
  C2HSImp.peekCString res >>= \res' ->
  return (res')

{-# LINE 54 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaErr2str :: (RdKafkaRespErrT) -> (String)
rdKafkaErr2str a1 =
  C2HSImp.unsafePerformIO $
  let {a1' = enumToCInt a1} in
  rdKafkaErr2str'_ a1' >>= \res ->
  C2HSImp.peekCString res >>= \res' ->
  return (res')

{-# LINE 57 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaErr2name :: (RdKafkaRespErrT) -> (String)
rdKafkaErr2name a1 =
  C2HSImp.unsafePerformIO $
  let {a1' = enumToCInt a1} in
  rdKafkaErr2name'_ a1' >>= \res ->
  C2HSImp.peekCString res >>= \res' ->
  return (res')

{-# LINE 60 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaErrno2err :: (Int) -> (RdKafkaRespErrT)
rdKafkaErrno2err a1 =
  C2HSImp.unsafePerformIO $
  let {a1' = fromIntegral a1} in
  rdKafkaErrno2err'_ a1' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 63 "src/Kafka/Internal/RdKafka.chs" #-}


peekCAText :: CString -> IO Text
peekCAText cp = Text.pack <$> peekCAString cp

peekCText :: CString -> IO Text
peekCText cp = Text.pack <$> peekCString cp

kafkaErrnoString :: IO String
kafkaErrnoString = do
    (Errno num) <- getErrno
    return $ rdKafkaErr2str $ rdKafkaErrno2err (fromIntegral num)

-- Kafka Pointer Types
data RdKafkaConfT
type RdKafkaConfTPtr = C2HSImp.ForeignPtr (RdKafkaConfT)
{-# LINE 78 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaTopicConfT
type RdKafkaTopicConfTPtr = C2HSImp.ForeignPtr (RdKafkaTopicConfT)
{-# LINE 81 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaT
type RdKafkaTPtr = C2HSImp.ForeignPtr (RdKafkaT)
{-# LINE 84 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaTopicPartitionT = RdKafkaTopicPartitionT
    { topic'RdKafkaTopicPartitionT :: CString
    , partition'RdKafkaTopicPartitionT :: Int
    , offset'RdKafkaTopicPartitionT :: Int64
    , metadata'RdKafkaTopicPartitionT :: Word8Ptr
    , metadataSize'RdKafkaTopicPartitionT :: Int
    , opaque'RdKafkaTopicPartitionT :: Word8Ptr
    , err'RdKafkaTopicPartitionT :: RdKafkaRespErrT
    } deriving (Show, Eq)

instance Storable RdKafkaTopicPartitionT where
    alignment _ = 8
{-# LINE 97 "src/Kafka/Internal/RdKafka.chs" #-}

    sizeOf _ = 64
{-# LINE 98 "src/Kafka/Internal/RdKafka.chs" #-}

    peek p = RdKafkaTopicPartitionT
        <$> liftM id           ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
        <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CInt}) p)
        <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO C2HSImp.CLLong}) p)
        <*> liftM castPtr      ((\ptr -> do {C2HSImp.peekByteOff ptr 24 :: IO (C2HSImp.Ptr ())}) p)
        <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 32 :: IO C2HSImp.CULong}) p)
        <*> liftM castPtr      ((\ptr -> do {C2HSImp.peekByteOff ptr 40 :: IO (C2HSImp.Ptr ())}) p)
        <*> liftM cIntToEnum   ((\ptr -> do {C2HSImp.peekByteOff ptr 48 :: IO C2HSImp.CInt}) p)
    poke p x = do
        (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: (C2HSImp.Ptr C2HSImp.CChar))})         p (id           $ topic'RdKafkaTopicPartitionT x)
        (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: C2HSImp.CInt)})     p (fromIntegral $ partition'RdKafkaTopicPartitionT x)
        (\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: C2HSImp.CLLong)})        p (fromIntegral $ offset'RdKafkaTopicPartitionT x)
        (\ptr val -> do {C2HSImp.pokeByteOff ptr 24 (val :: (C2HSImp.Ptr ()))})      p (castPtr      $ metadata'RdKafkaTopicPartitionT x)
        (\ptr val -> do {C2HSImp.pokeByteOff ptr 32 (val :: C2HSImp.CULong)}) p (fromIntegral $ metadataSize'RdKafkaTopicPartitionT x)
        (\ptr val -> do {C2HSImp.pokeByteOff ptr 40 (val :: (C2HSImp.Ptr ()))})        p (castPtr      $ opaque'RdKafkaTopicPartitionT x)
        (\ptr val -> do {C2HSImp.pokeByteOff ptr 48 (val :: C2HSImp.CInt)})           p (enumToCInt   $ err'RdKafkaTopicPartitionT x)

type RdKafkaTopicPartitionTPtr = C2HSImp.ForeignPtr (RdKafkaTopicPartitionT)
{-# LINE 116 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaTopicPartitionListT = RdKafkaTopicPartitionListT
    { cnt'RdKafkaTopicPartitionListT   :: Int
    , size'RdKafkaTopicPartitionListT  :: Int
    , elems'RdKafkaTopicPartitionListT :: Ptr RdKafkaTopicPartitionT
    } deriving (Show, Eq)

type RdKafkaTopicPartitionListTPtr = C2HSImp.ForeignPtr (RdKafkaTopicPartitionListT)
{-# LINE 124 "src/Kafka/Internal/RdKafka.chs" #-}


instance Storable RdKafkaTopicPartitionListT where
  alignment _ = 8
{-# LINE 127 "src/Kafka/Internal/RdKafka.chs" #-}

  sizeOf _    = 16
{-# LINE 128 "src/Kafka/Internal/RdKafka.chs" #-}

  peek p = RdKafkaTopicPartitionListT
    <$> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CInt}) p)
    <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 4 :: IO C2HSImp.CInt}) p)
    <*> liftM castPtr      ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO (C2HSImp.Ptr (RdKafkaTopicPartitionT))}) p)
  poke p x = do
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: C2HSImp.CInt)})   p (fromIntegral $ cnt'RdKafkaTopicPartitionListT x)
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 4 (val :: C2HSImp.CInt)})  p (fromIntegral $ size'RdKafkaTopicPartitionListT x)
    (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: (C2HSImp.Ptr (RdKafkaTopicPartitionT)))}) p (castPtr      $ elems'RdKafkaTopicPartitionListT x)

data RdKafkaTopicT
type RdKafkaTopicTPtr = C2HSImp.ForeignPtr (RdKafkaTopicT)
{-# LINE 139 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaMessageT = RdKafkaMessageT
    { err'RdKafkaMessageT :: RdKafkaRespErrT
    , topic'RdKafkaMessageT :: Ptr RdKafkaTopicT
    , partition'RdKafkaMessageT :: Int
    , len'RdKafkaMessageT :: Int
    , keyLen'RdKafkaMessageT :: Int
    , offset'RdKafkaMessageT :: Int64
    , payload'RdKafkaMessageT :: Word8Ptr
    , key'RdKafkaMessageT :: Word8Ptr
    , opaque'RdKafkaMessageT :: Ptr ()
    }
    deriving (Show, Eq)

instance Storable RdKafkaMessageT where
    alignment _ = 8
{-# LINE 155 "src/Kafka/Internal/RdKafka.chs" #-}

    sizeOf _ = 72
{-# LINE 156 "src/Kafka/Internal/RdKafka.chs" #-}

    peek p = RdKafkaMessageT
        <$> liftM cIntToEnum    ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CInt}) p)
        <*> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO (C2HSImp.Ptr (RdKafkaTopicT))}) p)
        <*> liftM fromIntegral  ((\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO C2HSImp.CInt}) p)
        <*> liftM fromIntegral  ((\ptr -> do {C2HSImp.peekByteOff ptr 32 :: IO C2HSImp.CULong}) p)
        <*> liftM fromIntegral  ((\ptr -> do {C2HSImp.peekByteOff ptr 48 :: IO C2HSImp.CULong}) p)
        <*> liftM fromIntegral  ((\ptr -> do {C2HSImp.peekByteOff ptr 56 :: IO C2HSImp.CLLong}) p)
        <*> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 24 :: IO (C2HSImp.Ptr ())}) p)
        <*> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 40 :: IO (C2HSImp.Ptr ())}) p)
        <*> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 64 :: IO (C2HSImp.Ptr ())}) p)
    poke p x = do
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: C2HSImp.CInt)})        p (enumToCInt   $ err'RdKafkaMessageT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: (C2HSImp.Ptr (RdKafkaTopicT)))})        p (castPtr      $ topic'RdKafkaMessageT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: C2HSImp.CInt)})  p (fromIntegral $ partition'RdKafkaMessageT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 32 (val :: C2HSImp.CULong)})        p (fromIntegral $ len'RdKafkaMessageT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 48 (val :: C2HSImp.CULong)})    p (fromIntegral $ keyLen'RdKafkaMessageT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 56 (val :: C2HSImp.CLLong)})     p (fromIntegral $ offset'RdKafkaMessageT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 24 (val :: (C2HSImp.Ptr ()))})    p (castPtr      $ payload'RdKafkaMessageT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 40 (val :: (C2HSImp.Ptr ()))})        p (castPtr      $ key'RdKafkaMessageT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 64 (val :: (C2HSImp.Ptr ()))})   p (castPtr      $ opaque'RdKafkaMessageT x)

type RdKafkaMessageTPtr = C2HSImp.ForeignPtr (RdKafkaMessageT)
{-# LINE 178 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaMetadataBrokerT = RdKafkaMetadataBrokerT
  { id'RdKafkaMetadataBrokerT  :: Int
  , host'RdKafkaMetadataBrokerT :: CString
  , port'RdKafkaMetadataBrokerT :: Int
  } deriving (Show, Eq)

type RdKafkaMetadataBrokerTPtr = C2HSImp.Ptr (RdKafkaMetadataBrokerT)
{-# LINE 186 "src/Kafka/Internal/RdKafka.chs" #-}



instance Storable RdKafkaMetadataBrokerT where
  alignment _ = 8
{-# LINE 190 "src/Kafka/Internal/RdKafka.chs" #-}

  sizeOf _ = 24
{-# LINE 191 "src/Kafka/Internal/RdKafka.chs" #-}

  peek p = RdKafkaMetadataBrokerT
    <$> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CInt}) p)
    <*> liftM id ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
    <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO C2HSImp.CInt}) p)
  poke = undefined

data RdKafkaMetadataPartitionT = RdKafkaMetadataPartitionT
  { id'RdKafkaMetadataPartitionT :: Int
  , err'RdKafkaMetadataPartitionT :: RdKafkaRespErrT
  , leader'RdKafkaMetadataPartitionT :: Int
  , replicaCnt'RdKafkaMetadataPartitionT :: Int
  , replicas'RdKafkaMetadataPartitionT :: Ptr CInt32T
  , isrCnt'RdKafkaMetadataPartitionT :: Int
  , isrs'RdKafkaMetadataPartitionT :: Ptr CInt32T
  } deriving (Show, Eq)

instance Storable RdKafkaMetadataPartitionT where
  alignment _ = 8
{-# LINE 209 "src/Kafka/Internal/RdKafka.chs" #-}

  sizeOf _ = 40
{-# LINE 210 "src/Kafka/Internal/RdKafka.chs" #-}

  peek p = RdKafkaMetadataPartitionT
    <$> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CInt}) p)
    <*> liftM cIntToEnum ((\ptr -> do {C2HSImp.peekByteOff ptr 4 :: IO C2HSImp.CInt}) p)
    <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CInt}) p)
    <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 12 :: IO C2HSImp.CInt}) p)
    <*> liftM castPtr ((\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO (C2HSImp.Ptr C2HSImp.CInt)}) p)
    <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 24 :: IO C2HSImp.CInt}) p)
    <*> liftM castPtr ((\ptr -> do {C2HSImp.peekByteOff ptr 32 :: IO (C2HSImp.Ptr C2HSImp.CInt)}) p)

  poke = undefined

type RdKafkaMetadataPartitionTPtr = C2HSImp.Ptr (RdKafkaMetadataPartitionT)
{-# LINE 222 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaMetadataTopicT = RdKafkaMetadataTopicT
  { topic'RdKafkaMetadataTopicT :: CString
  , partitionCnt'RdKafkaMetadataTopicT :: Int
  , partitions'RdKafkaMetadataTopicT :: Ptr RdKafkaMetadataPartitionT
  , err'RdKafkaMetadataTopicT :: RdKafkaRespErrT
  } deriving (Show, Eq)

instance Storable RdKafkaMetadataTopicT where
  alignment _ = 8
{-# LINE 232 "src/Kafka/Internal/RdKafka.chs" #-}

  sizeOf _ = 32
{-# LINE 233 "src/Kafka/Internal/RdKafka.chs" #-}

  peek p = RdKafkaMetadataTopicT
    <$> liftM id ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
    <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CInt}) p)
    <*> liftM castPtr ((\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO (C2HSImp.Ptr ())}) p)
    <*> liftM cIntToEnum ((\ptr -> do {C2HSImp.peekByteOff ptr 24 :: IO C2HSImp.CInt}) p)
  poke _ _ = undefined

type RdKafkaMetadataTopicTPtr = C2HSImp.Ptr (RdKafkaMetadataTopicT)
{-# LINE 241 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaMetadataT = RdKafkaMetadataT
  { brokerCnt'RdKafkaMetadataT :: Int
  , brokers'RdKafkaMetadataT :: RdKafkaMetadataBrokerTPtr
  , topicCnt'RdKafkaMetadataT :: Int
  , topics'RdKafkaMetadataT :: RdKafkaMetadataTopicTPtr
  , origBrokerId'RdKafkaMetadataT :: CInt32T
  } deriving (Show, Eq)

instance Storable RdKafkaMetadataT where
  alignment _ = 8
{-# LINE 252 "src/Kafka/Internal/RdKafka.chs" #-}

  sizeOf _ = 48
{-# LINE 253 "src/Kafka/Internal/RdKafka.chs" #-}

  peek p = RdKafkaMetadataT
    <$> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO C2HSImp.CInt}) p)
    <*> liftM castPtr ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO (C2HSImp.Ptr ())}) p)
    <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO C2HSImp.CInt}) p)
    <*> liftM castPtr ((\ptr -> do {C2HSImp.peekByteOff ptr 24 :: IO (C2HSImp.Ptr ())}) p)
    <*> liftM fromIntegral ((\ptr -> do {C2HSImp.peekByteOff ptr 32 :: IO C2HSImp.CInt}) p)
  poke _ _ = undefined

type RdKafkaMetadataTPtr = C2HSImp.ForeignPtr (RdKafkaMetadataT)
{-# LINE 262 "src/Kafka/Internal/RdKafka.chs" #-}


-------------------------------------------------------------------------------------------------
---- Partitions
rdKafkaTopicPartitionListNew :: (Int) -> IO ((RdKafkaTopicPartitionListTPtr))
rdKafkaTopicPartitionListNew a1 =
  let {a1' = fromIntegral a1} in
  rdKafkaTopicPartitionListNew'_ a1' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 267 "src/Kafka/Internal/RdKafka.chs" #-}


foreign import ccall unsafe "rdkafka.h &rd_kafka_topic_partition_list_destroy"
    rdKafkaTopicPartitionListDestroy :: FinalizerPtr RdKafkaTopicPartitionListT

newRdKafkaTopicPartitionListT :: Int -> IO RdKafkaTopicPartitionListTPtr
newRdKafkaTopicPartitionListT size = do
    ret <- rdKafkaTopicPartitionListNew size
    addForeignPtrFinalizer rdKafkaTopicPartitionListDestroy ret
    return ret

rdKafkaTopicPartitionListAdd :: (RdKafkaTopicPartitionListTPtr) -> (String) -> (Int) -> IO ((RdKafkaTopicPartitionTPtr))
rdKafkaTopicPartitionListAdd a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  let {a3' = fromIntegral a3} in
  rdKafkaTopicPartitionListAdd'_ a1' a2' a3' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 279 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaTopicPartitionListAddRange :: (RdKafkaTopicPartitionListTPtr) -> (String) -> (Int) -> (Int) -> IO ()
rdKafkaTopicPartitionListAddRange a1 a2 a3 a4 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  let {a3' = fromIntegral a3} in
  let {a4' = fromIntegral a4} in
  rdKafkaTopicPartitionListAddRange'_ a1' a2' a3' a4' >>
  return ()

{-# LINE 282 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaTopicPartitionListCopy :: (RdKafkaTopicPartitionListTPtr) -> IO ((RdKafkaTopicPartitionListTPtr))
rdKafkaTopicPartitionListCopy a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaTopicPartitionListCopy'_ a1' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 285 "src/Kafka/Internal/RdKafka.chs" #-}


copyRdKafkaTopicPartitionList :: RdKafkaTopicPartitionListTPtr -> IO RdKafkaTopicPartitionListTPtr
copyRdKafkaTopicPartitionList pl = do
    cp <- rdKafkaTopicPartitionListCopy pl
    addForeignPtrFinalizer rdKafkaTopicPartitionListDestroy cp
    return cp

rdKafkaTopicPartitionListSetOffset :: (RdKafkaTopicPartitionListTPtr) -> (String) -> (Int) -> (Int64) -> IO ((RdKafkaRespErrT))
rdKafkaTopicPartitionListSetOffset a1 a2 a3 a4 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  let {a3' = fromIntegral a3} in
  let {a4' = fromIntegral a4} in
  rdKafkaTopicPartitionListSetOffset'_ a1' a2' a3' a4' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 295 "src/Kafka/Internal/RdKafka.chs" #-}


---- Rebalance Callback
type RdRebalanceCallback' = Ptr RdKafkaT -> CInt -> Ptr RdKafkaTopicPartitionListT -> Ptr Word8 -> IO ()
type RdRebalanceCallback = Ptr RdKafkaT -> RdKafkaRespErrT -> Ptr RdKafkaTopicPartitionListT -> IO ()

foreign import ccall safe "wrapper"
    mkRebalanceCallback :: RdRebalanceCallback' -> IO (FunPtr RdRebalanceCallback')

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_rebalance_cb"
     rdKafkaConfSetRebalanceCb' ::
       Ptr RdKafkaConfT
       -> FunPtr RdRebalanceCallback'
       -> IO ()

rdKafkaConfSetRebalanceCb :: RdKafkaConfTPtr -> RdRebalanceCallback -> IO ()
rdKafkaConfSetRebalanceCb conf cb = do
    cb' <- mkRebalanceCallback (\k e p _ -> cb k (cIntToEnum e) p)
    withForeignPtr conf $ \c -> rdKafkaConfSetRebalanceCb' c cb'
    return ()

---- Delivery Callback
type DeliveryCallback' = Ptr RdKafkaT -> Ptr RdKafkaMessageT -> Word8Ptr -> IO ()
type DeliveryCallback = Ptr RdKafkaT -> Ptr RdKafkaMessageT -> IO ()

foreign import ccall safe "wrapper"
    mkDeliveryCallback :: DeliveryCallback' -> IO (FunPtr DeliveryCallback')

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_dr_msg_cb"
    rdKafkaConfSetDrMsgCb' :: Ptr RdKafkaConfT -> FunPtr DeliveryCallback' -> IO ()

rdKafkaConfSetDrMsgCb :: RdKafkaConfTPtr -> DeliveryCallback -> IO ()
rdKafkaConfSetDrMsgCb conf cb = do
    cb' <- mkDeliveryCallback (\k m _ -> cb k m)
    withForeignPtr conf $ \c -> rdKafkaConfSetDrMsgCb' c cb'
    return ()

---- Consume Callback
type ConsumeCallback = Ptr RdKafkaMessageT -> Word8Ptr -> IO ()

foreign import ccall safe "wrapper"
    mkConsumeCallback :: ConsumeCallback -> IO (FunPtr ConsumeCallback)

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_consume_cb"
    rdKafkaConfSetConsumeCb' :: Ptr RdKafkaConfT -> FunPtr ConsumeCallback -> IO ()

rdKafkaConfSetConsumeCb :: RdKafkaConfTPtr -> ConsumeCallback -> IO ()
rdKafkaConfSetConsumeCb conf cb = do
    cb' <- mkConsumeCallback cb
    withForeignPtr conf $ \c -> rdKafkaConfSetConsumeCb' c cb'
    return ()

---- Offset Commit Callback
type OffsetCommitCallback' = Ptr RdKafkaT -> CInt -> Ptr RdKafkaTopicPartitionListT -> Word8Ptr -> IO ()
type OffsetCommitCallback  = Ptr RdKafkaT -> RdKafkaRespErrT -> Ptr RdKafkaTopicPartitionListT -> IO ()

foreign import ccall safe "wrapper"
    mkOffsetCommitCallback :: OffsetCommitCallback' -> IO (FunPtr OffsetCommitCallback')

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_offset_commit_cb"
    rdKafkaConfSetOffsetCommitCb' :: Ptr RdKafkaConfT -> FunPtr OffsetCommitCallback' -> IO ()

rdKafkaConfSetOffsetCommitCb :: RdKafkaConfTPtr -> OffsetCommitCallback -> IO ()
rdKafkaConfSetOffsetCommitCb conf cb = do
    cb' <- mkOffsetCommitCallback (\k e p _ -> cb k (cIntToEnum e) p)
    withForeignPtr conf $ \c -> rdKafkaConfSetOffsetCommitCb' c cb'
    return ()


----- Error Callback
type ErrorCallback' = Ptr RdKafkaT -> CInt -> CString -> Word8Ptr -> IO ()
type ErrorCallback  = Ptr RdKafkaT -> RdKafkaRespErrT -> String -> IO ()

foreign import ccall safe "wrapper"
    mkErrorCallback :: ErrorCallback' -> IO (FunPtr ErrorCallback')

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_error_cb"
    rdKafkaConfSetErrorCb' :: Ptr RdKafkaConfT -> FunPtr ErrorCallback' -> IO ()

rdKafkaConfSetErrorCb :: RdKafkaConfTPtr -> ErrorCallback -> IO ()
rdKafkaConfSetErrorCb conf cb = do
    cb' <- mkErrorCallback (\k e r _ -> peekCAString r >>= cb k (cIntToEnum e))
    withForeignPtr conf $ \c -> rdKafkaConfSetErrorCb' c cb'

---- Throttle Callback
type ThrottleCallback = Ptr RdKafkaT -> CString -> Int -> Int -> Word8Ptr -> IO ()

foreign import ccall safe "wrapper"
    mkThrottleCallback :: ThrottleCallback -> IO (FunPtr ThrottleCallback)

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_throttle_cb"
    rdKafkaConfSetThrottleCb' :: Ptr RdKafkaConfT -> FunPtr ThrottleCallback -> IO ()

rdKafkaConfSetThrottleCb :: RdKafkaConfTPtr -> ThrottleCallback -> IO ()
rdKafkaConfSetThrottleCb conf cb = do
    cb' <- mkThrottleCallback cb
    withForeignPtr conf $ \c -> rdKafkaConfSetThrottleCb' c cb'
    return ()

---- Log Callback
type LogCallback' = Ptr RdKafkaT -> CInt -> CString -> CString -> IO ()
type LogCallback = Ptr RdKafkaT -> Int -> String -> String -> IO ()

foreign import ccall safe "wrapper"
    mkLogCallback :: LogCallback' -> IO (FunPtr LogCallback')

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_log_cb"
    rdKafkaConfSetLogCb' :: Ptr RdKafkaConfT -> FunPtr LogCallback' -> IO ()

rdKafkaConfSetLogCb :: RdKafkaConfTPtr -> LogCallback -> IO ()
rdKafkaConfSetLogCb conf cb = do
    cb' <- mkLogCallback $ \k l f b -> do
            f' <- peekCAString f
            b' <- peekCAString b
            cb k (cIntConv l) f' b'
    withForeignPtr conf $ \c -> rdKafkaConfSetLogCb' c cb'

---- Stats Callback
type StatsCallback' = Ptr RdKafkaT -> CString -> CSize -> Word8Ptr -> IO ()
type StatsCallback = Ptr RdKafkaT -> String -> IO ()

foreign import ccall safe "wrapper"
    mkStatsCallback :: StatsCallback' -> IO (FunPtr StatsCallback')

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_stats_cb"
    rdKafkaConfSetStatsCb' :: Ptr RdKafkaConfT -> FunPtr StatsCallback' -> IO ()

rdKafkaConfSetStatsCb :: RdKafkaConfTPtr -> StatsCallback -> IO ()
rdKafkaConfSetStatsCb conf cb = do
    cb' <- mkStatsCallback $ \k j jl _ -> peekCAStringLen (j, cIntConv jl) >>= cb k
    withForeignPtr conf $ \c -> rdKafkaConfSetStatsCb' c cb'
    return ()

---- Socket Callback
type SocketCallback = Int -> Int -> Int -> Word8Ptr -> IO ()

foreign import ccall safe "wrapper"
    mkSocketCallback :: SocketCallback -> IO (FunPtr SocketCallback)

foreign import ccall safe "rd_kafka.h rd_kafka_conf_set_socket_cb"
    rdKafkaConfSetSocketCb' :: Ptr RdKafkaConfT -> FunPtr SocketCallback -> IO ()

rdKafkaConfSetSocketCb :: RdKafkaConfTPtr -> SocketCallback -> IO ()
rdKafkaConfSetSocketCb conf cb = do
    cb' <- mkSocketCallback cb
    withForeignPtr conf $ \c -> rdKafkaConfSetSocketCb' c cb'
    return ()

rdKafkaConfSetOpaque :: (RdKafkaConfTPtr) -> (Word8Ptr) -> IO ()
rdKafkaConfSetOpaque a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = castPtr a2} in
  rdKafkaConfSetOpaque'_ a1' a2' >>
  return ()

{-# LINE 444 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaOpaque :: (RdKafkaTPtr) -> IO ((Word8Ptr))
rdKafkaOpaque a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaOpaque'_ a1' >>= \res ->
  let {res' = castPtr res} in
  return (res')

{-# LINE 447 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaConfSetDefaultTopicConf :: (RdKafkaConfTPtr) -> (RdKafkaTopicConfTPtr) -> IO ()
rdKafkaConfSetDefaultTopicConf a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaConfSetDefaultTopicConf'_ a1' a2' >>
  return ()

{-# LINE 450 "src/Kafka/Internal/RdKafka.chs" #-}


---- Partitioner Callback
type PartitionerCallback =
    Ptr RdKafkaTopicTPtr
    -> Word8Ptr    -- keydata
    -> Int         -- keylen
    -> Int         -- partition_cnt
    -> Word8Ptr    -- topic_opaque
    -> Word8Ptr    -- msg_opaque
    -> IO Int

foreign import ccall safe "wrapper"
    mkPartitionerCallback :: PartitionerCallback -> IO (FunPtr PartitionerCallback)

foreign import ccall safe "rd_kafka.h rd_kafka_topic_conf_set_partitioner_cb"
    rdKafkaTopicConfSetPartitionerCb' :: Ptr RdKafkaTopicConfT -> FunPtr PartitionerCallback -> IO ()

rdKafkaTopicConfSetPartitionerCb :: RdKafkaTopicConfTPtr -> PartitionerCallback -> IO ()
rdKafkaTopicConfSetPartitionerCb conf cb = do
    cb' <- mkPartitionerCallback cb
    withForeignPtr conf $ \c -> rdKafkaTopicConfSetPartitionerCb' c cb'
    return ()

---- Partition

rdKafkaTopicPartitionAvailable :: (RdKafkaTopicTPtr) -> (CInt32T) -> IO ((Int))
rdKafkaTopicPartitionAvailable a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = cIntConv a2} in
  rdKafkaTopicPartitionAvailable'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 477 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaMsgPartitionerRandom :: (RdKafkaTopicTPtr) -> (Word8Ptr) -> (CSize) -> (CInt32T) -> (Word8Ptr) -> (Word8Ptr) -> IO ((CInt32T))
rdKafkaMsgPartitionerRandom a1 a2 a3 a4 a5 a6 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = castPtr a2} in
  let {a3' = cIntConv a3} in
  let {a4' = cIntConv a4} in
  let {a5' = castPtr a5} in
  let {a6' = castPtr a6} in
  rdKafkaMsgPartitionerRandom'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  let {res' = cIntConv res} in
  return (res')

{-# LINE 486 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaMsgPartitionerConsistent :: (RdKafkaTopicTPtr) -> (Word8Ptr) -> (CSize) -> (CInt32T) -> (Word8Ptr) -> (Word8Ptr) -> IO ((CInt32T))
rdKafkaMsgPartitionerConsistent a1 a2 a3 a4 a5 a6 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = castPtr a2} in
  let {a3' = cIntConv a3} in
  let {a4' = cIntConv a4} in
  let {a5' = castPtr a5} in
  let {a6' = castPtr a6} in
  rdKafkaMsgPartitionerConsistent'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  let {res' = cIntConv res} in
  return (res')

{-# LINE 495 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaMsgPartitionerConsistentRandom :: (RdKafkaTopicTPtr) -> (Word8Ptr) -> (CSize) -> (CInt32T) -> (Word8Ptr) -> (Word8Ptr) -> IO ((CInt32T))
rdKafkaMsgPartitionerConsistentRandom a1 a2 a3 a4 a5 a6 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = castPtr a2} in
  let {a3' = cIntConv a3} in
  let {a4' = cIntConv a4} in
  let {a5' = castPtr a5} in
  let {a6' = castPtr a6} in
  rdKafkaMsgPartitionerConsistentRandom'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  let {res' = cIntConv res} in
  return (res')

{-# LINE 504 "src/Kafka/Internal/RdKafka.chs" #-}


---- Poll / Yield

rdKafkaYield :: (RdKafkaTPtr) -> IO ()
rdKafkaYield a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaYield'_ a1' >>
  return ()

{-# LINE 509 "src/Kafka/Internal/RdKafka.chs" #-}


---- Pause / Resume
rdKafkaPausePartitions :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaPausePartitions a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaPausePartitions'_ a1' a2' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 513 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaResumePartitions :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaResumePartitions a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaResumePartitions'_ a1' a2' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 516 "src/Kafka/Internal/RdKafka.chs" #-}


---- QUEUE
data RdKafkaQueueT
type RdKafkaQueueTPtr = C2HSImp.ForeignPtr (RdKafkaQueueT)
{-# LINE 520 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaQueueNew :: (RdKafkaTPtr) -> IO ((RdKafkaQueueTPtr))
rdKafkaQueueNew a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaQueueNew'_ a1' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 523 "src/Kafka/Internal/RdKafka.chs" #-}


foreign import ccall unsafe "rdkafka.h &rd_kafka_queue_destroy"
    rdKafkaQueueDestroyF :: FinalizerPtr RdKafkaQueueT

rdKafkaQueueDestroy :: (RdKafkaQueueTPtr) -> IO ()
rdKafkaQueueDestroy a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaQueueDestroy'_ a1' >>
  return ()

{-# LINE 529 "src/Kafka/Internal/RdKafka.chs" #-}


newRdKafkaQueue :: RdKafkaTPtr -> IO RdKafkaQueueTPtr
newRdKafkaQueue k = do
    q <- rdKafkaQueueNew k
    addForeignPtrFinalizer rdKafkaQueueDestroyF q
    return q

rdKafkaConsumeQueue :: (RdKafkaQueueTPtr) -> (Int) -> IO ((RdKafkaMessageTPtr))
rdKafkaConsumeQueue a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = fromIntegral a2} in
  rdKafkaConsumeQueue'_ a1' a2' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 538 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaQueueForward :: (RdKafkaQueueTPtr) -> (RdKafkaQueueTPtr) -> IO ()
rdKafkaQueueForward a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaQueueForward'_ a1' a2' >>
  return ()

{-# LINE 541 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaQueueGetPartition' :: (RdKafkaTPtr) -> (String) -> (Int) -> IO ((RdKafkaQueueTPtr))
rdKafkaQueueGetPartition' a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  let {a3' = fromIntegral a3} in
  rdKafkaQueueGetPartition''_ a1' a2' a3' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 544 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaQueueGetPartition :: RdKafkaTPtr -> String -> Int -> IO (Maybe RdKafkaQueueTPtr)
rdKafkaQueueGetPartition k t p = do
    ret <- rdKafkaQueueGetPartition' k t p
    withForeignPtr ret $ \realPtr ->
        if realPtr == nullPtr then return Nothing
        else do
            addForeignPtrFinalizer rdKafkaQueueDestroyF ret
            return $ Just ret

rdKafkaConsumeBatchQueue' :: (RdKafkaQueueTPtr) -> (Int) -> (Ptr (Ptr RdKafkaMessageT)) -> (CSize) -> IO ((CSize))
rdKafkaConsumeBatchQueue' a1 a2 a3 a4 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = fromIntegral a2} in
  let {a3' = castPtr a3} in
  let {a4' = cIntConv a4} in
  rdKafkaConsumeBatchQueue''_ a1' a2' a3' a4' >>= \res ->
  let {res' = cIntConv res} in
  return (res')

{-# LINE 557 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaConsumeBatchQueue :: RdKafkaQueueTPtr -> Int -> Int -> IO [RdKafkaMessageTPtr]
rdKafkaConsumeBatchQueue qptr timeout batchSize = do
  allocaArray batchSize $ \pArr -> do
    rSize <- rdKafkaConsumeBatchQueue' qptr timeout pArr (fromIntegral batchSize)
    peekArray (fromIntegral rSize) pArr >>= traverse newForeignPtr_

-------------------------------------------------------------------------------------------------
---- High-level KafkaConsumer

rdKafkaSubscribe :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaSubscribe a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaSubscribe'_ a1' a2' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 570 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaUnsubscribe :: (RdKafkaTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaUnsubscribe a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaUnsubscribe'_ a1' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 574 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaSubscription' :: (RdKafkaTPtr) -> IO ((RdKafkaRespErrT), (Ptr RdKafkaTopicPartitionListT))
rdKafkaSubscription' a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  alloca $ \a2' ->
  rdKafkaSubscription''_ a1' a2' >>= \res ->
  let {res' = cIntToEnum res} in
  peekPtr  a2'>>= \a2'' ->
  return (res', a2'')

{-# LINE 578 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaSubscription :: RdKafkaTPtr -> IO (Either RdKafkaRespErrT RdKafkaTopicPartitionListTPtr)
rdKafkaSubscription k = do
    (err, sub) <- rdKafkaSubscription' k
    case err of
        RdKafkaRespErrNoError ->
            Right <$> newForeignPtr rdKafkaTopicPartitionListDestroy sub
        e -> return (Left e)

rdKafkaConsumerPoll :: (RdKafkaTPtr) -> (Int) -> IO ((RdKafkaMessageTPtr))
rdKafkaConsumerPoll a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = fromIntegral a2} in
  rdKafkaConsumerPoll'_ a1' a2' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 589 "src/Kafka/Internal/RdKafka.chs" #-}


pollRdKafkaConsumer :: RdKafkaTPtr -> Int -> IO RdKafkaMessageTPtr
pollRdKafkaConsumer k t = do
    m <- rdKafkaConsumerPoll k t
    addForeignPtrFinalizer rdKafkaMessageDestroyF m
    return m

rdKafkaConsumerClose :: (RdKafkaTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaConsumerClose a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaConsumerClose'_ a1' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 598 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaPollSetConsumer :: (RdKafkaTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaPollSetConsumer a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaPollSetConsumer'_ a1' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 601 "src/Kafka/Internal/RdKafka.chs" #-}


-- rd_kafka_assign
rdKafkaAssign :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaAssign a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaAssign'_ a1' a2' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 606 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaAssignment' :: (RdKafkaTPtr) -> IO ((RdKafkaRespErrT), (Ptr RdKafkaTopicPartitionListT))
rdKafkaAssignment' a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  alloca $ \a2' ->
  rdKafkaAssignment''_ a1' a2' >>= \res ->
  let {res' = cIntToEnum res} in
  peekPtr  a2'>>= \a2'' ->
  return (res', a2'')

{-# LINE 610 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaAssignment :: RdKafkaTPtr -> IO (Either RdKafkaRespErrT RdKafkaTopicPartitionListTPtr)
rdKafkaAssignment k = do
    (err, ass) <- rdKafkaAssignment' k
    case err of
        RdKafkaRespErrNoError ->
            Right <$> newForeignPtr rdKafkaTopicPartitionListDestroy ass
        e -> return (Left e)

rdKafkaCommit :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> (Bool) -> IO ((RdKafkaRespErrT))
rdKafkaCommit a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  let {a3' = boolToCInt a3} in
  rdKafkaCommit'_ a1' a2' a3' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 622 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaCommitMessage :: (RdKafkaTPtr) -> (RdKafkaMessageTPtr) -> (Bool) -> IO ((RdKafkaRespErrT))
rdKafkaCommitMessage a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  let {a3' = boolToCInt a3} in
  rdKafkaCommitMessage'_ a1' a2' a3' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 626 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaCommitted :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> (Int) -> IO ((RdKafkaRespErrT))
rdKafkaCommitted a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  let {a3' = fromIntegral a3} in
  rdKafkaCommitted'_ a1' a2' a3' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 630 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaPosition :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaPosition a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaPosition'_ a1' a2' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 634 "src/Kafka/Internal/RdKafka.chs" #-}


-------------------------------------------------------------------------------------------------
---- Groups
data RdKafkaGroupMemberInfoT = RdKafkaGroupMemberInfoT
    { memberId'RdKafkaGroupMemberInfoT              :: CString
    , clientId'RdKafkaGroupMemberInfoT              :: CString
    , clientHost'RdKafkaGroupMemberInfoT            :: CString
    , memberMetadata'RdKafkaGroupMemberInfoT        :: Word8Ptr
    , memberMetadataSize'RdKafkaGroupMemberInfoT    :: Int
    , memberAssignment'RdKafkaGroupMemberInfoT      :: Word8Ptr
    , memberAssignmentSize'RdKafkaGroupMemberInfoT  :: Int }

instance Storable RdKafkaGroupMemberInfoT where
    alignment _ = 8
{-# LINE 648 "src/Kafka/Internal/RdKafka.chs" #-}

    sizeOf _ = 56
{-# LINE 649 "src/Kafka/Internal/RdKafka.chs" #-}

    peek p = RdKafkaGroupMemberInfoT
        <$> liftM id            ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
        <*> liftM id            ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
        <*> liftM id            ((\ptr -> do {C2HSImp.peekByteOff ptr 16 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
        <*> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 24 :: IO (C2HSImp.Ptr ())}) p)
        <*> liftM fromIntegral  ((\ptr -> do {C2HSImp.peekByteOff ptr 32 :: IO C2HSImp.CInt}) p)
        <*> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 40 :: IO (C2HSImp.Ptr ())}) p)
        <*> liftM fromIntegral  ((\ptr -> do {C2HSImp.peekByteOff ptr 48 :: IO C2HSImp.CInt}) p)
    poke p x = do
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: (C2HSImp.Ptr C2HSImp.CChar))})              p (id           $ memberId'RdKafkaGroupMemberInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: (C2HSImp.Ptr C2HSImp.CChar))})              p (id           $ clientId'RdKafkaGroupMemberInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: (C2HSImp.Ptr C2HSImp.CChar))})            p (id           $ clientHost'RdKafkaGroupMemberInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 24 (val :: (C2HSImp.Ptr ()))})        p (castPtr      $ memberMetadata'RdKafkaGroupMemberInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 32 (val :: C2HSImp.CInt)})   p (fromIntegral $ memberMetadataSize'RdKafkaGroupMemberInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 40 (val :: (C2HSImp.Ptr ()))})      p (castPtr      $ memberAssignment'RdKafkaGroupMemberInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 48 (val :: C2HSImp.CInt)}) p (fromIntegral $ memberAssignmentSize'RdKafkaGroupMemberInfoT x)

type RdKafkaGroupMemberInfoTPtr = C2HSImp.Ptr (RdKafkaGroupMemberInfoT)
{-# LINE 667 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaGroupInfoT = RdKafkaGroupInfoT
    { broker'RdKafkaGroupInfoT       :: RdKafkaMetadataBrokerTPtr
    , group'RdKafkaGroupInfoT        :: CString
    , err'RdKafkaGroupInfoT          :: RdKafkaRespErrT
    , state'RdKafkaGroupInfoT        :: CString
    , protocolType'RdKafkaGroupInfoT :: CString
    , protocol'RdKafkaGroupInfoT     :: CString
    , members'RdKafkaGroupInfoT      :: RdKafkaGroupMemberInfoTPtr
    , memberCnt'RdKafkaGroupInfoT    :: Int }

instance Storable RdKafkaGroupInfoT where
    alignment _ = 8
{-# LINE 680 "src/Kafka/Internal/RdKafka.chs" #-}

    sizeOf _ = 80
{-# LINE 681 "src/Kafka/Internal/RdKafka.chs" #-}

    peek p = RdKafkaGroupInfoT
        <$> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr ())}) p)
        <*> liftM id            ((\ptr -> do {C2HSImp.peekByteOff ptr 24 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
        <*> liftM cIntToEnum    ((\ptr -> do {C2HSImp.peekByteOff ptr 32 :: IO C2HSImp.CInt}) p)
        <*> liftM id            ((\ptr -> do {C2HSImp.peekByteOff ptr 40 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
        <*> liftM id            ((\ptr -> do {C2HSImp.peekByteOff ptr 48 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
        <*> liftM id            ((\ptr -> do {C2HSImp.peekByteOff ptr 56 :: IO (C2HSImp.Ptr C2HSImp.CChar)}) p)
        <*> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 64 :: IO (RdKafkaGroupMemberInfoTPtr)}) p)
        <*> liftM fromIntegral  ((\ptr -> do {C2HSImp.peekByteOff ptr 72 :: IO C2HSImp.CInt}) p)
    poke p x = do
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: (C2HSImp.Ptr ()))})        p (castPtr      $ broker'RdKafkaGroupInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 24 (val :: (C2HSImp.Ptr C2HSImp.CChar))})         p (id           $ group'RdKafkaGroupInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 32 (val :: C2HSImp.CInt)})           p (enumToCInt   $ err'RdKafkaGroupInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 40 (val :: (C2HSImp.Ptr C2HSImp.CChar))})         p (id           $ state'RdKafkaGroupInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 48 (val :: (C2HSImp.Ptr C2HSImp.CChar))}) p (id           $ protocolType'RdKafkaGroupInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 56 (val :: (C2HSImp.Ptr C2HSImp.CChar))})      p (id           $ protocol'RdKafkaGroupInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 64 (val :: (RdKafkaGroupMemberInfoTPtr))})       p (castPtr      $ members'RdKafkaGroupInfoT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 72 (val :: C2HSImp.CInt)})    p (fromIntegral $ memberCnt'RdKafkaGroupInfoT x)

type RdKafkaGroupInfoTPtr = C2HSImp.ForeignPtr (RdKafkaGroupInfoT)
{-# LINE 701 "src/Kafka/Internal/RdKafka.chs" #-}


data RdKafkaGroupListT = RdKafkaGroupListT
    { groups'RdKafkaGroupListT   :: Ptr RdKafkaGroupInfoT
    , groupCnt'RdKafkaGroupListT :: Int }

instance Storable RdKafkaGroupListT where
    alignment _ = 8
{-# LINE 708 "src/Kafka/Internal/RdKafka.chs" #-}

    sizeOf _ = 16
{-# LINE 709 "src/Kafka/Internal/RdKafka.chs" #-}

    peek p = RdKafkaGroupListT
        <$> liftM castPtr       ((\ptr -> do {C2HSImp.peekByteOff ptr 0 :: IO (C2HSImp.Ptr (RdKafkaGroupInfoT))}) p)
        <*> liftM fromIntegral  ((\ptr -> do {C2HSImp.peekByteOff ptr 8 :: IO C2HSImp.CInt}) p)
    poke p x = do
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: (C2HSImp.Ptr (RdKafkaGroupInfoT)))})        p (castPtr      $ groups'RdKafkaGroupListT x)
      (\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: C2HSImp.CInt)})     p (fromIntegral $ groupCnt'RdKafkaGroupListT x)

type RdKafkaGroupListTPtr = C2HSImp.ForeignPtr (RdKafkaGroupListT)
{-# LINE 717 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaListGroups' :: (RdKafkaTPtr) -> (CString) -> (Int) -> IO ((RdKafkaRespErrT), (Ptr RdKafkaGroupListT))
rdKafkaListGroups' a1 a2 a4 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  (flip ($)) a2 $ \a2' ->
  alloca $ \a3' ->
  let {a4' = fromIntegral a4} in
  rdKafkaListGroups''_ a1' a2' a3' a4' >>= \res ->
  let {res' = cIntToEnum res} in
  peek  a3'>>= \a3'' ->
  return (res', a3'')

{-# LINE 721 "src/Kafka/Internal/RdKafka.chs" #-}


foreign import ccall "rdkafka.h &rd_kafka_group_list_destroy"
    rdKafkaGroupListDestroy :: FinalizerPtr RdKafkaGroupListT

rdKafkaListGroups :: RdKafkaTPtr -> Maybe String -> Int -> IO (Either RdKafkaRespErrT RdKafkaGroupListTPtr)
rdKafkaListGroups k g t = case g of
    Nothing -> listGroups nullPtr
    Just strGrp -> withCAString strGrp listGroups
    where
        listGroups grp = do
            (err, res) <- rdKafkaListGroups' k grp t
            case err of
                RdKafkaRespErrNoError -> Right <$> newForeignPtr rdKafkaGroupListDestroy res
                e -> return $ Left e
-------------------------------------------------------------------------------------------------

-- rd_kafka_message
foreign import ccall unsafe "rdkafka.h &rd_kafka_message_destroy"
    rdKafkaMessageDestroyF :: FinalizerPtr RdKafkaMessageT

foreign import ccall unsafe "rdkafka.h rd_kafka_message_destroy"
    rdKafkaMessageDestroy :: Ptr RdKafkaMessageT -> IO ()

rdKafkaQueryWatermarkOffsets' :: (RdKafkaTPtr) -> (String) -> (CInt32T) -> (Int) -> IO ((RdKafkaRespErrT), (Int64), (Int64))
rdKafkaQueryWatermarkOffsets' a1 a2 a3 a6 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  let {a3' = cIntConv a3} in
  alloca $ \a4' ->
  alloca $ \a5' ->
  let {a6' = cIntConv a6} in
  rdKafkaQueryWatermarkOffsets''_ a1' a2' a3' a4' a5' a6' >>= \res ->
  let {res' = cIntToEnum res} in
  peekInt64Conv  a4'>>= \a4'' ->
  peekInt64Conv  a5'>>= \a5'' ->
  return (res', a4'', a5'')

{-# LINE 749 "src/Kafka/Internal/RdKafka.chs" #-}



rdKafkaQueryWatermarkOffsets :: RdKafkaTPtr -> String -> Int -> Int -> IO (Either RdKafkaRespErrT (Int64, Int64))
rdKafkaQueryWatermarkOffsets kafka topic partition timeout = do
    (err, l, h) <- rdKafkaQueryWatermarkOffsets' kafka topic (cIntConv partition) timeout
    return $ case err of
                RdKafkaRespErrNoError -> Right (cIntConv l, cIntConv h)
                e                     -> Left e

type RdKafkaTimestampTypeTPtr = C2HSImp.ForeignPtr (RdKafkaTimestampTypeT)
{-# LINE 759 "src/Kafka/Internal/RdKafka.chs" #-}


instance Storable RdKafkaTimestampTypeT where
  sizeOf _    = 4
{-# LINE 762 "src/Kafka/Internal/RdKafka.chs" #-}

  alignment _ = 4
{-# LINE 763 "src/Kafka/Internal/RdKafka.chs" #-}

  peek p      = cIntToEnum <$> peek (castPtr p)
  poke p x    = poke (castPtr p) (enumToCInt x)

rdKafkaReadTimestamp' :: (Ptr RdKafkaMessageT) -> (RdKafkaTimestampTypeTPtr) -> IO ((CInt64T))
rdKafkaReadTimestamp' a1 a2 =
  let {a1' = castPtr a1} in
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaReadTimestamp''_ a1' a2' >>= \res ->
  let {res' = cIntConv res} in
  return (res')

{-# LINE 768 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaMessageTimestamp :: (RdKafkaMessageTPtr) -> (RdKafkaTimestampTypeTPtr) -> IO ((CInt64T))
rdKafkaMessageTimestamp a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaMessageTimestamp'_ a1' a2' >>= \res ->
  let {res' = cIntConv res} in
  return (res')

{-# LINE 771 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaOffsetsForTimes :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> (Int) -> IO ((RdKafkaRespErrT))
rdKafkaOffsetsForTimes a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  let {a3' = fromIntegral a3} in
  rdKafkaOffsetsForTimes'_ a1' a2' a3' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 774 "src/Kafka/Internal/RdKafka.chs" #-}


-- rd_kafka_conf
rdKafkaConfNew :: IO ((RdKafkaConfTPtr))
rdKafkaConfNew =
  rdKafkaConfNew'_ >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 778 "src/Kafka/Internal/RdKafka.chs" #-}


foreign import ccall unsafe "rdkafka.h &rd_kafka_conf_destroy"
    rdKafkaConfDestroy :: FinalizerPtr RdKafkaConfT

rdKafkaConfDup :: (RdKafkaConfTPtr) -> IO ((RdKafkaConfTPtr))
rdKafkaConfDup a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaConfDup'_ a1' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 784 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaConfSet :: (RdKafkaConfTPtr) -> (String) -> (String) -> (CCharBufPointer) -> (CSize) -> IO ((RdKafkaConfResT))
rdKafkaConfSet a1 a2 a3 a4 a5 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  C2HSImp.withCString a3 $ \a3' ->
  let {a4' = id a4} in
  let {a5' = cIntConv a5} in
  rdKafkaConfSet'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 788 "src/Kafka/Internal/RdKafka.chs" #-}


newRdKafkaConfT :: IO RdKafkaConfTPtr
newRdKafkaConfT = do
    ret <- rdKafkaConfNew
    addForeignPtrFinalizer rdKafkaConfDestroy ret
    return ret

rdKafkaConfDump :: (RdKafkaConfTPtr) -> (CSizePtr) -> IO ((Ptr CString))
rdKafkaConfDump a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = castPtr a2} in
  rdKafkaConfDump'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 797 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaConfDumpFree :: (Ptr CString) -> (CSize) -> IO ()
rdKafkaConfDumpFree a1 a2 =
  let {a1' = id a1} in
  let {a2' = cIntConv a2} in
  rdKafkaConfDumpFree'_ a1' a2' >>
  return ()

{-# LINE 800 "src/Kafka/Internal/RdKafka.chs" #-}


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

{-# LINE 803 "src/Kafka/Internal/RdKafka.chs" #-}


-- rd_kafka_topic_conf
rdKafkaTopicConfNew :: IO ((RdKafkaTopicConfTPtr))
rdKafkaTopicConfNew =
  rdKafkaTopicConfNew'_ >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 807 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaTopicConfDup :: (RdKafkaTopicConfTPtr) -> IO ((RdKafkaTopicConfTPtr))
rdKafkaTopicConfDup a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaTopicConfDup'_ a1' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 810 "src/Kafka/Internal/RdKafka.chs" #-}


foreign import ccall unsafe "rdkafka.h &rd_kafka_topic_conf_destroy"
    rdKafkaTopicConfDestroy :: FinalizerPtr RdKafkaTopicConfT

rdKafkaTopicConfSet :: (RdKafkaTopicConfTPtr) -> (String) -> (String) -> (CCharBufPointer) -> (CSize) -> IO ((RdKafkaConfResT))
rdKafkaTopicConfSet a1 a2 a3 a4 a5 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  C2HSImp.withCString a3 $ \a3' ->
  let {a4' = id a4} in
  let {a5' = cIntConv a5} in
  rdKafkaTopicConfSet'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 817 "src/Kafka/Internal/RdKafka.chs" #-}


newRdKafkaTopicConfT :: IO RdKafkaTopicConfTPtr
newRdKafkaTopicConfT = do
    ret <- rdKafkaTopicConfNew
    addForeignPtrFinalizer rdKafkaTopicConfDestroy ret
    return ret

rdKafkaTopicConfDump :: (RdKafkaTopicConfTPtr) -> (CSizePtr) -> IO ((Ptr CString))
rdKafkaTopicConfDump a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = castPtr a2} in
  rdKafkaTopicConfDump'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')

{-# LINE 826 "src/Kafka/Internal/RdKafka.chs" #-}


-- rd_kafka
rdKafkaNew :: (RdKafkaTypeT) -> (RdKafkaConfTPtr) -> (CCharBufPointer) -> (CSize) -> IO ((RdKafkaTPtr))
rdKafkaNew a1 a2 a3 a4 =
  let {a1' = enumToCInt a1} in
  C2HSImp.withForeignPtr a2 $ \a2' ->
  let {a3' = id a3} in
  let {a4' = cIntConv a4} in
  rdKafkaNew'_ a1' a2' a3' a4' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 831 "src/Kafka/Internal/RdKafka.chs" #-}


foreign import ccall safe "rdkafka.h &rd_kafka_destroy"
    rdKafkaDestroy :: FunPtr (Ptr RdKafkaT -> IO ())

newRdKafkaT :: RdKafkaTypeT -> RdKafkaConfTPtr -> IO (Either Text RdKafkaTPtr)
newRdKafkaT kafkaType confPtr =
    allocaBytes nErrorBytes $ \charPtr -> do
        duper <- rdKafkaConfDup confPtr
        ret <- rdKafkaNew kafkaType duper charPtr (fromIntegral nErrorBytes)
        withForeignPtr ret $ \realPtr -> do
            if realPtr == nullPtr then peekCText charPtr >>= return . Left
            else do
                -- do not call 'rd_kafka_close_consumer' on destroying all Kafka.
                -- when needed, applications should do it explicitly.
                -- {# call rd_kafka_destroy_flags #} realPtr 0x8
                addForeignPtrFinalizer rdKafkaDestroy ret
                return $ Right ret

rdKafkaBrokersAdd :: (RdKafkaTPtr) -> (String) -> IO ((Int))
rdKafkaBrokersAdd a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  rdKafkaBrokersAdd'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 851 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaSetLogLevel :: (RdKafkaTPtr) -> (Int) -> IO ()
rdKafkaSetLogLevel a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = fromIntegral a2} in
  rdKafkaSetLogLevel'_ a1' a2' >>
  return ()

{-# LINE 854 "src/Kafka/Internal/RdKafka.chs" #-}


-- rd_kafka consume

rdKafkaConsumeStartInternal :: (RdKafkaTopicTPtr) -> (CInt32T) -> (CInt64T) -> IO ((Int))
rdKafkaConsumeStartInternal a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = cIntConv a2} in
  let {a3' = cIntConv a3} in
  rdKafkaConsumeStartInternal'_ a1' a2' a3' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 859 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaConsumeStart :: RdKafkaTopicTPtr -> Int -> Int64 -> IO (Maybe String)
rdKafkaConsumeStart topicPtr partition offset = do
    i <- rdKafkaConsumeStartInternal topicPtr (fromIntegral partition) (fromIntegral offset)
    case i of
        -1 -> kafkaErrnoString >>= return . Just
        _ -> return Nothing
rdKafkaConsumeStopInternal :: (RdKafkaTopicTPtr) -> (CInt32T) -> IO ((Int))
rdKafkaConsumeStopInternal a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = cIntConv a2} in
  rdKafkaConsumeStopInternal'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 868 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaSeek :: (RdKafkaTopicTPtr) -> (Int32) -> (Int64) -> (Int) -> IO ((RdKafkaRespErrT))
rdKafkaSeek a1 a2 a3 a4 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = fromIntegral a2} in
  let {a3' = fromIntegral a3} in
  let {a4' = fromIntegral a4} in
  rdKafkaSeek'_ a1' a2' a3' a4' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 871 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaConsume :: (RdKafkaTopicTPtr) -> (CInt32T) -> (Int) -> IO ((RdKafkaMessageTPtr))
rdKafkaConsume a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = cIntConv a2} in
  let {a3' = fromIntegral a3} in
  rdKafkaConsume'_ a1' a2' a3' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 874 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaConsumeBatch :: (RdKafkaTopicTPtr) -> (CInt32T) -> (Int) -> (Ptr (Ptr RdKafkaMessageT)) -> (CSize) -> IO ((CSize))
rdKafkaConsumeBatch a1 a2 a3 a4 a5 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = cIntConv a2} in
  let {a3' = fromIntegral a3} in
  let {a4' = castPtr a4} in
  let {a5' = cIntConv a5} in
  rdKafkaConsumeBatch'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = cIntConv res} in
  return (res')

{-# LINE 878 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaConsumeStop :: RdKafkaTopicTPtr -> Int -> IO (Maybe String)
rdKafkaConsumeStop topicPtr partition = do
    i <- rdKafkaConsumeStopInternal topicPtr (fromIntegral partition)
    case i of
        -1 -> kafkaErrnoString >>= return . Just
        _ -> return Nothing

rdKafkaOffsetStore :: (RdKafkaTopicTPtr) -> (CInt32T) -> (CInt64T) -> IO ((RdKafkaRespErrT))
rdKafkaOffsetStore a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = cIntConv a2} in
  let {a3' = cIntConv a3} in
  rdKafkaOffsetStore'_ a1' a2' a3' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 889 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaOffsetsStore :: (RdKafkaTPtr) -> (RdKafkaTopicPartitionListTPtr) -> IO ((RdKafkaRespErrT))
rdKafkaOffsetsStore a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaOffsetsStore'_ a1' a2' >>= \res ->
  let {res' = cIntToEnum res} in
  return (res')

{-# LINE 893 "src/Kafka/Internal/RdKafka.chs" #-}


-- rd_kafka produce

rdKafkaProduce :: (RdKafkaTopicTPtr) -> (CInt32T) -> (Int) -> (Word8Ptr) -> (CSize) -> (Word8Ptr) -> (CSize) -> (Ptr ()) -> IO ((Int))
rdKafkaProduce a1 a2 a3 a4 a5 a6 a7 a8 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = cIntConv a2} in
  let {a3' = fromIntegral a3} in
  let {a4' = castPtr a4} in
  let {a5' = cIntConv a5} in
  let {a6' = castPtr a6} in
  let {a7' = cIntConv a7} in
  let {a8' = castPtr a8} in
  rdKafkaProduce'_ a1' a2' a3' a4' a5' a6' a7' a8' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 900 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaProduceBatch :: (RdKafkaTopicTPtr) -> (CInt32T) -> (Int) -> (RdKafkaMessageTPtr) -> (Int) -> IO ((Int))
rdKafkaProduceBatch a1 a2 a3 a4 a5 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = cIntConv a2} in
  let {a3' = fromIntegral a3} in
  C2HSImp.withForeignPtr a4 $ \a4' ->
  let {a5' = fromIntegral a5} in
  rdKafkaProduceBatch'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 903 "src/Kafka/Internal/RdKafka.chs" #-}



-- rd_kafka_metadata

rdKafkaMetadata' :: (RdKafkaTPtr) -> (Bool) -> (RdKafkaTopicTPtr) -> (Int) -> IO ((RdKafkaRespErrT), (Ptr RdKafkaMetadataT))
rdKafkaMetadata' a1 a2 a3 a5 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = boolToCInt a2} in
  C2HSImp.withForeignPtr a3 $ \a3' ->
  alloca $ \a4' ->
  let {a5' = fromIntegral a5} in
  rdKafkaMetadata''_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = cIntToEnum res} in
  peekPtr  a4'>>= \a4'' ->
  return (res', a4'')

{-# LINE 911 "src/Kafka/Internal/RdKafka.chs" #-}


foreign import ccall unsafe "rdkafka.h &rd_kafka_metadata_destroy"
    rdKafkaMetadataDestroy :: FinalizerPtr RdKafkaMetadataT

rdKafkaMetadata :: RdKafkaTPtr -> Bool -> Maybe RdKafkaTopicTPtr -> Int -> IO (Either RdKafkaRespErrT RdKafkaMetadataTPtr)
rdKafkaMetadata k allTopics mt timeout = do
    tptr <- maybe (newForeignPtr_ nullPtr) pure mt
    (err, res) <- rdKafkaMetadata' k allTopics tptr timeout
    case err of
        RdKafkaRespErrNoError -> Right <$> newForeignPtr rdKafkaMetadataDestroy res
        e -> return (Left e)

rdKafkaPoll :: (RdKafkaTPtr) -> (Int) -> IO ((Int))
rdKafkaPoll a1 a2 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  let {a2' = fromIntegral a2} in
  rdKafkaPoll'_ a1' a2' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 925 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaOutqLen :: (RdKafkaTPtr) -> IO ((Int))
rdKafkaOutqLen a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaOutqLen'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 928 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaDump :: (CFilePtr) -> (RdKafkaTPtr) -> IO ()
rdKafkaDump a1 a2 =
  let {a1' = id a1} in
  C2HSImp.withForeignPtr a2 $ \a2' ->
  rdKafkaDump'_ a1' a2' >>
  return ()

{-# LINE 931 "src/Kafka/Internal/RdKafka.chs" #-}


-- rd_kafka_topic
rdKafkaTopicName :: (RdKafkaTopicTPtr) -> IO ((String))
rdKafkaTopicName a1 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  rdKafkaTopicName'_ a1' >>= \res ->
  C2HSImp.peekCString res >>= \res' ->
  return (res')

{-# LINE 935 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaTopicNew :: (RdKafkaTPtr) -> (String) -> (RdKafkaTopicConfTPtr) -> IO ((RdKafkaTopicTPtr))
rdKafkaTopicNew a1 a2 a3 =
  C2HSImp.withForeignPtr a1 $ \a1' ->
  C2HSImp.withCString a2 $ \a2' ->
  C2HSImp.withForeignPtr a3 $ \a3' ->
  rdKafkaTopicNew'_ a1' a2' a3' >>= \res ->
  C2HSImp.newForeignPtr_ res >>= \res' ->
  return (res')

{-# LINE 938 "src/Kafka/Internal/RdKafka.chs" #-}


rdKafkaTopicDestroy :: (Ptr RdKafkaTopicT) -> IO ()
rdKafkaTopicDestroy a1 =
  let {a1' = castPtr a1} in
  rdKafkaTopicDestroy'_ a1' >>
  return ()

{-# LINE 941 "src/Kafka/Internal/RdKafka.chs" #-}


destroyUnmanagedRdKafkaTopic :: RdKafkaTopicTPtr -> IO ()
destroyUnmanagedRdKafkaTopic ptr =
  withForeignPtr ptr rdKafkaTopicDestroy

foreign import ccall unsafe "rdkafka.h &rd_kafka_topic_destroy"
    rdKafkaTopicDestroy' :: FinalizerPtr RdKafkaTopicT

newUnmanagedRdKafkaTopicT :: RdKafkaTPtr -> String -> Maybe RdKafkaTopicConfTPtr -> IO (Either String RdKafkaTopicTPtr)
newUnmanagedRdKafkaTopicT kafkaPtr topic topicConfPtr = do
    duper <- maybe (newForeignPtr_ nullPtr) rdKafkaTopicConfDup topicConfPtr
    ret <- rdKafkaTopicNew kafkaPtr topic duper
    withForeignPtr ret $ \realPtr ->
        if realPtr == nullPtr then kafkaErrnoString >>= return . Left
        else return $ Right ret

newRdKafkaTopicT :: RdKafkaTPtr -> String -> Maybe RdKafkaTopicConfTPtr -> IO (Either String RdKafkaTopicTPtr)
newRdKafkaTopicT kafkaPtr topic topicConfPtr = do
    res <- newUnmanagedRdKafkaTopicT kafkaPtr topic topicConfPtr
    _ <- traverse (addForeignPtrFinalizer rdKafkaTopicDestroy') res
    return res

-- Marshall / Unmarshall
enumToCInt :: Enum a => a -> CInt
enumToCInt = fromIntegral . fromEnum
{-# INLINE enumToCInt #-}

cIntToEnum :: Enum a => CInt -> a
cIntToEnum = toEnum . fromIntegral
{-# INLINE cIntToEnum #-}

cIntConv :: (Integral a, Num b) =>  a -> b
cIntConv = fromIntegral
{-# INLINE cIntConv #-}

boolToCInt :: Bool -> CInt
boolToCInt True = CInt 1
boolToCInt False = CInt 0
{-# INLINE boolToCInt #-}

peekInt64Conv :: (Storable a, Integral a) =>  Ptr a -> IO Int64
peekInt64Conv  = liftM cIntConv . peek
{-# INLINE peekInt64Conv #-}

peekPtr :: Ptr a -> IO (Ptr b)
peekPtr = peek . castPtr
{-# INLINE peekPtr #-}

-- Handle -> File descriptor

foreign import ccall "" fdopen :: Fd -> CString -> IO (Ptr CFile)

handleToCFile :: Handle -> String -> IO (CFilePtr)
handleToCFile h m =
 do iomode <- newCString m
    fd <- handleToFd h
    fdopen fd iomode

c_stdin :: IO CFilePtr
c_stdin = handleToCFile stdin "r"
c_stdout :: IO CFilePtr
c_stdout = handleToCFile stdout "w"
c_stderr :: IO CFilePtr
c_stderr = handleToCFile stderr "w"

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_version"
  rdKafkaVersion'_ :: (IO C2HSImp.CInt)

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_version_str"
  rdKafkaVersionStr'_ :: (IO (C2HSImp.Ptr C2HSImp.CChar))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_err2str"
  rdKafkaErr2str'_ :: (C2HSImp.CInt -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_err2name"
  rdKafkaErr2name'_ :: (C2HSImp.CInt -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_errno2err"
  rdKafkaErrno2err'_ :: (C2HSImp.CInt -> (IO C2HSImp.CInt))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_partition_list_new"
  rdKafkaTopicPartitionListNew'_ :: (C2HSImp.CInt -> (IO (C2HSImp.Ptr (RdKafkaTopicPartitionListT))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_partition_list_add"
  rdKafkaTopicPartitionListAdd'_ :: ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr (RdKafkaTopicPartitionT))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_partition_list_add_range"
  rdKafkaTopicPartitionListAddRange'_ :: ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO ())))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_partition_list_copy"
  rdKafkaTopicPartitionListCopy'_ :: ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (IO (C2HSImp.Ptr (RdKafkaTopicPartitionListT))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_partition_list_set_offset"
  rdKafkaTopicPartitionListSetOffset'_ :: ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (C2HSImp.CLLong -> (IO C2HSImp.CInt)))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_conf_set_opaque"
  rdKafkaConfSetOpaque'_ :: ((C2HSImp.Ptr (RdKafkaConfT)) -> ((C2HSImp.Ptr ()) -> (IO ())))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_opaque"
  rdKafkaOpaque'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (IO (C2HSImp.Ptr ())))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_conf_set_default_topic_conf"
  rdKafkaConfSetDefaultTopicConf'_ :: ((C2HSImp.Ptr (RdKafkaConfT)) -> ((C2HSImp.Ptr (RdKafkaTopicConfT)) -> (IO ())))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_partition_available"
  rdKafkaTopicPartitionAvailable'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_msg_partitioner_random"
  rdKafkaMsgPartitionerRandom'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> (C2HSImp.CInt -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_msg_partitioner_consistent"
  rdKafkaMsgPartitionerConsistent'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> (C2HSImp.CInt -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_msg_partitioner_consistent_random"
  rdKafkaMsgPartitionerConsistentRandom'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> (C2HSImp.CInt -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_yield"
  rdKafkaYield'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (IO ()))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_pause_partitions"
  rdKafkaPausePartitions'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_resume_partitions"
  rdKafkaResumePartitions'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_queue_new"
  rdKafkaQueueNew'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (IO (C2HSImp.Ptr (RdKafkaQueueT))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_queue_destroy"
  rdKafkaQueueDestroy'_ :: ((C2HSImp.Ptr (RdKafkaQueueT)) -> (IO ()))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_consume_queue"
  rdKafkaConsumeQueue'_ :: ((C2HSImp.Ptr (RdKafkaQueueT)) -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr (RdKafkaMessageT)))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_queue_forward"
  rdKafkaQueueForward'_ :: ((C2HSImp.Ptr (RdKafkaQueueT)) -> ((C2HSImp.Ptr (RdKafkaQueueT)) -> (IO ())))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_queue_get_partition"
  rdKafkaQueueGetPartition''_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr (RdKafkaQueueT))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_consume_batch_queue"
  rdKafkaConsumeBatchQueue''_ :: ((C2HSImp.Ptr (RdKafkaQueueT)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (RdKafkaMessageT))) -> (C2HSImp.CULong -> (IO C2HSImp.CLong)))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_subscribe"
  rdKafkaSubscribe'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_unsubscribe"
  rdKafkaUnsubscribe'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (IO C2HSImp.CInt))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_subscription"
  rdKafkaSubscription''_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (C2HSImp.Ptr (RdKafkaTopicPartitionListT))) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_consumer_poll"
  rdKafkaConsumerPoll'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr (RdKafkaMessageT)))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_consumer_close"
  rdKafkaConsumerClose'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (IO C2HSImp.CInt))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_poll_set_consumer"
  rdKafkaPollSetConsumer'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (IO C2HSImp.CInt))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_assign"
  rdKafkaAssign'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_assignment"
  rdKafkaAssignment''_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (C2HSImp.Ptr (RdKafkaTopicPartitionListT))) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_commit"
  rdKafkaCommit'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_commit_message"
  rdKafkaCommitMessage'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaMessageT)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_committed"
  rdKafkaCommitted'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_position"
  rdKafkaPosition'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_list_groups"
  rdKafkaListGroups''_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (C2HSImp.Ptr (RdKafkaGroupListT))) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_query_watermark_offsets"
  rdKafkaQueryWatermarkOffsets''_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CLLong) -> ((C2HSImp.Ptr C2HSImp.CLLong) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_message_timestamp"
  rdKafkaReadTimestamp''_ :: ((C2HSImp.Ptr (RdKafkaMessageT)) -> ((C2HSImp.Ptr (RdKafkaTimestampTypeT)) -> (IO C2HSImp.CLLong)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_message_timestamp"
  rdKafkaMessageTimestamp'_ :: ((C2HSImp.Ptr (RdKafkaMessageT)) -> ((C2HSImp.Ptr (RdKafkaTimestampTypeT)) -> (IO C2HSImp.CLLong)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_offsets_for_times"
  rdKafkaOffsetsForTimes'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_conf_new"
  rdKafkaConfNew'_ :: (IO (C2HSImp.Ptr (RdKafkaConfT)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_conf_dup"
  rdKafkaConfDup'_ :: ((C2HSImp.Ptr (RdKafkaConfT)) -> (IO (C2HSImp.Ptr (RdKafkaConfT))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_conf_set"
  rdKafkaConfSet'_ :: ((C2HSImp.Ptr (RdKafkaConfT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CULong -> (IO C2HSImp.CInt))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_conf_dump"
  rdKafkaConfDump'_ :: ((C2HSImp.Ptr (RdKafkaConfT)) -> ((C2HSImp.Ptr C2HSImp.CULong) -> (IO (C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_conf_dump_free"
  rdKafkaConfDumpFree'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (C2HSImp.CULong -> (IO ())))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_conf_properties_show"
  rdKafkaConfPropertiesShow'_ :: ((CFilePtr) -> (IO ()))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_conf_new"
  rdKafkaTopicConfNew'_ :: (IO (C2HSImp.Ptr (RdKafkaTopicConfT)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_conf_dup"
  rdKafkaTopicConfDup'_ :: ((C2HSImp.Ptr (RdKafkaTopicConfT)) -> (IO (C2HSImp.Ptr (RdKafkaTopicConfT))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_conf_set"
  rdKafkaTopicConfSet'_ :: ((C2HSImp.Ptr (RdKafkaTopicConfT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CULong -> (IO C2HSImp.CInt))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_conf_dump"
  rdKafkaTopicConfDump'_ :: ((C2HSImp.Ptr (RdKafkaTopicConfT)) -> ((C2HSImp.Ptr C2HSImp.CULong) -> (IO (C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_new"
  rdKafkaNew'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (RdKafkaConfT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CULong -> (IO (C2HSImp.Ptr (RdKafkaT)))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_brokers_add"
  rdKafkaBrokersAdd'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_set_log_level"
  rdKafkaSetLogLevel'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (C2HSImp.CInt -> (IO ())))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_consume_start"
  rdKafkaConsumeStartInternal'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (C2HSImp.CLLong -> (IO C2HSImp.CInt))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_consume_stop"
  rdKafkaConsumeStopInternal'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_seek"
  rdKafkaSeek'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (C2HSImp.CLLong -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_consume"
  rdKafkaConsume'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO (C2HSImp.Ptr (RdKafkaMessageT))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_consume_batch"
  rdKafkaConsumeBatch'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (RdKafkaMessageT))) -> (C2HSImp.CULong -> (IO C2HSImp.CLong))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_offset_store"
  rdKafkaOffsetStore'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (C2HSImp.CLLong -> (IO C2HSImp.CInt))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_offsets_store"
  rdKafkaOffsetsStore'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr (RdKafkaTopicPartitionListT)) -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_produce"
  rdKafkaProduce'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((C2HSImp.Ptr ()) -> (C2HSImp.CULong -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_produce_batch"
  rdKafkaProduceBatch'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (RdKafkaMessageT)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_metadata"
  rdKafkaMetadata''_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (RdKafkaTopicT)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_poll"
  rdKafkaPoll'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_outq_len"
  rdKafkaOutqLen'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> (IO C2HSImp.CInt))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_dump"
  rdKafkaDump'_ :: ((CFilePtr) -> ((C2HSImp.Ptr (RdKafkaT)) -> (IO ())))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_name"
  rdKafkaTopicName'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_new"
  rdKafkaTopicNew'_ :: ((C2HSImp.Ptr (RdKafkaT)) -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr (RdKafkaTopicConfT)) -> (IO (C2HSImp.Ptr (RdKafkaTopicT))))))

foreign import ccall safe "Kafka/Internal/RdKafka.chs.h rd_kafka_topic_destroy"
  rdKafkaTopicDestroy'_ :: ((C2HSImp.Ptr (RdKafkaTopicT)) -> (IO ()))