diff options
Diffstat (limited to 'fig-bus/src')
| -rw-r--r-- | fig-bus/src/Fig/Bus/Binary/Utils.hs | 15 |
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 |
