{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Database.ClickHouseDriver.ServerProtocol where
import Data.ByteString (ByteString)
import Data.Vector (Vector, fromList, (!?))
_HELLO :: Word
_HELLO :: Word
_HELLO = Word
0 :: Word
_DATA :: Word
_DATA :: Word
_DATA = Word
1 :: Word
_EXCEPTION :: Word
_EXCEPTION :: Word
_EXCEPTION = Word
2 :: Word
_PROGRESS :: Word
_PROGRESS :: Word
_PROGRESS = Word
3 :: Word
_PONG :: Word
_PONG :: Word
_PONG = Word
4 :: Word
_END_OF_STREAM :: Word
_END_OF_STREAM :: Word
_END_OF_STREAM = Word
5 :: Word
_PROFILE_INFO :: Word
_PROFILE_INFO :: Word
_PROFILE_INFO = Word
6 :: Word
_TOTAL :: Word
_TOTAL :: Word
_TOTAL = Word
7 :: Word
_EXTREMES :: Word
_EXTREMES :: Word
_EXTREMES = Word
8 :: Word
_TABLES_STATUS_RESPONSE :: Word
_TABLES_STATUS_RESPONSE :: Word
_TABLES_STATUS_RESPONSE = Word
9 :: Word
_LOG :: Word
_LOG :: Word
_LOG = Word
10 :: Word
_TABLE_COLUMNS :: Word
_TABLE_COLUMNS :: Word
_TABLE_COLUMNS = Word
11 :: Word
typeStr :: Vector ByteString
typeStr :: Vector ByteString
typeStr =
[ByteString] -> Vector ByteString
forall a. [a] -> Vector a
fromList
[ ByteString
"Hello",
ByteString
"Data",
ByteString
"Exception",
ByteString
"Progress",
ByteString
"Pong",
ByteString
"EndOfStream",
ByteString
"ProfileInfo",
ByteString
"Totals",
ByteString
"Extremes",
ByteString
"TablesStatusResponse",
ByteString
"Log",
ByteString
"TableColumns"
]
toString :: Int -> ByteString
toString :: Int -> ByteString
toString Int
n =
case Vector ByteString
typeStr Vector ByteString -> Int -> Maybe ByteString
forall a. Vector a -> Int -> Maybe a
!? Int
n of
Maybe ByteString
Nothing -> ByteString
"Unknown Packet"
Just ByteString
t -> ByteString
t