module Database.Memcache.Types (
Authentication(..), Username, Password,
Q(..), K(..), Key, Value, Extras, Initial, Delta, Expiration, Flags,
Version, Status(..),
Header(..), mEMCACHE_HEADER_SIZE, PktType(..),
Request(..), OpRequest(..), SESet(..), SEIncr(..), SETouch(..), emptyReq,
Response(..), OpResponse(..), emptyRes
) where
import Data.ByteString (ByteString)
import Data.Word
data Authentication
= Auth { username :: !Username, password :: !Password }
| NoAuth
deriving (Eq, Show)
type Username = ByteString
type Password = ByteString
mEMCACHE_HEADER_SIZE :: Int
mEMCACHE_HEADER_SIZE = 24
data Header = Header {
op :: Word8,
keyLen :: Word16,
extraLen :: Word8,
status :: Status,
bodyLen :: Word32,
opaque :: Word32,
cas :: Version
} deriving (Eq, Show)
data PktType = PktRequest | PktResponse
deriving (Eq, Show)
data Q = Loud | Quiet deriving (Eq, Show)
data K = NoKey | IncludeKey deriving (Eq, Show)
type Key = ByteString
type Value = ByteString
type Extras = ByteString
type Initial = Word64
type Delta = Word64
type Expiration = Word32
type Flags = Word32
type Version = Word64
data OpRequest
= ReqGet Q K Key
| ReqSet Q Key Value SESet
| ReqAdd Q Key Value SESet
| ReqReplace Q Key Value SESet
| ReqDelete Q Key
| ReqIncrement Q Key SEIncr
| ReqDecrement Q Key SEIncr
| ReqAppend Q Key Value
| ReqPrepend Q Key Value
| ReqTouch Key SETouch
| ReqGAT Q K Key SETouch
| ReqFlush Q (Maybe SETouch)
| ReqNoop
| ReqVersion
| ReqStat (Maybe Key)
| ReqQuit Q
| ReqSASLList
| ReqSASLStart Key Value
| ReqSASLStep Key Value
deriving (Eq, Show)
data SESet = SESet Flags Expiration deriving (Eq, Show)
data SEIncr = SEIncr Initial Delta Expiration deriving (Eq, Show)
data SETouch = SETouch Expiration deriving (Eq, Show)
data Request = Req {
reqOp :: OpRequest,
reqOpaque :: Word32,
reqCas :: Version
} deriving (Eq, Show)
emptyReq :: Request
emptyReq = Req { reqOp = ReqNoop, reqOpaque = 0, reqCas = 0 }
data OpResponse
= ResGet Q Value Flags
| ResGetK Q Key Value Flags
| ResSet Q
| ResAdd Q
| ResReplace Q
| ResDelete Q
| ResIncrement Q Word64
| ResDecrement Q Word64
| ResAppend Q
| ResPrepend Q
| ResTouch
| ResGAT Q Value Flags
| ResGATK Q Key Value Flags
| ResFlush Q
| ResNoop
| ResVersion Value
| ResStat Key Value
| ResQuit Q
| ResSASLList Value
| ResSASLStart
| ResSASLStep
deriving (Eq, Show)
data Status
= NoError
| ErrKeyNotFound
| ErrKeyExists
| ErrValueTooLarge
| ErrInvalidArgs
| ErrItemNotStored
| ErrValueNonNumeric
| ErrUnknownCommand
| ErrOutOfMemory
| SaslAuthFail
| SaslAuthContinue
deriving (Eq, Show)
data Response = Res {
resOp :: OpResponse,
resStatus :: Status,
resOpaque :: Word32,
resCas :: Version
} deriving (Eq, Show)
emptyRes :: Response
emptyRes = Res { resOp = ResNoop, resStatus = NoError, resOpaque = 0, resCas = 0 }