summaryrefslogtreecommitdiff
path: root/dht/src/Data/Tox/Msg.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Data/Tox/Msg.hs')
-rw-r--r--dht/src/Data/Tox/Msg.hs26
1 files changed, 22 insertions, 4 deletions
diff --git a/dht/src/Data/Tox/Msg.hs b/dht/src/Data/Tox/Msg.hs
index 8819faa7..4398586f 100644
--- a/dht/src/Data/Tox/Msg.hs
+++ b/dht/src/Data/Tox/Msg.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE DataKinds #-} 2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DefaultSignatures #-} 3{-# LANGUAGE DefaultSignatures #-}
3{-# LANGUAGE FlexibleInstances #-} 4{-# LANGUAGE FlexibleInstances #-}
@@ -7,6 +8,7 @@
7{-# LANGUAGE MultiParamTypeClasses #-} 8{-# LANGUAGE MultiParamTypeClasses #-}
8{-# LANGUAGE PolyKinds #-} 9{-# LANGUAGE PolyKinds #-}
9{-# LANGUAGE StandaloneDeriving #-} 10{-# LANGUAGE StandaloneDeriving #-}
11{-# LANGUAGE TemplateHaskell #-}
10{-# LANGUAGE TypeFamilies #-} 12{-# LANGUAGE TypeFamilies #-}
11module Data.Tox.Msg where 13module Data.Tox.Msg where
12 14
@@ -14,6 +16,7 @@ import Crypto.Error
14import qualified Crypto.PubKey.Ed25519 as Ed25519 16import qualified Crypto.PubKey.Ed25519 as Ed25519
15import Data.ByteArray as BA 17import Data.ByteArray as BA
16import Data.ByteString as B 18import Data.ByteString as B
19import Data.Constraint
17import Data.Dependent.Sum 20import Data.Dependent.Sum
18import Data.Functor.Contravariant 21import Data.Functor.Contravariant
19import Data.Functor.Identity 22import Data.Functor.Identity
@@ -31,6 +34,12 @@ import Crypto.Tox
31import Data.PacketBuffer (compressSequenceNumbers, decompressSequenceNumbers) 34import Data.PacketBuffer (compressSequenceNumbers, decompressSequenceNumbers)
32import Network.Tox.NodeId 35import Network.Tox.NodeId
33 36
37#if MIN_VERSION_dependent_sum(0,6,0)
38import Data.Constraint.Compose
39import Data.Constraint.Extras
40import Data.Constraint.Extras.TH
41#endif
42
34newtype Unknown = Unknown B.ByteString deriving (Eq,Show) 43newtype Unknown = Unknown B.ByteString deriving (Eq,Show)
35newtype Padded = Padded B.ByteString deriving (Eq,Show) 44newtype Padded = Padded B.ByteString deriving (Eq,Show)
36 45
@@ -102,11 +111,7 @@ msgID (Pkt mid :=> Identity _) = M mid
102 111
103-- TODO 112-- TODO
104instance GShow Pkt where gshowsPrec = showsPrec 113instance GShow Pkt where gshowsPrec = showsPrec
105instance ShowTag Pkt Identity where
106 showTaggedPrec (Pkt _) = showsPrec
107
108instance GEq Pkt where geq (Pkt _) (Pkt _) = eqT 114instance GEq Pkt where geq (Pkt _) (Pkt _) = eqT
109instance EqTag Pkt Identity where eqTagged (Pkt _) (Pkt _) = (==)
110 115
111someMsgVal :: KnownMsg n => Msg n a -> SomeMsg 116someMsgVal :: KnownMsg n => Msg n a -> SomeMsg
112someMsgVal m = msgid (proxy m) 117someMsgVal m = msgid (proxy m)
@@ -311,3 +316,16 @@ instance Serialize Invite where
311 ConfirmedInvite ns -> return () -- TODO: encode nodes. 316 ConfirmedInvite ns -> return () -- TODO: encode nodes.
312 317
313instance Packet Invite where 318instance Packet Invite where
319
320#if MIN_VERSION_dependent_sum(0,6,0)
321-- deriveArgDict ''Pkt
322instance ArgDict (ComposeC Show Identity) Pkt where
323 type ConstraintsFor Pkt (ComposeC Show Identity) = ()
324 argDict (Pkt _) = Dict
325instance ArgDict (ComposeC Eq Identity) Pkt where
326 type ConstraintsFor Pkt (ComposeC Eq Identity) = ()
327 argDict (Pkt _) = Dict
328#else
329instance EqTag Pkt Identity where eqTagged (Pkt _) (Pkt _) = (==)
330instance ShowTag Pkt Identity where showTaggedPrec (Pkt _) = showsPrec
331#endif