diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-04-21 19:45:09 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-04-21 19:45:09 -0400 |
commit | 378770cde6fb9fd85983c05eab9eeff2e34398c2 (patch) | |
tree | 761273cdf6cc507db3fb1f6d7a2658d1fd799214 /Types.hs | |
parent | a5f677919c2db47149e545165c9cacbf2c6b07b4 (diff) | |
download | debug-me-378770cde6fb9fd85983c05eab9eeff2e34398c2.tar.gz |
working toward getting developer mode connection to server working
Diffstat (limited to 'Types.hs')
-rw-r--r-- | Types.hs | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -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 |