module Net.Mptcp.Flags (
  MptcpFlag
)
where

data MptcpFlag = MptcpFlagFin | MptcpFlagSyn | MptcpFlagRst | MptcpFlagPsh
    | MptcpFlagAck | MptcpFlagUrg | MptcpFlagEcn | MptcpFlagCwr | MptcpFlagNonce
        deriving (MptcpFlag -> MptcpFlag -> Bool
(MptcpFlag -> MptcpFlag -> Bool)
-> (MptcpFlag -> MptcpFlag -> Bool) -> Eq MptcpFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MptcpFlag -> MptcpFlag -> Bool
$c/= :: MptcpFlag -> MptcpFlag -> Bool
== :: MptcpFlag -> MptcpFlag -> Bool
$c== :: MptcpFlag -> MptcpFlag -> Bool
Eq, Int -> MptcpFlag -> ShowS
[MptcpFlag] -> ShowS
MptcpFlag -> String
(Int -> MptcpFlag -> ShowS)
-> (MptcpFlag -> String)
-> ([MptcpFlag] -> ShowS)
-> Show MptcpFlag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MptcpFlag] -> ShowS
$cshowList :: [MptcpFlag] -> ShowS
show :: MptcpFlag -> String
$cshow :: MptcpFlag -> String
showsPrec :: Int -> MptcpFlag -> ShowS
$cshowsPrec :: Int -> MptcpFlag -> ShowS
Show, MptcpFlag
MptcpFlag -> MptcpFlag -> Bounded MptcpFlag
forall a. a -> a -> Bounded a
maxBound :: MptcpFlag
$cmaxBound :: MptcpFlag
minBound :: MptcpFlag
$cminBound :: MptcpFlag
Bounded)

-- values are power of 2 of the flag
instance Enum MptcpFlag where
    toEnum :: Int -> MptcpFlag
toEnum Int
0 = MptcpFlag
MptcpFlagFin
    toEnum Int
1 = MptcpFlag
MptcpFlagSyn
    toEnum Int
2 = MptcpFlag
MptcpFlagRst
    toEnum Int
3 = MptcpFlag
MptcpFlagPsh
    toEnum Int
4 = MptcpFlag
MptcpFlagAck
    toEnum Int
5 = MptcpFlag
MptcpFlagUrg
    toEnum Int
6 = MptcpFlag
MptcpFlagEcn
    toEnum Int
7 = MptcpFlag
MptcpFlagCwr
    toEnum Int
8 = MptcpFlag
MptcpFlagNonce
    toEnum Int
n = String -> MptcpFlag
forall a. HasCallStack => String -> a
error (String -> MptcpFlag) -> String -> MptcpFlag
forall a b. (a -> b) -> a -> b
$ String
"toEnum n: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n

    fromEnum :: MptcpFlag -> Int
fromEnum MptcpFlag
MptcpFlagFin = Int
0
    fromEnum MptcpFlag
MptcpFlagSyn = Int
1
    fromEnum MptcpFlag
MptcpFlagRst = Int
2
    fromEnum MptcpFlag
MptcpFlagPsh = Int
3
    fromEnum MptcpFlag
MptcpFlagAck = Int
4
    fromEnum MptcpFlag
MptcpFlagUrg = Int
5
    fromEnum MptcpFlag
MptcpFlagEcn = Int
6
    fromEnum MptcpFlag
MptcpFlagCwr = Int
7
    fromEnum MptcpFlag
MptcpFlagNonce = Int
8
    -- fromEnum _ = error $ "fromEnum not implemented"

    enumFrom :: MptcpFlag -> [MptcpFlag]
enumFrom     MptcpFlag
x   = MptcpFlag -> MptcpFlag -> [MptcpFlag]
forall a. Enum a => a -> a -> [a]
enumFromTo     MptcpFlag
x MptcpFlag
forall a. Bounded a => a
maxBound
    enumFromThen :: MptcpFlag -> MptcpFlag -> [MptcpFlag]
enumFromThen MptcpFlag
x MptcpFlag
y = MptcpFlag -> MptcpFlag -> MptcpFlag -> [MptcpFlag]
forall a. Enum a => a -> a -> a -> [a]
enumFromThenTo MptcpFlag
x MptcpFlag
y MptcpFlag
bound
      where
        bound :: MptcpFlag
bound | MptcpFlag -> Int
forall a. Enum a => a -> Int
fromEnum MptcpFlag
y Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= MptcpFlag -> Int
forall a. Enum a => a -> Int
fromEnum MptcpFlag
x = MptcpFlag
forall a. Bounded a => a
maxBound
              | Bool
otherwise                = MptcpFlag
forall a. Bounded a => a
minBound