diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/DatagramServer/Mainline.hs | 2 | ||||
-rw-r--r-- | src/Network/DatagramServer/Tox.hs | 2 | ||||
-rw-r--r-- | src/Network/DatagramServer/Types.hs | 6 |
3 files changed, 10 insertions, 0 deletions
diff --git a/src/Network/DatagramServer/Mainline.hs b/src/Network/DatagramServer/Mainline.hs index c127c07b..87825ce0 100644 --- a/src/Network/DatagramServer/Mainline.hs +++ b/src/Network/DatagramServer/Mainline.hs | |||
@@ -358,3 +358,5 @@ instance (Typeable tid, BEncode tid) => BEncode (KError tid) where | |||
358 | {-# INLINE fromBEncode #-} | 358 | {-# INLINE fromBEncode #-} |
359 | #endif | 359 | #endif |
360 | 360 | ||
361 | instance Read (NodeId KMessageOf) where readsPrec d s = map (\(w,xs) -> (NodeId w, xs)) $ decodeHex s | ||
362 | |||
diff --git a/src/Network/DatagramServer/Tox.hs b/src/Network/DatagramServer/Tox.hs index 2c432d70..b323a4df 100644 --- a/src/Network/DatagramServer/Tox.hs +++ b/src/Network/DatagramServer/Tox.hs | |||
@@ -286,3 +286,5 @@ instance WireFormat ByteString Message where | |||
286 | 286 | ||
287 | decodeHeaders ctx bs = runGet getMessage bs >>= decipher ctx | 287 | decodeHeaders ctx bs = runGet getMessage bs >>= decipher ctx |
288 | encodeHeaders ctx msg = runPut $ putMessage $ encipher ctx msg | 288 | encodeHeaders ctx msg = runPut $ putMessage $ encipher ctx msg |
289 | |||
290 | instance Read (NodeId Message) where readsPrec d s = map (\(w,xs) -> (NodeId w, xs)) $ decodeHex s | ||
diff --git a/src/Network/DatagramServer/Types.hs b/src/Network/DatagramServer/Types.hs index ea38d46e..e2d56dc0 100644 --- a/src/Network/DatagramServer/Types.hs +++ b/src/Network/DatagramServer/Types.hs | |||
@@ -10,6 +10,7 @@ | |||
10 | {-# LANGUAGE MultiParamTypeClasses #-} | 10 | {-# LANGUAGE MultiParamTypeClasses #-} |
11 | {-# LANGUAGE RankNTypes #-} | 11 | {-# LANGUAGE RankNTypes #-} |
12 | {-# LANGUAGE ScopedTypeVariables #-} | 12 | {-# LANGUAGE ScopedTypeVariables #-} |
13 | {-# LANGUAGE TupleSections #-} | ||
13 | {-# LANGUAGE TypeFamilies #-} | 14 | {-# LANGUAGE TypeFamilies #-} |
14 | {-# LANGUAGE StandaloneDeriving #-} | 15 | {-# LANGUAGE StandaloneDeriving #-} |
15 | module Network.DatagramServer.Types | 16 | module Network.DatagramServer.Types |
@@ -336,6 +337,11 @@ class Envelope envelope => WireFormat raw envelope where | |||
336 | encodeHexDoc :: Serialize x => x -> Doc | 337 | encodeHexDoc :: Serialize x => x -> Doc |
337 | encodeHexDoc nid = PP.text $ Char8.unpack $ Base16.encode $ S.encode nid | 338 | encodeHexDoc nid = PP.text $ Char8.unpack $ Base16.encode $ S.encode nid |
338 | 339 | ||
340 | decodeHex :: Serialize x => String -> [(x,String)] | ||
341 | decodeHex s = either (const []) (pure . (, Char8.unpack ybs)) $ S.decode xbs | ||
342 | where | ||
343 | (xbs,ybs) = Base16.decode $ Char8.pack s | ||
344 | |||
339 | -- FIXME Orphan Serialize intance for large words | 345 | -- FIXME Orphan Serialize intance for large words |
340 | instance (Serialize a, Serialize b) => Serialize (LargeKey a b) where | 346 | instance (Serialize a, Serialize b) => Serialize (LargeKey a b) where |
341 | put (LargeKey lo hi) = put hi >> put lo | 347 | put (LargeKey lo hi) = put hi >> put lo |