diff options
author | James Crayne <jim.crayne@gmail.com> | 2016-04-28 17:25:01 -0400 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2016-04-28 17:25:01 -0400 |
commit | 4ec9cc5e6e1c71184c0537fb2fbd4387f27b3ac2 (patch) | |
tree | 67b144c4d839cd617cb4a9233b78802ad315f63c /KikiD/Message.hs | |
parent | e7db95eb413a311dbeddd8bf2474f3710b9258c0 (diff) |
remove kikid, moved to separate repo
Diffstat (limited to 'KikiD/Message.hs')
-rw-r--r-- | KikiD/Message.hs | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/KikiD/Message.hs b/KikiD/Message.hs deleted file mode 100644 index efefdc6..0000000 --- a/KikiD/Message.hs +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | {-# LANGUAGE DoAndIfThenElse #-} | ||
2 | module KikiD.Message where | ||
3 | |||
4 | import Data.Serialize as Cereal | ||
5 | import qualified Data.ByteString.Char8 as B | ||
6 | import Data.Monoid | ||
7 | import Text.Read | ||
8 | import Data.Char (ord,chr) | ||
9 | import Control.Monad | ||
10 | import Data.Bytes.Serial as R | ||
11 | import Data.Bytes.Put as Put | ||
12 | import Data.Bytes.Get as Get | ||
13 | import Codec.LineReady | ||
14 | import Control.Monad.Loops | ||
15 | import Data.Word | ||
16 | |||
17 | data KikiDMessage = TODO deriving (Show,Read) | ||
18 | |||
19 | instance Serialize KikiDMessage where | ||
20 | put m = mapM_ (Cereal.putWord8 . fromIntegral . ord) "TO\nO" | ||
21 | -- putByteString . B.pack $ show m ++ "\n" | ||
22 | get = do | ||
23 | t <- Cereal.getWord8 | ||
24 | o <- Cereal.getWord8 | ||
25 | d <- Cereal.getWord8 | ||
26 | o <- Cereal.getWord8 | ||
27 | let s = map (chr . fromIntegral) [t,o,d,o] | ||
28 | if "TO\nO" == s | ||
29 | then return TODO | ||
30 | else fail ("Could not decode message: " ++ show s) | ||
31 | |||
32 | instance Serial KikiDMessage where | ||
33 | serialize m = Put.putByteString . toLineReady . Cereal.encode $ m | ||
34 | deserialize = do | ||
35 | xs <- unfoldM $ do | ||
36 | flag <- Get.isEmpty | ||
37 | if flag then return Nothing else do | ||
38 | c <- fmap (chr . fromIntegral) Get.getWord8 | ||
39 | if (c == '\n') then return Nothing else return (Just c) | ||
40 | case (Cereal.decode . fromLineReady $ B.pack xs) of | ||
41 | Left str -> fail str | ||
42 | Right x -> return x | ||