summaryrefslogtreecommitdiffhomepage
path: root/Types.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-21 19:45:09 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-21 19:45:09 -0400
commit378770cde6fb9fd85983c05eab9eeff2e34398c2 (patch)
tree761273cdf6cc507db3fb1f6d7a2658d1fd799214 /Types.hs
parenta5f677919c2db47149e545165c9cacbf2c6b07b4 (diff)
downloaddebug-me-378770cde6fb9fd85983c05eab9eeff2e34398c2.tar.gz
working toward getting developer mode connection to server working
Diffstat (limited to 'Types.hs')
-rw-r--r--Types.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/Types.hs b/Types.hs
index b28713d..76a30a2 100644
--- a/Types.hs
+++ b/Types.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE DeriveGeneric, FlexibleInstances #-}
+{-# LANGUAGE DeriveGeneric, FlexibleInstances, FlexibleContexts #-}
{- | Main types for debug-me
-
@@ -15,6 +15,9 @@ module Types (
import Val
import Memory
import Serialization
+import Network.WebSockets (WebSocketsData(..))
+import qualified Data.Binary
+import qualified Data.ByteString.Lazy as L
-- | Things that the developer sees.
data Seen = Seen
@@ -191,3 +194,16 @@ instance ToJSON ControlAction where
toEncoding = genericToEncoding sumOptions
instance FromJSON ControlAction where
parseJSON = genericParseJSON sumOptions
+
+instance WebSocketsData (Message Seen) where
+ fromLazyByteString = decodeBinaryMessage
+ toLazyByteString = Data.Binary.encode
+
+instance WebSocketsData (Message Entered) where
+ fromLazyByteString = decodeBinaryMessage
+ toLazyByteString = Data.Binary.encode
+
+decodeBinaryMessage :: Binary (Message a) => L.ByteString -> Message a
+decodeBinaryMessage b = case Data.Binary.decodeOrFail b of
+ Right (_, _, msg) -> msg
+ Left (_, _, err) -> error $ "Binary decode error: " ++ err