diff options
Diffstat (limited to 'dht/src/Data/Tox/Msg.hs')
-rw-r--r-- | dht/src/Data/Tox/Msg.hs | 26 |
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 #-} |
11 | module Data.Tox.Msg where | 13 | module Data.Tox.Msg where |
12 | 14 | ||
@@ -14,6 +16,7 @@ import Crypto.Error | |||
14 | import qualified Crypto.PubKey.Ed25519 as Ed25519 | 16 | import qualified Crypto.PubKey.Ed25519 as Ed25519 |
15 | import Data.ByteArray as BA | 17 | import Data.ByteArray as BA |
16 | import Data.ByteString as B | 18 | import Data.ByteString as B |
19 | import Data.Constraint | ||
17 | import Data.Dependent.Sum | 20 | import Data.Dependent.Sum |
18 | import Data.Functor.Contravariant | 21 | import Data.Functor.Contravariant |
19 | import Data.Functor.Identity | 22 | import Data.Functor.Identity |
@@ -31,6 +34,12 @@ import Crypto.Tox | |||
31 | import Data.PacketBuffer (compressSequenceNumbers, decompressSequenceNumbers) | 34 | import Data.PacketBuffer (compressSequenceNumbers, decompressSequenceNumbers) |
32 | import Network.Tox.NodeId | 35 | import Network.Tox.NodeId |
33 | 36 | ||
37 | #if MIN_VERSION_dependent_sum(0,6,0) | ||
38 | import Data.Constraint.Compose | ||
39 | import Data.Constraint.Extras | ||
40 | import Data.Constraint.Extras.TH | ||
41 | #endif | ||
42 | |||
34 | newtype Unknown = Unknown B.ByteString deriving (Eq,Show) | 43 | newtype Unknown = Unknown B.ByteString deriving (Eq,Show) |
35 | newtype Padded = Padded B.ByteString deriving (Eq,Show) | 44 | newtype 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 |
104 | instance GShow Pkt where gshowsPrec = showsPrec | 113 | instance GShow Pkt where gshowsPrec = showsPrec |
105 | instance ShowTag Pkt Identity where | ||
106 | showTaggedPrec (Pkt _) = showsPrec | ||
107 | |||
108 | instance GEq Pkt where geq (Pkt _) (Pkt _) = eqT | 114 | instance GEq Pkt where geq (Pkt _) (Pkt _) = eqT |
109 | instance EqTag Pkt Identity where eqTagged (Pkt _) (Pkt _) = (==) | ||
110 | 115 | ||
111 | someMsgVal :: KnownMsg n => Msg n a -> SomeMsg | 116 | someMsgVal :: KnownMsg n => Msg n a -> SomeMsg |
112 | someMsgVal m = msgid (proxy m) | 117 | someMsgVal 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 | ||
313 | instance Packet Invite where | 318 | instance Packet Invite where |
319 | |||
320 | #if MIN_VERSION_dependent_sum(0,6,0) | ||
321 | -- deriveArgDict ''Pkt | ||
322 | instance ArgDict (ComposeC Show Identity) Pkt where | ||
323 | type ConstraintsFor Pkt (ComposeC Show Identity) = () | ||
324 | argDict (Pkt _) = Dict | ||
325 | instance ArgDict (ComposeC Eq Identity) Pkt where | ||
326 | type ConstraintsFor Pkt (ComposeC Eq Identity) = () | ||
327 | argDict (Pkt _) = Dict | ||
328 | #else | ||
329 | instance EqTag Pkt Identity where eqTagged (Pkt _) (Pkt _) = (==) | ||
330 | instance ShowTag Pkt Identity where showTaggedPrec (Pkt _) = showsPrec | ||
331 | #endif | ||