module Pulsar.Types where
import qualified Data.ByteString.Lazy.Char8 as CL
import Data.Char ( toLower )
import Data.String
import qualified Data.Text as T
import Proto.PulsarApi ( MessageIdData )
data Topic = Topic
{ Topic -> TopicType
type' :: TopicType
, Topic -> Tenant
tenant :: Tenant
, Topic -> NameSpace
namespace :: NameSpace
, Topic -> TopicName
name :: TopicName
}
defaultTopic :: String -> Topic
defaultTopic :: String -> Topic
defaultTopic n :: String
n = Topic :: TopicType -> Tenant -> NameSpace -> TopicName -> Topic
Topic { type' :: TopicType
type' = TopicType
NonPersistent
, tenant :: Tenant
tenant = String -> Tenant
Tenant "public"
, namespace :: NameSpace
namespace = String -> NameSpace
NameSpace "default"
, name :: TopicName
name = String -> TopicName
TopicName String
n
}
instance Show Topic where
show :: Topic -> String
show (Topic typ :: TopicType
typ tn :: Tenant
tn ns :: NameSpace
ns n :: TopicName
n) =
Char -> Char
toLower (Char -> Char) -> ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TopicType -> String
forall a. Show a => a -> String
show TopicType
typ String -> ShowS
forall a. Semigroup a => a -> a -> a
<> "://" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Tenant -> String
forall a. Show a => a -> String
show Tenant
tn String -> ShowS
forall a. Semigroup a => a -> a -> a
<> "/" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> NameSpace -> String
forall a. Show a => a -> String
show NameSpace
ns String -> ShowS
forall a. Semigroup a => a -> a -> a
<> "/" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> TopicName -> String
forall a. Show a => a -> String
show TopicName
n
data TopicType = Persistent | NonPersistent
instance Show TopicType where
show :: TopicType -> String
show Persistent = "persistent"
show NonPersistent = "non-persistent"
newtype Tenant = Tenant String
instance Show Tenant where
show :: Tenant -> String
show (Tenant t :: String
t) = String
t
newtype NameSpace = NameSpace String
instance Show NameSpace where
show :: NameSpace -> String
show (NameSpace t :: String
t) = String
t
newtype TopicName = TopicName String
instance Show TopicName where
show :: TopicName -> String
show (TopicName t :: String
t) = String
t
newtype MsgId = MsgId MessageIdData
data Message = Message MsgId CL.ByteString
newtype PulsarMessage = PulsarMessage CL.ByteString deriving Int -> PulsarMessage -> ShowS
[PulsarMessage] -> ShowS
PulsarMessage -> String
(Int -> PulsarMessage -> ShowS)
-> (PulsarMessage -> String)
-> ([PulsarMessage] -> ShowS)
-> Show PulsarMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PulsarMessage] -> ShowS
$cshowList :: [PulsarMessage] -> ShowS
show :: PulsarMessage -> String
$cshow :: PulsarMessage -> String
showsPrec :: Int -> PulsarMessage -> ShowS
$cshowsPrec :: Int -> PulsarMessage -> ShowS
Show
instance IsString PulsarMessage where
fromString :: String -> PulsarMessage
fromString = ByteString -> PulsarMessage
PulsarMessage (ByteString -> PulsarMessage)
-> (String -> ByteString) -> String -> PulsarMessage
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
CL.pack
newtype SubscriptionName = SubscriptionName T.Text deriving Int -> SubscriptionName -> ShowS
[SubscriptionName] -> ShowS
SubscriptionName -> String
(Int -> SubscriptionName -> ShowS)
-> (SubscriptionName -> String)
-> ([SubscriptionName] -> ShowS)
-> Show SubscriptionName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SubscriptionName] -> ShowS
$cshowList :: [SubscriptionName] -> ShowS
show :: SubscriptionName -> String
$cshow :: SubscriptionName -> String
showsPrec :: Int -> SubscriptionName -> ShowS
$cshowsPrec :: Int -> SubscriptionName -> ShowS
Show
instance IsString SubscriptionName where
fromString :: String -> SubscriptionName
fromString = Text -> SubscriptionName
SubscriptionName (Text -> SubscriptionName)
-> (String -> Text) -> String -> SubscriptionName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack