{-# LANGUAGE DeriveGeneric #-}
module Data.BEncode.Types
(
BInteger
, BString
, BList
, BDict
, BValue (..)
, isInteger
, isString
, isList
, isDict
) where
import Control.DeepSeq
import Data.ByteString
import GHC.Generics (Generic)
import Data.BEncode.BDict
type BInteger = Integer
type BString = ByteString
type BList = [BValue]
type BDict = BDictMap BValue
data BValue
= BInteger !BInteger
| BString !BString
| BList BList
| BDict BDict
deriving (Int -> BValue -> ShowS
[BValue] -> ShowS
BValue -> String
(Int -> BValue -> ShowS)
-> (BValue -> String) -> ([BValue] -> ShowS) -> Show BValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BValue] -> ShowS
$cshowList :: [BValue] -> ShowS
show :: BValue -> String
$cshow :: BValue -> String
showsPrec :: Int -> BValue -> ShowS
$cshowsPrec :: Int -> BValue -> ShowS
Show, ReadPrec [BValue]
ReadPrec BValue
Int -> ReadS BValue
ReadS [BValue]
(Int -> ReadS BValue)
-> ReadS [BValue]
-> ReadPrec BValue
-> ReadPrec [BValue]
-> Read BValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BValue]
$creadListPrec :: ReadPrec [BValue]
readPrec :: ReadPrec BValue
$creadPrec :: ReadPrec BValue
readList :: ReadS [BValue]
$creadList :: ReadS [BValue]
readsPrec :: Int -> ReadS BValue
$creadsPrec :: Int -> ReadS BValue
Read, BValue -> BValue -> Bool
(BValue -> BValue -> Bool)
-> (BValue -> BValue -> Bool) -> Eq BValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BValue -> BValue -> Bool
$c/= :: BValue -> BValue -> Bool
== :: BValue -> BValue -> Bool
$c== :: BValue -> BValue -> Bool
Eq, Eq BValue
Eq BValue
-> (BValue -> BValue -> Ordering)
-> (BValue -> BValue -> Bool)
-> (BValue -> BValue -> Bool)
-> (BValue -> BValue -> Bool)
-> (BValue -> BValue -> Bool)
-> (BValue -> BValue -> BValue)
-> (BValue -> BValue -> BValue)
-> Ord BValue
BValue -> BValue -> Bool
BValue -> BValue -> Ordering
BValue -> BValue -> BValue
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
min :: BValue -> BValue -> BValue
$cmin :: BValue -> BValue -> BValue
max :: BValue -> BValue -> BValue
$cmax :: BValue -> BValue -> BValue
>= :: BValue -> BValue -> Bool
$c>= :: BValue -> BValue -> Bool
> :: BValue -> BValue -> Bool
$c> :: BValue -> BValue -> Bool
<= :: BValue -> BValue -> Bool
$c<= :: BValue -> BValue -> Bool
< :: BValue -> BValue -> Bool
$c< :: BValue -> BValue -> Bool
compare :: BValue -> BValue -> Ordering
$ccompare :: BValue -> BValue -> Ordering
$cp1Ord :: Eq BValue
Ord, (forall x. BValue -> Rep BValue x)
-> (forall x. Rep BValue x -> BValue) -> Generic BValue
forall x. Rep BValue x -> BValue
forall x. BValue -> Rep BValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BValue x -> BValue
$cfrom :: forall x. BValue -> Rep BValue x
Generic)
instance NFData BValue where
rnf :: BValue -> ()
rnf (BInteger BInteger
i) = BInteger -> ()
forall a. NFData a => a -> ()
rnf BInteger
i
rnf (BString BString
s) = BString -> ()
forall a. NFData a => a -> ()
rnf BString
s
rnf (BList [BValue]
l) = [BValue] -> ()
forall a. NFData a => a -> ()
rnf [BValue]
l
rnf (BDict BDict
d) = BDict -> ()
forall a. NFData a => a -> ()
rnf BDict
d
isInteger :: BValue -> Bool
isInteger :: BValue -> Bool
isInteger (BInteger BInteger
_) = Bool
True
isInteger BValue
_ = Bool
False
{-# INLINE isInteger #-}
isString :: BValue -> Bool
isString :: BValue -> Bool
isString (BString BString
_) = Bool
True
isString BValue
_ = Bool
False
{-# INLINE isString #-}
isList :: BValue -> Bool
isList :: BValue -> Bool
isList (BList [BValue]
_) = Bool
True
isList BValue
_ = Bool
False
{-# INLINE isList #-}
isDict :: BValue -> Bool
isDict :: BValue -> Bool
isDict (BList [BValue]
_) = Bool
True
isDict BValue
_ = Bool
False
{-# INLINE isDict #-}