shrub/pkg/hs/urbit-eventlog-lmdb/lib/Urbit/EventLog/Event.hs
2020-11-25 11:33:36 -05:00

22 lines
547 B
Haskell

module Urbit.EventLog.Event
( buildLogEvent
, parseLogEvent
)
where
import ClassyPrelude
import Data.Serialize
import Urbit.Noun
buildLogEvent :: Mug -> Noun -> ByteString
buildLogEvent mug noun = (runPut $ putWord32le mug) ++ (jamBS noun)
parseLogEvent :: MonadIO m => ByteString -> m (Mug, Noun)
parseLogEvent bs = do
let (prefix, suffix) = splitAt 4 bs
let mug = case runGet getWord32le prefix of
Left _ -> error "Impossible misread of word32 in parseLogEvent"
Right x -> x
n <- cueBSExn suffix
pure (mug, n)