summaryrefslogtreecommitdiff
path: root/KikiD/Message.hs
diff options
context:
space:
mode:
Diffstat (limited to 'KikiD/Message.hs')
-rw-r--r--KikiD/Message.hs42
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 #-}
2module KikiD.Message where
3
4import Data.Serialize as Cereal
5import qualified Data.ByteString.Char8 as B
6import Data.Monoid
7import Text.Read
8import Data.Char (ord,chr)
9import Control.Monad
10import Data.Bytes.Serial as R
11import Data.Bytes.Put as Put
12import Data.Bytes.Get as Get
13import Codec.LineReady
14import Control.Monad.Loops
15import Data.Word
16
17data KikiDMessage = TODO deriving (Show,Read)
18
19instance 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
32instance 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