summaryrefslogtreecommitdiff
path: root/fig-bus/src/Fig/Bus/Binary
diff options
context:
space:
mode:
Diffstat (limited to 'fig-bus/src/Fig/Bus/Binary')
-rw-r--r--fig-bus/src/Fig/Bus/Binary/Utils.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/fig-bus/src/Fig/Bus/Binary/Utils.hs b/fig-bus/src/Fig/Bus/Binary/Utils.hs
index a270fcc..8add010 100644
--- a/fig-bus/src/Fig/Bus/Binary/Utils.hs
+++ b/fig-bus/src/Fig/Bus/Binary/Utils.hs
@@ -15,13 +15,14 @@ intFromLEBytes [] = 0
intFromLEBytes (x:xs) = shiftL (intFromLEBytes xs) 8 .|. fromIntegral x
readLengthPrefixed :: Handle -> IO (Maybe ByteString)
-readLengthPrefixed h = do
- n <- hGet h 4
- case intFromLEBytes (BS.unpack n) of
- 0 -> pure $ Just ""
- len -> do
- x <- hGet h len
- pure $ Just x
+readLengthPrefixed h = hGet h 4 >>= \case
+ n | BS.null n -> pure Nothing
+ n ->
+ case intFromLEBytes (BS.unpack n) of
+ 0 -> pure $ Just ""
+ len -> do
+ x <- hGet h len
+ pure $ Just x
readEvent :: Handle -> IO (Maybe EventType)
readEvent h = do