{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Database.CQL.Protocol.Response
( Response (..)
, warnings
, traceId
, unpack
, Ready (..)
, decodeReady
, Authenticate (..)
, AuthChallenge (..)
, AuthSuccess (..)
, decodeAuthenticate
, decodeAuthChallenge
, decodeAuthSuccess
, Result (..)
, MetaData (..)
, ColumnSpec (..)
, decodeResult
, decodeMetaData
, Supported (..)
, decodeSupported
, Event (..)
, TopologyChange (..)
, SchemaChange (..)
, StatusChange (..)
, Change (..)
, decodeSchemaChange
, decodeChange
, decodeEvent
, decodeTopologyChange
, decodeStatusChange
, Error (..)
, WriteType (..)
, decodeError
, decodeWriteType
) where
import Control.Applicative
import Control.Exception (Exception)
import Control.Monad
import Data.Bits
import Data.ByteString (ByteString)
import Data.Int
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Serialize hiding (Result)
import Data.Typeable
import Data.UUID (UUID)
import Data.Word
import Database.CQL.Protocol.Tuple
import Database.CQL.Protocol.Codec
import Database.CQL.Protocol.Types
import Database.CQL.Protocol.Header
import Network.Socket (SockAddr)
import Prelude
import qualified Data.ByteString.Lazy as LB
data Response k a b
= RsError (Maybe UUID) [Text] !Error
| RsReady (Maybe UUID) [Text] !Ready
| RsAuthenticate (Maybe UUID) [Text] !Authenticate
| RsAuthChallenge (Maybe UUID) [Text] !AuthChallenge
| RsAuthSuccess (Maybe UUID) [Text] !AuthSuccess
| (Maybe UUID) [Text] !Supported
| RsResult (Maybe UUID) [Text] !(Result k a b)
| RsEvent (Maybe UUID) [Text] !Event
deriving Int -> Response k a b -> ShowS
[Response k a b] -> ShowS
Response k a b -> String
(Int -> Response k a b -> ShowS)
-> (Response k a b -> String)
-> ([Response k a b] -> ShowS)
-> Show (Response k a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k a b. Show b => Int -> Response k a b -> ShowS
forall k a b. Show b => [Response k a b] -> ShowS
forall k a b. Show b => Response k a b -> String
showList :: [Response k a b] -> ShowS
$cshowList :: forall k a b. Show b => [Response k a b] -> ShowS
show :: Response k a b -> String
$cshow :: forall k a b. Show b => Response k a b -> String
showsPrec :: Int -> Response k a b -> ShowS
$cshowsPrec :: forall k a b. Show b => Int -> Response k a b -> ShowS
Show
warnings :: Response k a b -> [Text]
warnings :: Response k a b -> [Text]
warnings (RsError Maybe UUID
_ [Text]
w Error
_) = [Text]
w
warnings (RsReady Maybe UUID
_ [Text]
w Ready
_) = [Text]
w
warnings (RsAuthenticate Maybe UUID
_ [Text]
w Authenticate
_) = [Text]
w
warnings (RsAuthChallenge Maybe UUID
_ [Text]
w AuthChallenge
_) = [Text]
w
warnings (RsAuthSuccess Maybe UUID
_ [Text]
w AuthSuccess
_) = [Text]
w
warnings (RsSupported Maybe UUID
_ [Text]
w Supported
_) = [Text]
w
warnings (RsResult Maybe UUID
_ [Text]
w Result k a b
_) = [Text]
w
warnings (RsEvent Maybe UUID
_ [Text]
w Event
_) = [Text]
w
traceId :: Response k a b -> Maybe UUID
traceId :: Response k a b -> Maybe UUID
traceId (RsError Maybe UUID
x [Text]
_ Error
_) = Maybe UUID
x
traceId (RsReady Maybe UUID
x [Text]
_ Ready
_) = Maybe UUID
x
traceId (RsAuthenticate Maybe UUID
x [Text]
_ Authenticate
_) = Maybe UUID
x
traceId (RsAuthChallenge Maybe UUID
x [Text]
_ AuthChallenge
_) = Maybe UUID
x
traceId (RsAuthSuccess Maybe UUID
x [Text]
_ AuthSuccess
_) = Maybe UUID
x
traceId (RsSupported Maybe UUID
x [Text]
_ Supported
_) = Maybe UUID
x
traceId (RsResult Maybe UUID
x [Text]
_ Result k a b
_) = Maybe UUID
x
traceId (RsEvent Maybe UUID
x [Text]
_ Event
_) = Maybe UUID
x
unpack :: (Tuple a, Tuple b)
=> Compression
-> Header
-> LB.ByteString
-> Either String (Response k a b)
unpack :: Compression
-> Header -> ByteString -> Either String (Response k a b)
unpack Compression
c Header
h ByteString
b = do
let f :: Flags
f = Header -> Flags
flags Header
h
let v :: Version
v = Header -> Version
version Header
h
ByteString
x <- if Flags
compress Flags -> Flags -> Bool
`isSet` Flags
f then Compression -> ByteString -> Either String ByteString
deflate Compression
c ByteString
b else ByteString -> Either String ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
b
(Get (Response k a b)
-> ByteString -> Either String (Response k a b))
-> ByteString
-> Get (Response k a b)
-> Either String (Response k a b)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Get (Response k a b)
-> ByteString -> Either String (Response k a b)
forall a. Get a -> ByteString -> Either String a
runGetLazy ByteString
x (Get (Response k a b) -> Either String (Response k a b))
-> Get (Response k a b) -> Either String (Response k a b)
forall a b. (a -> b) -> a -> b
$ do
Maybe UUID
t <- if Flags
tracing Flags -> Flags -> Bool
`isSet` Flags
f then UUID -> Maybe UUID
forall a. a -> Maybe a
Just (UUID -> Maybe UUID) -> Get UUID -> Get (Maybe UUID)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get UUID
decodeUUID else Maybe UUID -> Get (Maybe UUID)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe UUID
forall a. Maybe a
Nothing
[Text]
w <- if Flags
warning Flags -> Flags -> Bool
`isSet` Flags
f then Get [Text]
decodeList else [Text] -> Get [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return []
Version -> Maybe UUID -> [Text] -> OpCode -> Get (Response k a b)
forall a b k.
(Tuple a, Tuple b) =>
Version -> Maybe UUID -> [Text] -> OpCode -> Get (Response k a b)
message Version
v Maybe UUID
t [Text]
w (Header -> OpCode
opCode Header
h)
where
message :: Version -> Maybe UUID -> [Text] -> OpCode -> Get (Response k a b)
message Version
_ Maybe UUID
t [Text]
w OpCode
OcError = Maybe UUID -> [Text] -> Error -> Response k a b
forall k a b. Maybe UUID -> [Text] -> Error -> Response k a b
RsError Maybe UUID
t [Text]
w (Error -> Response k a b) -> Get Error -> Get (Response k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Error
decodeError
message Version
_ Maybe UUID
t [Text]
w OpCode
OcReady = Maybe UUID -> [Text] -> Ready -> Response k a b
forall k a b. Maybe UUID -> [Text] -> Ready -> Response k a b
RsReady Maybe UUID
t [Text]
w (Ready -> Response k a b) -> Get Ready -> Get (Response k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Ready
decodeReady
message Version
_ Maybe UUID
t [Text]
w OpCode
OcAuthenticate = Maybe UUID -> [Text] -> Authenticate -> Response k a b
forall k a b.
Maybe UUID -> [Text] -> Authenticate -> Response k a b
RsAuthenticate Maybe UUID
t [Text]
w (Authenticate -> Response k a b)
-> Get Authenticate -> Get (Response k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Authenticate
decodeAuthenticate
message Version
_ Maybe UUID
t [Text]
w OpCode
OcSupported = Maybe UUID -> [Text] -> Supported -> Response k a b
forall k a b. Maybe UUID -> [Text] -> Supported -> Response k a b
RsSupported Maybe UUID
t [Text]
w (Supported -> Response k a b)
-> Get Supported -> Get (Response k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Supported
decodeSupported
message Version
v Maybe UUID
t [Text]
w OpCode
OcResult = Maybe UUID -> [Text] -> Result k a b -> Response k a b
forall k a b.
Maybe UUID -> [Text] -> Result k a b -> Response k a b
RsResult Maybe UUID
t [Text]
w (Result k a b -> Response k a b)
-> Get (Result k a b) -> Get (Response k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version -> Get (Result k a b)
forall k a b. (Tuple a, Tuple b) => Version -> Get (Result k a b)
decodeResult Version
v
message Version
v Maybe UUID
t [Text]
w OpCode
OcEvent = Maybe UUID -> [Text] -> Event -> Response k a b
forall k a b. Maybe UUID -> [Text] -> Event -> Response k a b
RsEvent Maybe UUID
t [Text]
w (Event -> Response k a b) -> Get Event -> Get (Response k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version -> Get Event
decodeEvent Version
v
message Version
_ Maybe UUID
t [Text]
w OpCode
OcAuthChallenge = Maybe UUID -> [Text] -> AuthChallenge -> Response k a b
forall k a b.
Maybe UUID -> [Text] -> AuthChallenge -> Response k a b
RsAuthChallenge Maybe UUID
t [Text]
w (AuthChallenge -> Response k a b)
-> Get AuthChallenge -> Get (Response k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get AuthChallenge
decodeAuthChallenge
message Version
_ Maybe UUID
t [Text]
w OpCode
OcAuthSuccess = Maybe UUID -> [Text] -> AuthSuccess -> Response k a b
forall k a b. Maybe UUID -> [Text] -> AuthSuccess -> Response k a b
RsAuthSuccess Maybe UUID
t [Text]
w (AuthSuccess -> Response k a b)
-> Get AuthSuccess -> Get (Response k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get AuthSuccess
decodeAuthSuccess
message Version
_ Maybe UUID
_ [Text]
_ OpCode
other = String -> Get (Response k a b)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Response k a b)) -> String -> Get (Response k a b)
forall a b. (a -> b) -> a -> b
$ String
"decode-response: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ OpCode -> String
forall a. Show a => a -> String
show OpCode
other
deflate :: Compression -> ByteString -> Either String ByteString
deflate Compression
f ByteString
x = Either String ByteString
-> (ByteString -> Either String ByteString)
-> Maybe ByteString
-> Either String ByteString
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either String ByteString
forall b. Either String b
deflateError ByteString -> Either String ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return (Compression -> ByteString -> Maybe ByteString
expand Compression
f ByteString
x)
deflateError :: Either String b
deflateError = String -> Either String b
forall a b. a -> Either a b
Left String
"unpack: decompression failure"
newtype Authenticate = Authenticate Text deriving Int -> Authenticate -> ShowS
[Authenticate] -> ShowS
Authenticate -> String
(Int -> Authenticate -> ShowS)
-> (Authenticate -> String)
-> ([Authenticate] -> ShowS)
-> Show Authenticate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Authenticate] -> ShowS
$cshowList :: [Authenticate] -> ShowS
show :: Authenticate -> String
$cshow :: Authenticate -> String
showsPrec :: Int -> Authenticate -> ShowS
$cshowsPrec :: Int -> Authenticate -> ShowS
Show
decodeAuthenticate :: Get Authenticate
decodeAuthenticate :: Get Authenticate
decodeAuthenticate = Text -> Authenticate
Authenticate (Text -> Authenticate) -> Get Text -> Get Authenticate
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Text
decodeString
newtype AuthChallenge = AuthChallenge (Maybe LB.ByteString) deriving Int -> AuthChallenge -> ShowS
[AuthChallenge] -> ShowS
AuthChallenge -> String
(Int -> AuthChallenge -> ShowS)
-> (AuthChallenge -> String)
-> ([AuthChallenge] -> ShowS)
-> Show AuthChallenge
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthChallenge] -> ShowS
$cshowList :: [AuthChallenge] -> ShowS
show :: AuthChallenge -> String
$cshow :: AuthChallenge -> String
showsPrec :: Int -> AuthChallenge -> ShowS
$cshowsPrec :: Int -> AuthChallenge -> ShowS
Show
decodeAuthChallenge :: Get AuthChallenge
decodeAuthChallenge :: Get AuthChallenge
decodeAuthChallenge = Maybe ByteString -> AuthChallenge
AuthChallenge (Maybe ByteString -> AuthChallenge)
-> Get (Maybe ByteString) -> Get AuthChallenge
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe ByteString)
decodeBytes
newtype AuthSuccess = AuthSuccess (Maybe LB.ByteString) deriving Int -> AuthSuccess -> ShowS
[AuthSuccess] -> ShowS
AuthSuccess -> String
(Int -> AuthSuccess -> ShowS)
-> (AuthSuccess -> String)
-> ([AuthSuccess] -> ShowS)
-> Show AuthSuccess
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthSuccess] -> ShowS
$cshowList :: [AuthSuccess] -> ShowS
show :: AuthSuccess -> String
$cshow :: AuthSuccess -> String
showsPrec :: Int -> AuthSuccess -> ShowS
$cshowsPrec :: Int -> AuthSuccess -> ShowS
Show
decodeAuthSuccess :: Get AuthSuccess
decodeAuthSuccess :: Get AuthSuccess
decodeAuthSuccess = Maybe ByteString -> AuthSuccess
AuthSuccess (Maybe ByteString -> AuthSuccess)
-> Get (Maybe ByteString) -> Get AuthSuccess
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Maybe ByteString)
decodeBytes
data Ready = Ready deriving Int -> Ready -> ShowS
[Ready] -> ShowS
Ready -> String
(Int -> Ready -> ShowS)
-> (Ready -> String) -> ([Ready] -> ShowS) -> Show Ready
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ready] -> ShowS
$cshowList :: [Ready] -> ShowS
show :: Ready -> String
$cshow :: Ready -> String
showsPrec :: Int -> Ready -> ShowS
$cshowsPrec :: Int -> Ready -> ShowS
Show
decodeReady :: Get Ready
decodeReady :: Get Ready
decodeReady = Ready -> Get Ready
forall (m :: * -> *) a. Monad m => a -> m a
return Ready
Ready
data Supported = Supported [CompressionAlgorithm] [CqlVersion] deriving Int -> Supported -> ShowS
[Supported] -> ShowS
Supported -> String
(Int -> Supported -> ShowS)
-> (Supported -> String)
-> ([Supported] -> ShowS)
-> Show Supported
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Supported] -> ShowS
$cshowList :: [Supported] -> ShowS
show :: Supported -> String
$cshow :: Supported -> String
showsPrec :: Int -> Supported -> ShowS
$cshowsPrec :: Int -> Supported -> ShowS
Show
decodeSupported :: Get Supported
decodeSupported :: Get Supported
decodeSupported = do
[(Text, [Text])]
opt <- Get [(Text, [Text])]
decodeMultiMap
[CompressionAlgorithm]
cmp <- (Text -> Get CompressionAlgorithm)
-> [Text] -> Get [CompressionAlgorithm]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Text -> Get CompressionAlgorithm
forall a (m :: * -> *).
(Eq a, IsString a, MonadFail m, Show a) =>
a -> m CompressionAlgorithm
toCompression ([Text] -> Get [CompressionAlgorithm])
-> (Maybe [Text] -> [Text])
-> Maybe [Text]
-> Get [CompressionAlgorithm]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Maybe [Text] -> [Text]
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe [Text] -> Get [CompressionAlgorithm])
-> Maybe [Text] -> Get [CompressionAlgorithm]
forall a b. (a -> b) -> a -> b
$ Text -> [(Text, [Text])] -> Maybe [Text]
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"COMPRESSION" [(Text, [Text])]
opt
let v :: [CqlVersion]
v = (Text -> CqlVersion) -> [Text] -> [CqlVersion]
forall a b. (a -> b) -> [a] -> [b]
map Text -> CqlVersion
toVersion ([Text] -> [CqlVersion])
-> (Maybe [Text] -> [Text]) -> Maybe [Text] -> [CqlVersion]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Maybe [Text] -> [Text]
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe [Text] -> [CqlVersion]) -> Maybe [Text] -> [CqlVersion]
forall a b. (a -> b) -> a -> b
$ Text -> [(Text, [Text])] -> Maybe [Text]
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"CQL_VERSION" [(Text, [Text])]
opt
Supported -> Get Supported
forall (m :: * -> *) a. Monad m => a -> m a
return (Supported -> Get Supported) -> Supported -> Get Supported
forall a b. (a -> b) -> a -> b
$ [CompressionAlgorithm] -> [CqlVersion] -> Supported
Supported [CompressionAlgorithm]
cmp [CqlVersion]
v
where
toCompression :: a -> m CompressionAlgorithm
toCompression a
"snappy" = CompressionAlgorithm -> m CompressionAlgorithm
forall (m :: * -> *) a. Monad m => a -> m a
return CompressionAlgorithm
Snappy
toCompression a
"lz4" = CompressionAlgorithm -> m CompressionAlgorithm
forall (m :: * -> *) a. Monad m => a -> m a
return CompressionAlgorithm
LZ4
toCompression a
other = String -> m CompressionAlgorithm
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m CompressionAlgorithm)
-> String -> m CompressionAlgorithm
forall a b. (a -> b) -> a -> b
$
String
"decode-supported: unknown compression: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
other
toVersion :: Text -> CqlVersion
toVersion Text
"3.0.0" = CqlVersion
Cqlv300
toVersion Text
other = Text -> CqlVersion
CqlVersion Text
other
data Result k a b
= VoidResult
| RowsResult !MetaData [b]
| SetKeyspaceResult !Keyspace
| PreparedResult !(QueryId k a b) !MetaData !MetaData
| SchemaChangeResult !SchemaChange
deriving (Int -> Result k a b -> ShowS
[Result k a b] -> ShowS
Result k a b -> String
(Int -> Result k a b -> ShowS)
-> (Result k a b -> String)
-> ([Result k a b] -> ShowS)
-> Show (Result k a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k a b. Show b => Int -> Result k a b -> ShowS
forall k a b. Show b => [Result k a b] -> ShowS
forall k a b. Show b => Result k a b -> String
showList :: [Result k a b] -> ShowS
$cshowList :: forall k a b. Show b => [Result k a b] -> ShowS
show :: Result k a b -> String
$cshow :: forall k a b. Show b => Result k a b -> String
showsPrec :: Int -> Result k a b -> ShowS
$cshowsPrec :: forall k a b. Show b => Int -> Result k a b -> ShowS
Show)
data MetaData = MetaData
{ MetaData -> Int32
columnCount :: !Int32
, MetaData -> Maybe PagingState
pagingState :: Maybe PagingState
, MetaData -> [ColumnSpec]
columnSpecs :: [ColumnSpec]
, MetaData -> [Int32]
primaryKeyIndices :: [Int32]
} deriving (Int -> MetaData -> ShowS
[MetaData] -> ShowS
MetaData -> String
(Int -> MetaData -> ShowS)
-> (MetaData -> String) -> ([MetaData] -> ShowS) -> Show MetaData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetaData] -> ShowS
$cshowList :: [MetaData] -> ShowS
show :: MetaData -> String
$cshow :: MetaData -> String
showsPrec :: Int -> MetaData -> ShowS
$cshowsPrec :: Int -> MetaData -> ShowS
Show)
data ColumnSpec = ColumnSpec
{ ColumnSpec -> Keyspace
keyspace :: !Keyspace
, ColumnSpec -> Table
table :: !Table
, ColumnSpec -> Text
columnName :: !Text
, ColumnSpec -> ColumnType
columnType :: !ColumnType
} deriving (Int -> ColumnSpec -> ShowS
[ColumnSpec] -> ShowS
ColumnSpec -> String
(Int -> ColumnSpec -> ShowS)
-> (ColumnSpec -> String)
-> ([ColumnSpec] -> ShowS)
-> Show ColumnSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnSpec] -> ShowS
$cshowList :: [ColumnSpec] -> ShowS
show :: ColumnSpec -> String
$cshow :: ColumnSpec -> String
showsPrec :: Int -> ColumnSpec -> ShowS
$cshowsPrec :: Int -> ColumnSpec -> ShowS
Show)
decodeResult :: forall k a b. (Tuple a, Tuple b) => Version -> Get (Result k a b)
decodeResult :: Version -> Get (Result k a b)
decodeResult Version
v = Get Int32
decodeInt Get Int32 -> (Int32 -> Get (Result k a b)) -> Get (Result k a b)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int32 -> Get (Result k a b)
forall a b k a.
(Eq a, Num a, PrivateTuple b, Show a) =>
a -> Get (Result k a b)
go
where
go :: a -> Get (Result k a b)
go a
0x1 = Result k a b -> Get (Result k a b)
forall (m :: * -> *) a. Monad m => a -> m a
return Result k a b
forall k a b. Result k a b
VoidResult
go a
0x2 = do
MetaData
m <- Get MetaData
decodeMetaData
Int32
n <- Get Int32
decodeInt
let c :: Int
c = Tagged b Int -> Int
forall a b. Tagged a b -> b
untag (Tagged b Int
forall a. PrivateTuple a => Tagged a Int
count :: Tagged b Int)
Bool -> Get () -> Get ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Int
c Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== -Int
1 Bool -> Bool -> Bool
|| MetaData -> Int32
columnCount MetaData
m Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
c) (Get () -> Get ()) -> Get () -> Get ()
forall a b. (a -> b) -> a -> b
$
String -> Get ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get ()) -> String -> Get ()
forall a b. (a -> b) -> a -> b
$ String
"column count: "
String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int32 -> String
forall a. Show a => a -> String
show (MetaData -> Int32
columnCount MetaData
m)
String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" =/= "
String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
c
let typecheck :: [ColumnType] -> [ColumnType]
typecheck = Tagged b ([ColumnType] -> [ColumnType])
-> [ColumnType] -> [ColumnType]
forall a b. Tagged a b -> b
untag (Tagged b ([ColumnType] -> [ColumnType])
forall a. PrivateTuple a => Tagged a ([ColumnType] -> [ColumnType])
check :: Tagged b ([ColumnType] -> [ColumnType]))
let ctypes :: [ColumnType]
ctypes = (ColumnSpec -> ColumnType) -> [ColumnSpec] -> [ColumnType]
forall a b. (a -> b) -> [a] -> [b]
map ColumnSpec -> ColumnType
columnType (MetaData -> [ColumnSpec]
columnSpecs MetaData
m)
let expected :: [ColumnType]
expected = [ColumnType] -> [ColumnType]
typecheck [ColumnType]
ctypes
let message :: String
message = String
"expected: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [ColumnType] -> String
forall a. Show a => a -> String
show [ColumnType]
expected String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", but got " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [ColumnType] -> String
forall a. Show a => a -> String
show [ColumnType]
ctypes
Bool -> Get () -> Get ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([ColumnType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ColumnType]
expected) (Get () -> Get ()) -> Get () -> Get ()
forall a b. (a -> b) -> a -> b
$
String -> Get ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get ()) -> String -> Get ()
forall a b. (a -> b) -> a -> b
$ String
"column-type error: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
message
MetaData -> [b] -> Result k a b
forall k a b. MetaData -> [b] -> Result k a b
RowsResult MetaData
m ([b] -> Result k a b) -> Get [b] -> Get (Result k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Get b -> Get [b]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
n) (Version -> [ColumnType] -> Get b
forall a. PrivateTuple a => Version -> [ColumnType] -> Get a
tuple Version
v [ColumnType]
ctypes)
go a
0x3 = Keyspace -> Result k a b
forall k a b. Keyspace -> Result k a b
SetKeyspaceResult (Keyspace -> Result k a b) -> Get Keyspace -> Get (Result k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace
go a
0x4 = if Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
V4
then QueryId k a b -> MetaData -> MetaData -> Result k a b
forall k a b. QueryId k a b -> MetaData -> MetaData -> Result k a b
PreparedResult (QueryId k a b -> MetaData -> MetaData -> Result k a b)
-> Get (QueryId k a b)
-> Get (MetaData -> MetaData -> Result k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (QueryId k a b)
forall k a b. Get (QueryId k a b)
decodeQueryId Get (MetaData -> MetaData -> Result k a b)
-> Get MetaData -> Get (MetaData -> Result k a b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get MetaData
decodePreparedV4 Get (MetaData -> Result k a b)
-> Get MetaData -> Get (Result k a b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get MetaData
decodeMetaData
else QueryId k a b -> MetaData -> MetaData -> Result k a b
forall k a b. QueryId k a b -> MetaData -> MetaData -> Result k a b
PreparedResult (QueryId k a b -> MetaData -> MetaData -> Result k a b)
-> Get (QueryId k a b)
-> Get (MetaData -> MetaData -> Result k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (QueryId k a b)
forall k a b. Get (QueryId k a b)
decodeQueryId Get (MetaData -> MetaData -> Result k a b)
-> Get MetaData -> Get (MetaData -> Result k a b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get MetaData
decodeMetaData Get (MetaData -> Result k a b)
-> Get MetaData -> Get (Result k a b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get MetaData
decodeMetaData
go a
0x5 = SchemaChange -> Result k a b
forall k a b. SchemaChange -> Result k a b
SchemaChangeResult (SchemaChange -> Result k a b)
-> Get SchemaChange -> Get (Result k a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version -> Get SchemaChange
decodeSchemaChange Version
v
go a
int = String -> Get (Result k a b)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get (Result k a b)) -> String -> Get (Result k a b)
forall a b. (a -> b) -> a -> b
$ String
"decode-result: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
int
decodeMetaData :: Get MetaData
decodeMetaData :: Get MetaData
decodeMetaData = do
Int32
f <- Get Int32
decodeInt
Int32
n <- Get Int32
decodeInt
Maybe PagingState
p <- if Int32 -> Bool
forall a. Bits a => a -> Bool
hasMorePages Int32
f then Get (Maybe PagingState)
decodePagingState else Maybe PagingState -> Get (Maybe PagingState)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe PagingState
forall a. Maybe a
Nothing
if Int32 -> Bool
forall a. Bits a => a -> Bool
hasNoMetaData Int32
f
then MetaData -> Get MetaData
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaData -> Get MetaData) -> MetaData -> Get MetaData
forall a b. (a -> b) -> a -> b
$ Int32 -> Maybe PagingState -> [ColumnSpec] -> [Int32] -> MetaData
MetaData Int32
n Maybe PagingState
p [] []
else Int32 -> Maybe PagingState -> [ColumnSpec] -> [Int32] -> MetaData
MetaData Int32
n Maybe PagingState
p ([ColumnSpec] -> [Int32] -> MetaData)
-> Get [ColumnSpec] -> Get ([Int32] -> MetaData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int32 -> Bool -> Get [ColumnSpec]
forall a. Integral a => a -> Bool -> Get [ColumnSpec]
decodeSpecs Int32
n (Int32 -> Bool
forall a. Bits a => a -> Bool
hasGlobalSpec Int32
f) Get ([Int32] -> MetaData) -> Get [Int32] -> Get MetaData
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Int32] -> Get [Int32]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
where
hasGlobalSpec :: a -> Bool
hasGlobalSpec a
f = a
f a -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` Int
0
hasMorePages :: a -> Bool
hasMorePages a
f = a
f a -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` Int
1
hasNoMetaData :: a -> Bool
hasNoMetaData a
f = a
f a -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` Int
2
decodeSpecs :: a -> Bool -> Get [ColumnSpec]
decodeSpecs a
n Bool
True = do
Keyspace
k <- Get Keyspace
decodeKeyspace
Table
t <- Get Table
decodeTable
Int -> Get ColumnSpec -> Get [ColumnSpec]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
n) (Get ColumnSpec -> Get [ColumnSpec])
-> Get ColumnSpec -> Get [ColumnSpec]
forall a b. (a -> b) -> a -> b
$ Keyspace -> Table -> Text -> ColumnType -> ColumnSpec
ColumnSpec Keyspace
k Table
t
(Text -> ColumnType -> ColumnSpec)
-> Get Text -> Get (ColumnType -> ColumnSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Text
decodeString
Get (ColumnType -> ColumnSpec) -> Get ColumnType -> Get ColumnSpec
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get ColumnType
decodeColumnType
decodeSpecs a
n Bool
False =
Int -> Get ColumnSpec -> Get [ColumnSpec]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
n) (Get ColumnSpec -> Get [ColumnSpec])
-> Get ColumnSpec -> Get [ColumnSpec]
forall a b. (a -> b) -> a -> b
$ Keyspace -> Table -> Text -> ColumnType -> ColumnSpec
ColumnSpec
(Keyspace -> Table -> Text -> ColumnType -> ColumnSpec)
-> Get Keyspace -> Get (Table -> Text -> ColumnType -> ColumnSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace
Get (Table -> Text -> ColumnType -> ColumnSpec)
-> Get Table -> Get (Text -> ColumnType -> ColumnSpec)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Table
decodeTable
Get (Text -> ColumnType -> ColumnSpec)
-> Get Text -> Get (ColumnType -> ColumnSpec)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Text
decodeString
Get (ColumnType -> ColumnSpec) -> Get ColumnType -> Get ColumnSpec
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get ColumnType
decodeColumnType
decodePreparedV4 :: Get MetaData
decodePreparedV4 :: Get MetaData
decodePreparedV4 = do
Int32
f <- Get Int32
decodeInt
Int32
n <- Get Int32
decodeInt
Int32
pkCount <- Get Int32
decodeInt
[Word16]
pkis <- Int -> Get Word16 -> Get [Word16]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
pkCount) Get Word16
decodeShort
[ColumnSpec]
specs <- Int32 -> Bool -> Get [ColumnSpec]
forall a. Integral a => a -> Bool -> Get [ColumnSpec]
decodeSpecs Int32
n (Int32 -> Bool
forall a. Bits a => a -> Bool
hasGlobalSpec Int32
f)
MetaData -> Get MetaData
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaData -> Get MetaData) -> MetaData -> Get MetaData
forall a b. (a -> b) -> a -> b
$ Int32 -> Maybe PagingState -> [ColumnSpec] -> [Int32] -> MetaData
MetaData Int32
n Maybe PagingState
forall a. Maybe a
Nothing [ColumnSpec]
specs (Word16 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Int32) -> [Word16] -> [Int32]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Word16]
pkis)
where
hasGlobalSpec :: a -> Bool
hasGlobalSpec a
f = a
f a -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` Int
0
decodeSpecs :: a -> Bool -> Get [ColumnSpec]
decodeSpecs a
n Bool
True = do
Keyspace
k <- Get Keyspace
decodeKeyspace
Table
t <- Get Table
decodeTable
Int -> Get ColumnSpec -> Get [ColumnSpec]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
n) (Get ColumnSpec -> Get [ColumnSpec])
-> Get ColumnSpec -> Get [ColumnSpec]
forall a b. (a -> b) -> a -> b
$ Keyspace -> Table -> Text -> ColumnType -> ColumnSpec
ColumnSpec Keyspace
k Table
t
(Text -> ColumnType -> ColumnSpec)
-> Get Text -> Get (ColumnType -> ColumnSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Text
decodeString
Get (ColumnType -> ColumnSpec) -> Get ColumnType -> Get ColumnSpec
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get ColumnType
decodeColumnType
decodeSpecs a
n Bool
False =
Int -> Get ColumnSpec -> Get [ColumnSpec]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
n) (Get ColumnSpec -> Get [ColumnSpec])
-> Get ColumnSpec -> Get [ColumnSpec]
forall a b. (a -> b) -> a -> b
$ Keyspace -> Table -> Text -> ColumnType -> ColumnSpec
ColumnSpec
(Keyspace -> Table -> Text -> ColumnType -> ColumnSpec)
-> Get Keyspace -> Get (Table -> Text -> ColumnType -> ColumnSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace
Get (Table -> Text -> ColumnType -> ColumnSpec)
-> Get Table -> Get (Text -> ColumnType -> ColumnSpec)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Table
decodeTable
Get (Text -> ColumnType -> ColumnSpec)
-> Get Text -> Get (ColumnType -> ColumnSpec)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Text
decodeString
Get (ColumnType -> ColumnSpec) -> Get ColumnType -> Get ColumnSpec
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get ColumnType
decodeColumnType
data SchemaChange
= SchemaCreated !Change
| SchemaUpdated !Change
| SchemaDropped !Change
deriving Int -> SchemaChange -> ShowS
[SchemaChange] -> ShowS
SchemaChange -> String
(Int -> SchemaChange -> ShowS)
-> (SchemaChange -> String)
-> ([SchemaChange] -> ShowS)
-> Show SchemaChange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SchemaChange] -> ShowS
$cshowList :: [SchemaChange] -> ShowS
show :: SchemaChange -> String
$cshow :: SchemaChange -> String
showsPrec :: Int -> SchemaChange -> ShowS
$cshowsPrec :: Int -> SchemaChange -> ShowS
Show
data Change
= KeyspaceChange !Keyspace
| TableChange !Keyspace !Table
| TypeChange !Keyspace !Text
| FunctionChange !Keyspace !Text ![Text]
| AggregateChange !Keyspace !Text ![Text]
deriving Int -> Change -> ShowS
[Change] -> ShowS
Change -> String
(Int -> Change -> ShowS)
-> (Change -> String) -> ([Change] -> ShowS) -> Show Change
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Change] -> ShowS
$cshowList :: [Change] -> ShowS
show :: Change -> String
$cshow :: Change -> String
showsPrec :: Int -> Change -> ShowS
$cshowsPrec :: Int -> Change -> ShowS
Show
decodeSchemaChange :: Version -> Get SchemaChange
decodeSchemaChange :: Version -> Get SchemaChange
decodeSchemaChange Version
v = Get Text
decodeString Get Text -> (Text -> Get SchemaChange) -> Get SchemaChange
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Get SchemaChange
forall a. (Eq a, IsString a, Show a) => a -> Get SchemaChange
fromString
where
fromString :: a -> Get SchemaChange
fromString a
"CREATED" = Change -> SchemaChange
SchemaCreated (Change -> SchemaChange) -> Get Change -> Get SchemaChange
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version -> Get Change
decodeChange Version
v
fromString a
"UPDATED" = Change -> SchemaChange
SchemaUpdated (Change -> SchemaChange) -> Get Change -> Get SchemaChange
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version -> Get Change
decodeChange Version
v
fromString a
"DROPPED" = Change -> SchemaChange
SchemaDropped (Change -> SchemaChange) -> Get Change -> Get SchemaChange
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version -> Get Change
decodeChange Version
v
fromString a
other = String -> Get SchemaChange
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get SchemaChange) -> String -> Get SchemaChange
forall a b. (a -> b) -> a -> b
$ String
"decode-schema-change: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
other
decodeChange :: Version -> Get Change
decodeChange :: Version -> Get Change
decodeChange Version
V4 = Get Text
decodeString Get Text -> (Text -> Get Change) -> Get Change
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Get Change
forall a. (Eq a, IsString a, Show a) => a -> Get Change
fromString
where
fromString :: a -> Get Change
fromString a
"KEYSPACE" = Keyspace -> Change
KeyspaceChange (Keyspace -> Change) -> Get Keyspace -> Get Change
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace
fromString a
"TABLE" = Keyspace -> Table -> Change
TableChange (Keyspace -> Table -> Change)
-> Get Keyspace -> Get (Table -> Change)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace Get (Table -> Change) -> Get Table -> Get Change
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Table
decodeTable
fromString a
"TYPE" = Keyspace -> Text -> Change
TypeChange (Keyspace -> Text -> Change)
-> Get Keyspace -> Get (Text -> Change)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace Get (Text -> Change) -> Get Text -> Get Change
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Text
decodeString
fromString a
"FUNCTION" = Keyspace -> Text -> [Text] -> Change
FunctionChange (Keyspace -> Text -> [Text] -> Change)
-> Get Keyspace -> Get (Text -> [Text] -> Change)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace Get (Text -> [Text] -> Change)
-> Get Text -> Get ([Text] -> Change)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Text
decodeString Get ([Text] -> Change) -> Get [Text] -> Get Change
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [Text]
decodeList
fromString a
"AGGREGATE" = Keyspace -> Text -> [Text] -> Change
AggregateChange (Keyspace -> Text -> [Text] -> Change)
-> Get Keyspace -> Get (Text -> [Text] -> Change)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace Get (Text -> [Text] -> Change)
-> Get Text -> Get ([Text] -> Change)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Text
decodeString Get ([Text] -> Change) -> Get [Text] -> Get Change
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [Text]
decodeList
fromString a
other = String -> Get Change
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get Change) -> String -> Get Change
forall a b. (a -> b) -> a -> b
$ String
"decode-change V4: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
other
decodeChange Version
V3 = Get Text
decodeString Get Text -> (Text -> Get Change) -> Get Change
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Get Change
forall a. (Eq a, IsString a, Show a) => a -> Get Change
fromString
where
fromString :: a -> Get Change
fromString a
"KEYSPACE" = Keyspace -> Change
KeyspaceChange (Keyspace -> Change) -> Get Keyspace -> Get Change
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace
fromString a
"TABLE" = Keyspace -> Table -> Change
TableChange (Keyspace -> Table -> Change)
-> Get Keyspace -> Get (Table -> Change)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace Get (Table -> Change) -> Get Table -> Get Change
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Table
decodeTable
fromString a
"TYPE" = Keyspace -> Text -> Change
TypeChange (Keyspace -> Text -> Change)
-> Get Keyspace -> Get (Text -> Change)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace Get (Text -> Change) -> Get Text -> Get Change
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Text
decodeString
fromString a
other = String -> Get Change
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get Change) -> String -> Get Change
forall a b. (a -> b) -> a -> b
$ String
"decode-change V3: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
other
data Event
= TopologyEvent !TopologyChange !SockAddr
| StatusEvent !StatusChange !SockAddr
| SchemaEvent !SchemaChange
deriving Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Show
data TopologyChange = NewNode | RemovedNode deriving (TopologyChange -> TopologyChange -> Bool
(TopologyChange -> TopologyChange -> Bool)
-> (TopologyChange -> TopologyChange -> Bool) -> Eq TopologyChange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopologyChange -> TopologyChange -> Bool
$c/= :: TopologyChange -> TopologyChange -> Bool
== :: TopologyChange -> TopologyChange -> Bool
$c== :: TopologyChange -> TopologyChange -> Bool
Eq, Eq TopologyChange
Eq TopologyChange
-> (TopologyChange -> TopologyChange -> Ordering)
-> (TopologyChange -> TopologyChange -> Bool)
-> (TopologyChange -> TopologyChange -> Bool)
-> (TopologyChange -> TopologyChange -> Bool)
-> (TopologyChange -> TopologyChange -> Bool)
-> (TopologyChange -> TopologyChange -> TopologyChange)
-> (TopologyChange -> TopologyChange -> TopologyChange)
-> Ord TopologyChange
TopologyChange -> TopologyChange -> Bool
TopologyChange -> TopologyChange -> Ordering
TopologyChange -> TopologyChange -> TopologyChange
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TopologyChange -> TopologyChange -> TopologyChange
$cmin :: TopologyChange -> TopologyChange -> TopologyChange
max :: TopologyChange -> TopologyChange -> TopologyChange
$cmax :: TopologyChange -> TopologyChange -> TopologyChange
>= :: TopologyChange -> TopologyChange -> Bool
$c>= :: TopologyChange -> TopologyChange -> Bool
> :: TopologyChange -> TopologyChange -> Bool
$c> :: TopologyChange -> TopologyChange -> Bool
<= :: TopologyChange -> TopologyChange -> Bool
$c<= :: TopologyChange -> TopologyChange -> Bool
< :: TopologyChange -> TopologyChange -> Bool
$c< :: TopologyChange -> TopologyChange -> Bool
compare :: TopologyChange -> TopologyChange -> Ordering
$ccompare :: TopologyChange -> TopologyChange -> Ordering
$cp1Ord :: Eq TopologyChange
Ord, Int -> TopologyChange -> ShowS
[TopologyChange] -> ShowS
TopologyChange -> String
(Int -> TopologyChange -> ShowS)
-> (TopologyChange -> String)
-> ([TopologyChange] -> ShowS)
-> Show TopologyChange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopologyChange] -> ShowS
$cshowList :: [TopologyChange] -> ShowS
show :: TopologyChange -> String
$cshow :: TopologyChange -> String
showsPrec :: Int -> TopologyChange -> ShowS
$cshowsPrec :: Int -> TopologyChange -> ShowS
Show)
data StatusChange = Up | Down deriving (StatusChange -> StatusChange -> Bool
(StatusChange -> StatusChange -> Bool)
-> (StatusChange -> StatusChange -> Bool) -> Eq StatusChange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatusChange -> StatusChange -> Bool
$c/= :: StatusChange -> StatusChange -> Bool
== :: StatusChange -> StatusChange -> Bool
$c== :: StatusChange -> StatusChange -> Bool
Eq, Eq StatusChange
Eq StatusChange
-> (StatusChange -> StatusChange -> Ordering)
-> (StatusChange -> StatusChange -> Bool)
-> (StatusChange -> StatusChange -> Bool)
-> (StatusChange -> StatusChange -> Bool)
-> (StatusChange -> StatusChange -> Bool)
-> (StatusChange -> StatusChange -> StatusChange)
-> (StatusChange -> StatusChange -> StatusChange)
-> Ord StatusChange
StatusChange -> StatusChange -> Bool
StatusChange -> StatusChange -> Ordering
StatusChange -> StatusChange -> StatusChange
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: StatusChange -> StatusChange -> StatusChange
$cmin :: StatusChange -> StatusChange -> StatusChange
max :: StatusChange -> StatusChange -> StatusChange
$cmax :: StatusChange -> StatusChange -> StatusChange
>= :: StatusChange -> StatusChange -> Bool
$c>= :: StatusChange -> StatusChange -> Bool
> :: StatusChange -> StatusChange -> Bool
$c> :: StatusChange -> StatusChange -> Bool
<= :: StatusChange -> StatusChange -> Bool
$c<= :: StatusChange -> StatusChange -> Bool
< :: StatusChange -> StatusChange -> Bool
$c< :: StatusChange -> StatusChange -> Bool
compare :: StatusChange -> StatusChange -> Ordering
$ccompare :: StatusChange -> StatusChange -> Ordering
$cp1Ord :: Eq StatusChange
Ord, Int -> StatusChange -> ShowS
[StatusChange] -> ShowS
StatusChange -> String
(Int -> StatusChange -> ShowS)
-> (StatusChange -> String)
-> ([StatusChange] -> ShowS)
-> Show StatusChange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StatusChange] -> ShowS
$cshowList :: [StatusChange] -> ShowS
show :: StatusChange -> String
$cshow :: StatusChange -> String
showsPrec :: Int -> StatusChange -> ShowS
$cshowsPrec :: Int -> StatusChange -> ShowS
Show)
decodeEvent :: Version -> Get Event
decodeEvent :: Version -> Get Event
decodeEvent Version
v = Get Text
decodeString Get Text -> (Text -> Get Event) -> Get Event
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Get Event
forall a. (Eq a, IsString a, Show a) => a -> Get Event
decodeByType
where
decodeByType :: a -> Get Event
decodeByType a
"TOPOLOGY_CHANGE" = TopologyChange -> SockAddr -> Event
TopologyEvent (TopologyChange -> SockAddr -> Event)
-> Get TopologyChange -> Get (SockAddr -> Event)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get TopologyChange
decodeTopologyChange Get (SockAddr -> Event) -> Get SockAddr -> Get Event
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get SockAddr
decodeSockAddr
decodeByType a
"STATUS_CHANGE" = StatusChange -> SockAddr -> Event
StatusEvent (StatusChange -> SockAddr -> Event)
-> Get StatusChange -> Get (SockAddr -> Event)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get StatusChange
decodeStatusChange Get (SockAddr -> Event) -> Get SockAddr -> Get Event
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get SockAddr
decodeSockAddr
decodeByType a
"SCHEMA_CHANGE" = SchemaChange -> Event
SchemaEvent (SchemaChange -> Event) -> Get SchemaChange -> Get Event
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version -> Get SchemaChange
decodeSchemaChange Version
v
decodeByType a
other = String -> Get Event
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get Event) -> String -> Get Event
forall a b. (a -> b) -> a -> b
$ String
"decode-event: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
other
decodeTopologyChange :: Get TopologyChange
decodeTopologyChange :: Get TopologyChange
decodeTopologyChange = Get Text
decodeString Get Text -> (Text -> Get TopologyChange) -> Get TopologyChange
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Get TopologyChange
forall a (m :: * -> *).
(Eq a, IsString a, MonadFail m, Show a) =>
a -> m TopologyChange
fromString
where
fromString :: a -> m TopologyChange
fromString a
"NEW_NODE" = TopologyChange -> m TopologyChange
forall (m :: * -> *) a. Monad m => a -> m a
return TopologyChange
NewNode
fromString a
"REMOVED_NODE" = TopologyChange -> m TopologyChange
forall (m :: * -> *) a. Monad m => a -> m a
return TopologyChange
RemovedNode
fromString a
other = String -> m TopologyChange
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m TopologyChange) -> String -> m TopologyChange
forall a b. (a -> b) -> a -> b
$
String
"decode-topology: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
other
decodeStatusChange :: Get StatusChange
decodeStatusChange :: Get StatusChange
decodeStatusChange = Get Text
decodeString Get Text -> (Text -> Get StatusChange) -> Get StatusChange
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Get StatusChange
forall a (m :: * -> *).
(Eq a, IsString a, MonadFail m, Show a) =>
a -> m StatusChange
fromString
where
fromString :: a -> m StatusChange
fromString a
"UP" = StatusChange -> m StatusChange
forall (m :: * -> *) a. Monad m => a -> m a
return StatusChange
Up
fromString a
"DOWN" = StatusChange -> m StatusChange
forall (m :: * -> *) a. Monad m => a -> m a
return StatusChange
Down
fromString a
other = String -> m StatusChange
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m StatusChange) -> String -> m StatusChange
forall a b. (a -> b) -> a -> b
$
String
"decode-status-change: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
other
data Error
= AlreadyExists !Text !Keyspace !Table
| BadCredentials !Text
| ConfigError !Text
| FunctionFailure !Text !Keyspace !Text ![Text]
| Invalid !Text
| IsBootstrapping !Text
| Overloaded !Text
| ProtocolError !Text
| ServerError !Text
| SyntaxError !Text
| TruncateError !Text
| Unauthorized !Text
| Unprepared !Text !ByteString
| Unavailable
{ Error -> Text
unavailMessage :: !Text
, Error -> Consistency
unavailConsistency :: !Consistency
, Error -> Int32
unavailNumRequired :: !Int32
, Error -> Int32
unavailNumAlive :: !Int32
}
| ReadFailure
{ Error -> Text
rFailureMessage :: !Text
, Error -> Consistency
rFailureConsistency :: !Consistency
, Error -> Int32
rFailureNumAck :: !Int32
, Error -> Int32
rFailureNumRequired :: !Int32
, Error -> Int32
rFailureNumFailures :: !Int32
, Error -> Bool
rFailureDataPresent :: !Bool
}
| ReadTimeout
{ Error -> Text
rTimeoutMessage :: !Text
, Error -> Consistency
rTimeoutConsistency :: !Consistency
, Error -> Int32
rTimeoutNumAck :: !Int32
, Error -> Int32
rTimeoutNumRequired :: !Int32
, Error -> Bool
rTimeoutDataPresent :: !Bool
}
| WriteFailure
{ Error -> Text
wFailureMessage :: !Text
, Error -> Consistency
wFailureConsistency :: !Consistency
, Error -> Int32
wFailureNumAck :: !Int32
, Error -> Int32
wFailureNumRequired :: !Int32
, Error -> Int32
wFailureNumFailures :: !Int32
, Error -> WriteType
wFailureWriteType :: !WriteType
}
| WriteTimeout
{ Error -> Text
wTimeoutMessage :: !Text
, Error -> Consistency
wTimeoutConsistency :: !Consistency
, Error -> Int32
wTimeoutNumAck :: !Int32
, Error -> Int32
wTimeoutNumRequired :: !Int32
, Error -> WriteType
wTimeoutWriteType :: !WriteType
}
deriving (Error -> Error -> Bool
(Error -> Error -> Bool) -> (Error -> Error -> Bool) -> Eq Error
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Error -> Error -> Bool
$c/= :: Error -> Error -> Bool
== :: Error -> Error -> Bool
$c== :: Error -> Error -> Bool
Eq, Int -> Error -> ShowS
[Error] -> ShowS
Error -> String
(Int -> Error -> ShowS)
-> (Error -> String) -> ([Error] -> ShowS) -> Show Error
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Error] -> ShowS
$cshowList :: [Error] -> ShowS
show :: Error -> String
$cshow :: Error -> String
showsPrec :: Int -> Error -> ShowS
$cshowsPrec :: Int -> Error -> ShowS
Show, Typeable)
instance Exception Error
data WriteType
= WriteSimple
| WriteBatch
| WriteBatchLog
| WriteUnloggedBatch
| WriteCounter
| WriteCas
| WriteView
| WriteCdc
deriving (WriteType -> WriteType -> Bool
(WriteType -> WriteType -> Bool)
-> (WriteType -> WriteType -> Bool) -> Eq WriteType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WriteType -> WriteType -> Bool
$c/= :: WriteType -> WriteType -> Bool
== :: WriteType -> WriteType -> Bool
$c== :: WriteType -> WriteType -> Bool
Eq, Int -> WriteType -> ShowS
[WriteType] -> ShowS
WriteType -> String
(Int -> WriteType -> ShowS)
-> (WriteType -> String)
-> ([WriteType] -> ShowS)
-> Show WriteType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WriteType] -> ShowS
$cshowList :: [WriteType] -> ShowS
show :: WriteType -> String
$cshow :: WriteType -> String
showsPrec :: Int -> WriteType -> ShowS
$cshowsPrec :: Int -> WriteType -> ShowS
Show)
decodeError :: Get Error
decodeError :: Get Error
decodeError = do
Int32
code <- Get Int32
decodeInt
Text
msg <- Get Text
decodeString
Int32 -> Text -> Get Error
toError Int32
code Text
msg
where
toError :: Int32 -> Text -> Get Error
toError :: Int32 -> Text -> Get Error
toError Int32
0x0000 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
ServerError Text
m
toError Int32
0x000A Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
ProtocolError Text
m
toError Int32
0x0100 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
BadCredentials Text
m
toError Int32
0x1000 Text
m = Text -> Consistency -> Int32 -> Int32 -> Error
Unavailable Text
m (Consistency -> Int32 -> Int32 -> Error)
-> Get Consistency -> Get (Int32 -> Int32 -> Error)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Consistency
decodeConsistency Get (Int32 -> Int32 -> Error) -> Get Int32 -> Get (Int32 -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt Get (Int32 -> Error) -> Get Int32 -> Get Error
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
toError Int32
0x1001 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
Overloaded Text
m
toError Int32
0x1002 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
IsBootstrapping Text
m
toError Int32
0x1003 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
TruncateError Text
m
toError Int32
0x1100 Text
m = Text -> Consistency -> Int32 -> Int32 -> WriteType -> Error
WriteTimeout Text
m
(Consistency -> Int32 -> Int32 -> WriteType -> Error)
-> Get Consistency -> Get (Int32 -> Int32 -> WriteType -> Error)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Consistency
decodeConsistency
Get (Int32 -> Int32 -> WriteType -> Error)
-> Get Int32 -> Get (Int32 -> WriteType -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (Int32 -> WriteType -> Error)
-> Get Int32 -> Get (WriteType -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (WriteType -> Error) -> Get WriteType -> Get Error
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get WriteType
decodeWriteType
toError Int32
0x1200 Text
m = Text -> Consistency -> Int32 -> Int32 -> Bool -> Error
ReadTimeout Text
m
(Consistency -> Int32 -> Int32 -> Bool -> Error)
-> Get Consistency -> Get (Int32 -> Int32 -> Bool -> Error)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Consistency
decodeConsistency
Get (Int32 -> Int32 -> Bool -> Error)
-> Get Int32 -> Get (Int32 -> Bool -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (Int32 -> Bool -> Error) -> Get Int32 -> Get (Bool -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (Bool -> Error) -> Get Bool -> Get Error
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Word8 -> Bool
bool (Word8 -> Bool) -> Get Word8 -> Get Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word8
decodeByte)
toError Int32
0x1300 Text
m = Text -> Consistency -> Int32 -> Int32 -> Int32 -> Bool -> Error
ReadFailure Text
m
(Consistency -> Int32 -> Int32 -> Int32 -> Bool -> Error)
-> Get Consistency
-> Get (Int32 -> Int32 -> Int32 -> Bool -> Error)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Consistency
decodeConsistency
Get (Int32 -> Int32 -> Int32 -> Bool -> Error)
-> Get Int32 -> Get (Int32 -> Int32 -> Bool -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (Int32 -> Int32 -> Bool -> Error)
-> Get Int32 -> Get (Int32 -> Bool -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (Int32 -> Bool -> Error) -> Get Int32 -> Get (Bool -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (Bool -> Error) -> Get Bool -> Get Error
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Word8 -> Bool
bool (Word8 -> Bool) -> Get Word8 -> Get Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word8
decodeByte)
toError Int32
0x1400 Text
m = Text -> Keyspace -> Text -> [Text] -> Error
FunctionFailure Text
m
(Keyspace -> Text -> [Text] -> Error)
-> Get Keyspace -> Get (Text -> [Text] -> Error)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace
Get (Text -> [Text] -> Error) -> Get Text -> Get ([Text] -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Text
decodeString
Get ([Text] -> Error) -> Get [Text] -> Get Error
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [Text]
decodeList
toError Int32
0x1500 Text
m = Text
-> Consistency -> Int32 -> Int32 -> Int32 -> WriteType -> Error
WriteFailure Text
m
(Consistency -> Int32 -> Int32 -> Int32 -> WriteType -> Error)
-> Get Consistency
-> Get (Int32 -> Int32 -> Int32 -> WriteType -> Error)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Consistency
decodeConsistency
Get (Int32 -> Int32 -> Int32 -> WriteType -> Error)
-> Get Int32 -> Get (Int32 -> Int32 -> WriteType -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (Int32 -> Int32 -> WriteType -> Error)
-> Get Int32 -> Get (Int32 -> WriteType -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (Int32 -> WriteType -> Error)
-> Get Int32 -> Get (WriteType -> Error)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int32
decodeInt
Get (WriteType -> Error) -> Get WriteType -> Get Error
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get WriteType
decodeWriteType
toError Int32
0x2000 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
SyntaxError Text
m
toError Int32
0x2100 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
Unauthorized Text
m
toError Int32
0x2200 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
Invalid Text
m
toError Int32
0x2300 Text
m = Error -> Get Error
forall (m :: * -> *) a. Monad m => a -> m a
return (Error -> Get Error) -> Error -> Get Error
forall a b. (a -> b) -> a -> b
$ Text -> Error
ConfigError Text
m
toError Int32
0x2400 Text
m = Text -> Keyspace -> Table -> Error
AlreadyExists Text
m (Keyspace -> Table -> Error)
-> Get Keyspace -> Get (Table -> Error)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Keyspace
decodeKeyspace Get (Table -> Error) -> Get Table -> Get Error
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Table
decodeTable
toError Int32
0x2500 Text
m = Text -> ByteString -> Error
Unprepared Text
m (ByteString -> Error) -> Get ByteString -> Get Error
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get ByteString
decodeShortBytes
toError Int32
code Text
_ = String -> Get Error
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get Error) -> String -> Get Error
forall a b. (a -> b) -> a -> b
$ String
"decode-error: unknown: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int32 -> String
forall a. Show a => a -> String
show Int32
code
bool :: Word8 -> Bool
bool :: Word8 -> Bool
bool Word8
0 = Bool
False
bool Word8
_ = Bool
True
decodeWriteType :: Get WriteType
decodeWriteType :: Get WriteType
decodeWriteType = Get Text
decodeString Get Text -> (Text -> Get WriteType) -> Get WriteType
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Get WriteType
forall a (m :: * -> *).
(Eq a, IsString a, MonadFail m, Show a) =>
a -> m WriteType
fromString
where
fromString :: a -> m WriteType
fromString a
"SIMPLE" = WriteType -> m WriteType
forall (m :: * -> *) a. Monad m => a -> m a
return WriteType
WriteSimple
fromString a
"BATCH" = WriteType -> m WriteType
forall (m :: * -> *) a. Monad m => a -> m a
return WriteType
WriteBatch
fromString a
"BATCH_LOG" = WriteType -> m WriteType
forall (m :: * -> *) a. Monad m => a -> m a
return WriteType
WriteBatchLog
fromString a
"UNLOGGED_BATCH" = WriteType -> m WriteType
forall (m :: * -> *) a. Monad m => a -> m a
return WriteType
WriteUnloggedBatch
fromString a
"COUNTER" = WriteType -> m WriteType
forall (m :: * -> *) a. Monad m => a -> m a
return WriteType
WriteCounter
fromString a
"CAS" = WriteType -> m WriteType
forall (m :: * -> *) a. Monad m => a -> m a
return WriteType
WriteCas
fromString a
"VIEW" = WriteType -> m WriteType
forall (m :: * -> *) a. Monad m => a -> m a
return WriteType
WriteView
fromString a
"CDC" = WriteType -> m WriteType
forall (m :: * -> *) a. Monad m => a -> m a
return WriteType
WriteCdc
fromString a
unknown = String -> m WriteType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m WriteType) -> String -> m WriteType
forall a b. (a -> b) -> a -> b
$
String
"decode: unknown write-type: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
unknown