-- | Information about messages
module Network.GRPC.Spec.MessageMeta (
    OutboundMeta(..)
  , InboundMeta(..)
  ) where

import Control.DeepSeq (NFData)
import Data.Default
import Data.Word
import GHC.Generics (Generic)

{-------------------------------------------------------------------------------
  Outbound messages
-------------------------------------------------------------------------------}

-- | Meta-information for outbound messages
data OutboundMeta = OutboundMeta {
      -- | Enable compression for this message
      --
      -- Even if enabled, compression will only be used if this results in a
      -- smaller message.
      OutboundMeta -> Bool
outboundEnableCompression :: Bool
    }
  deriving stock (Int -> OutboundMeta -> ShowS
[OutboundMeta] -> ShowS
OutboundMeta -> String
(Int -> OutboundMeta -> ShowS)
-> (OutboundMeta -> String)
-> ([OutboundMeta] -> ShowS)
-> Show OutboundMeta
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OutboundMeta -> ShowS
showsPrec :: Int -> OutboundMeta -> ShowS
$cshow :: OutboundMeta -> String
show :: OutboundMeta -> String
$cshowList :: [OutboundMeta] -> ShowS
showList :: [OutboundMeta] -> ShowS
Show, (forall x. OutboundMeta -> Rep OutboundMeta x)
-> (forall x. Rep OutboundMeta x -> OutboundMeta)
-> Generic OutboundMeta
forall x. Rep OutboundMeta x -> OutboundMeta
forall x. OutboundMeta -> Rep OutboundMeta x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OutboundMeta -> Rep OutboundMeta x
from :: forall x. OutboundMeta -> Rep OutboundMeta x
$cto :: forall x. Rep OutboundMeta x -> OutboundMeta
to :: forall x. Rep OutboundMeta x -> OutboundMeta
Generic)
  deriving anyclass (OutboundMeta -> ()
(OutboundMeta -> ()) -> NFData OutboundMeta
forall a. (a -> ()) -> NFData a
$crnf :: OutboundMeta -> ()
rnf :: OutboundMeta -> ()
NFData)

instance Default OutboundMeta where
  def :: OutboundMeta
def = OutboundMeta {
        outboundEnableCompression :: Bool
outboundEnableCompression = Bool
True
      }

{-------------------------------------------------------------------------------
  Inbound messages
-------------------------------------------------------------------------------}

-- | Meta-information about inbound messages
data InboundMeta = InboundMeta {
      -- | Size of the message in compressed form, /if/ it was compressed
      InboundMeta -> Maybe Word32
inboundCompressedSize :: Maybe Word32

      -- | Size of the message in uncompressed (but still serialized) form
    , InboundMeta -> Word32
inboundUncompressedSize :: Word32
    }
  deriving stock (Int -> InboundMeta -> ShowS
[InboundMeta] -> ShowS
InboundMeta -> String
(Int -> InboundMeta -> ShowS)
-> (InboundMeta -> String)
-> ([InboundMeta] -> ShowS)
-> Show InboundMeta
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InboundMeta -> ShowS
showsPrec :: Int -> InboundMeta -> ShowS
$cshow :: InboundMeta -> String
show :: InboundMeta -> String
$cshowList :: [InboundMeta] -> ShowS
showList :: [InboundMeta] -> ShowS
Show)