-- |
-- Module      : Relay.Session
-- Description : Session identifiers, sequence numbers, and wire frames.
module Relay.Session
  ( SessionId (..),
    Nat,
    Frame (..),
  )
where

import Data.UUID.Types (UUID)

-- | One per sending actor instance.
newtype SessionId = SessionId UUID
  deriving (Int -> SessionId -> ShowS
[SessionId] -> ShowS
SessionId -> String
(Int -> SessionId -> ShowS)
-> (SessionId -> String)
-> ([SessionId] -> ShowS)
-> Show SessionId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionId -> ShowS
showsPrec :: Int -> SessionId -> ShowS
$cshow :: SessionId -> String
show :: SessionId -> String
$cshowList :: [SessionId] -> ShowS
showList :: [SessionId] -> ShowS
Show, SessionId -> SessionId -> Bool
(SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> Bool) -> Eq SessionId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionId -> SessionId -> Bool
== :: SessionId -> SessionId -> Bool
$c/= :: SessionId -> SessionId -> Bool
/= :: SessionId -> SessionId -> Bool
Eq, Eq SessionId
Eq SessionId =>
(SessionId -> SessionId -> Ordering)
-> (SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> Bool)
-> (SessionId -> SessionId -> SessionId)
-> (SessionId -> SessionId -> SessionId)
-> Ord SessionId
SessionId -> SessionId -> Bool
SessionId -> SessionId -> Ordering
SessionId -> SessionId -> SessionId
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
$ccompare :: SessionId -> SessionId -> Ordering
compare :: SessionId -> SessionId -> Ordering
$c< :: SessionId -> SessionId -> Bool
< :: SessionId -> SessionId -> Bool
$c<= :: SessionId -> SessionId -> Bool
<= :: SessionId -> SessionId -> Bool
$c> :: SessionId -> SessionId -> Bool
> :: SessionId -> SessionId -> Bool
$c>= :: SessionId -> SessionId -> Bool
>= :: SessionId -> SessionId -> Bool
$cmax :: SessionId -> SessionId -> SessionId
max :: SessionId -> SessionId -> SessionId
$cmin :: SessionId -> SessionId -> SessionId
min :: SessionId -> SessionId -> SessionId
Ord)

-- | Sequence number type.
type Nat = Word

-- | A sequenced frame on the wire.
data Frame a = Frame
  { forall a. Frame a -> SessionId
frameSession :: SessionId,
    forall a. Frame a -> Nat
frameSeq :: Nat,
    forall a. Frame a -> a
framePayload :: a
  }
  deriving (Int -> Frame a -> ShowS
[Frame a] -> ShowS
Frame a -> String
(Int -> Frame a -> ShowS)
-> (Frame a -> String) -> ([Frame a] -> ShowS) -> Show (Frame a)
forall a. Show a => Int -> Frame a -> ShowS
forall a. Show a => [Frame a] -> ShowS
forall a. Show a => Frame a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Frame a -> ShowS
showsPrec :: Int -> Frame a -> ShowS
$cshow :: forall a. Show a => Frame a -> String
show :: Frame a -> String
$cshowList :: forall a. Show a => [Frame a] -> ShowS
showList :: [Frame a] -> ShowS
Show, Frame a -> Frame a -> Bool
(Frame a -> Frame a -> Bool)
-> (Frame a -> Frame a -> Bool) -> Eq (Frame a)
forall a. Eq a => Frame a -> Frame a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Frame a -> Frame a -> Bool
== :: Frame a -> Frame a -> Bool
$c/= :: forall a. Eq a => Frame a -> Frame a -> Bool
/= :: Frame a -> Frame a -> Bool
Eq)