summaryrefslogtreecommitdiffhomepage
path: root/debug-me.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-14 09:38:04 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-14 09:38:04 -0400
commit2a271b27c65a286882332b6268e8946851c52f2a (patch)
treeb46233a6285834d89947193a36df72341519b818 /debug-me.hs
parentde7af3470e0b972ea9498f7ed07e6b38e8f15d03 (diff)
downloaddebug-me-2a271b27c65a286882332b6268e8946851c52f2a.tar.gz
add JSON serialization
Fairly straightforward, but did have to decide how to encode all the ByteStrings, since they are not necessarily utf-8. Used base64. This commit was sponsored by Henrik Riomar on Patreon.
Diffstat (limited to 'debug-me.hs')
-rw-r--r--debug-me.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/debug-me.hs b/debug-me.hs
index 44f3a38..86558bc 100644
--- a/debug-me.hs
+++ b/debug-me.hs
@@ -41,7 +41,7 @@ developer :: TChan (Activity Entered) -> TChan (Activity Seen) -> IO ()
developer ichan ochan = do
startact <- atomically $ readTChan ochan
case startact of
- StartActivity (Seen b) sig -> do
+ StartActivity (Seen (Val b)) sig -> do
B.hPut stdout b
hFlush stdout
_ -> return ()
@@ -69,8 +69,8 @@ sendTtyInput ichan devstate = go
atomically $ do
ds <- readTVar devstate
let entered = Entered
- { enteredData = b
- , echoData = sentSince ds
+ { enteredData = Val b
+ , echoData = Val (sentSince ds)
}
let act = Activity entered (lastSeen ds) dummySignature
writeTChan ichan act
@@ -91,7 +91,7 @@ sendTtyOutput ochan devstate = go
act <- readTChan ochan
ds <- readTVar devstate
case act of
- Activity (Seen b) hp sig
+ Activity (Seen (Val b)) hp sig
| hp == lastSeen ds -> do
let ss = sentSince ds
let ss' = if b `B.isPrefixOf` ss
@@ -109,7 +109,7 @@ sendTtyOutput ochan devstate = go
user :: B.ByteString -> Pty -> TChan (Activity Entered) -> TChan (Activity Seen) -> IO ()
user startmsg p ichan ochan = do
- let startact = StartActivity (Seen (startmsg <> "\r\n")) dummySignature
+ let startact = StartActivity (Seen (Val (startmsg <> "\r\n"))) dummySignature
atomically $ writeTChan ochan startact
backlog <- newTVarIO $ Backlog ((hash startact, startact) :| [])
_ <- sendPtyOutput p ochan backlog
@@ -128,7 +128,7 @@ sendPtyOutput p ochan backlog = go
b <- readPty p
atomically $ do
Backlog (bl@((prevhash, _) :| _)) <- readTVar backlog
- let seen = Seen b
+ let seen = Seen (Val b)
let act = Activity seen prevhash dummySignature
writeTChan ochan act
writeTVar backlog (Backlog ((hash act, act) :| toList bl))
@@ -154,7 +154,7 @@ sendPtyInput ichan p backlog = go
else do
return (Left ("illegal entry" :: String, newact, bl'))
case mb of
- Right b -> do
+ Right (Val b) -> do
writePty p b
go
Left _e -> do
@@ -189,7 +189,7 @@ truncateBacklog (Backlog bl) _ = Backlog bl
isLegal :: Activity Entered -> Backlog -> Bool
isLegal (Activity entered hp sig) (Backlog (lastseen@(lastseenhash, _lastseen) :| bl))
| lastseenhash == hp = True
- | B.null (echoData entered) = False -- optimisation
+ | B.null (val (echoData entered)) = False -- optimisation
| any (== hp) (map fst bl) =
let sincehp = reverse (lastseen : takeWhile (\(h, _) -> h /= hp) bl)
in echoData entered == mconcat (map (seenData . activityContent . snd) sincehp)