module Simplex.Messaging.Version.Internal
( Version (..),
) where
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Word (Word16)
import Simplex.Messaging.Encoding
import Simplex.Messaging.Encoding.String
newtype Version v = Version Word16
deriving (Version v -> Version v -> Bool
(Version v -> Version v -> Bool)
-> (Version v -> Version v -> Bool) -> Eq (Version v)
forall v. Version v -> Version v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall v. Version v -> Version v -> Bool
== :: Version v -> Version v -> Bool
$c/= :: forall v. Version v -> Version v -> Bool
/= :: Version v -> Version v -> Bool
Eq, Eq (Version v)
Eq (Version v) =>
(Version v -> Version v -> Ordering)
-> (Version v -> Version v -> Bool)
-> (Version v -> Version v -> Bool)
-> (Version v -> Version v -> Bool)
-> (Version v -> Version v -> Bool)
-> (Version v -> Version v -> Version v)
-> (Version v -> Version v -> Version v)
-> Ord (Version v)
Version v -> Version v -> Bool
Version v -> Version v -> Ordering
Version v -> Version v -> Version v
forall v. Eq (Version v)
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
forall v. Version v -> Version v -> Bool
forall v. Version v -> Version v -> Ordering
forall v. Version v -> Version v -> Version v
$ccompare :: forall v. Version v -> Version v -> Ordering
compare :: Version v -> Version v -> Ordering
$c< :: forall v. Version v -> Version v -> Bool
< :: Version v -> Version v -> Bool
$c<= :: forall v. Version v -> Version v -> Bool
<= :: Version v -> Version v -> Bool
$c> :: forall v. Version v -> Version v -> Bool
> :: Version v -> Version v -> Bool
$c>= :: forall v. Version v -> Version v -> Bool
>= :: Version v -> Version v -> Bool
$cmax :: forall v. Version v -> Version v -> Version v
max :: Version v -> Version v -> Version v
$cmin :: forall v. Version v -> Version v -> Version v
min :: Version v -> Version v -> Version v
Ord, Int -> Version v -> ShowS
[Version v] -> ShowS
Version v -> String
(Int -> Version v -> ShowS)
-> (Version v -> String)
-> ([Version v] -> ShowS)
-> Show (Version v)
forall v. Int -> Version v -> ShowS
forall v. [Version v] -> ShowS
forall v. Version v -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall v. Int -> Version v -> ShowS
showsPrec :: Int -> Version v -> ShowS
$cshow :: forall v. Version v -> String
show :: Version v -> String
$cshowList :: forall v. [Version v] -> ShowS
showList :: [Version v] -> ShowS
Show)
instance Encoding (Version v) where
smpEncode :: Version v -> ByteString
smpEncode (Version Word16
v) = Word16 -> ByteString
forall a. Encoding a => a -> ByteString
smpEncode Word16
v
smpP :: Parser (Version v)
smpP = Word16 -> Version v
forall v. Word16 -> Version v
Version (Word16 -> Version v)
-> Parser ByteString Word16 -> Parser (Version v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Word16
forall a. Encoding a => Parser a
smpP
instance StrEncoding (Version v) where
strEncode :: Version v -> ByteString
strEncode (Version Word16
v) = Word16 -> ByteString
forall a. StrEncoding a => a -> ByteString
strEncode Word16
v
strP :: Parser (Version v)
strP = Word16 -> Version v
forall v. Word16 -> Version v
Version (Word16 -> Version v)
-> Parser ByteString Word16 -> Parser (Version v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Word16
forall a. StrEncoding a => Parser a
strP
instance ToJSON (Version v) where
toEncoding :: Version v -> Encoding
toEncoding (Version Word16
v) = Word16 -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding Word16
v
toJSON :: Version v -> Value
toJSON (Version Word16
v) = Word16 -> Value
forall a. ToJSON a => a -> Value
toJSON Word16
v
instance FromJSON (Version v) where
parseJSON :: Value -> Parser (Version v)
parseJSON Value
v = Word16 -> Version v
forall v. Word16 -> Version v
Version (Word16 -> Version v) -> Parser Word16 -> Parser (Version v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Word16
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v