{-# LANGUAGE OverloadedStrings #-}
module Periodic.Types.ClientType
  ( ClientType (..)
  ) where

import           Data.Binary

data ClientType = TypeClient
    | TypeWorker
    deriving (ClientType -> ClientType -> Bool
(ClientType -> ClientType -> Bool)
-> (ClientType -> ClientType -> Bool) -> Eq ClientType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClientType -> ClientType -> Bool
$c/= :: ClientType -> ClientType -> Bool
== :: ClientType -> ClientType -> Bool
$c== :: ClientType -> ClientType -> Bool
Eq, Int -> ClientType -> ShowS
[ClientType] -> ShowS
ClientType -> String
(Int -> ClientType -> ShowS)
-> (ClientType -> String)
-> ([ClientType] -> ShowS)
-> Show ClientType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientType] -> ShowS
$cshowList :: [ClientType] -> ShowS
show :: ClientType -> String
$cshow :: ClientType -> String
showsPrec :: Int -> ClientType -> ShowS
$cshowsPrec :: Int -> ClientType -> ShowS
Show)

instance Binary ClientType where
  get :: Get ClientType
get = do
    Word8
tp <- Get Word8
getWord8
    case Word8
tp of
      1 -> ClientType -> Get ClientType
forall (f :: * -> *) a. Applicative f => a -> f a
pure ClientType
TypeClient
      2 -> ClientType -> Get ClientType
forall (f :: * -> *) a. Applicative f => a -> f a
pure ClientType
TypeWorker
      _ -> String -> Get ClientType
forall a. HasCallStack => String -> a
error (String -> Get ClientType) -> String -> Get ClientType
forall a b. (a -> b) -> a -> b
$ "Error ClientType " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
tp

  put :: ClientType -> Put
put TypeClient = Word8 -> Put
putWord8 1
  put TypeWorker = Word8 -> Put
putWord8 2