@@ -19,8 +19,8 @@ module Ouroboros.Consensus.Util.StreamingLedgerTables
1919 ) where
2020
2121import Cardano.Slotting.Slot
22- import Codec.CBOR.Decoding (Decoder , decodeBreakOr , decodeMapLenOrIndef )
23- import Codec.CBOR.Encoding (Encoding , encodeBreak , encodeMapLenIndef )
22+ import Codec.CBOR.Decoding (Decoder , decodeBreakOr , decodeListLen , decodeMapLenOrIndef )
23+ import Codec.CBOR.Encoding (Encoding , encodeBreak , encodeListLen , encodeMapLenIndef )
2424import Codec.CBOR.Read
2525import Codec.CBOR.Write
2626import Control.Concurrent.Class.MonadMVar
@@ -101,7 +101,7 @@ yieldCborMapS ::
101101 Stream (Of ByteString ) m () ->
102102 Stream (Of (a , b )) (ExceptT DeserialiseFailure m ) (Stream (Of ByteString ) m () )
103103yieldCborMapS decK decV = execStateT $ do
104- hoist lift (decodeCbor decodeMapLenOrIndef) >>= \ case
104+ hoist lift (decodeCbor decodeListLen >> decodeCbor decodeMapLenOrIndef) >>= \ case
105105 Nothing -> go
106106 Just n -> replicateM_ n yieldKV
107107 where
@@ -232,7 +232,7 @@ sinkInMemoryS ::
232232 ExceptT DeserialiseFailure m ()
233233sinkInMemoryS _ writeChunkSize encK encV (SomeHasFS fs) fp s =
234234 ExceptT $ withFile fs (mkFsPath [fp]) (WriteMode MustBeNew ) $ \ hdl -> do
235- void $ hPutSome fs hdl $ toStrictByteString encodeMapLenIndef
235+ void $ hPutSome fs hdl $ toStrictByteString (encodeListLen 1 <> encodeMapLenIndef)
236236 e <- runExceptT $ go hdl writeChunkSize mempty s
237237 case e of
238238 Left err -> pure $ Left err
@@ -241,11 +241,11 @@ sinkInMemoryS _ writeChunkSize encK encV (SomeHasFS fs) fp s =
241241 pure $ Right ()
242242 where
243243 go tb 0 m s' = do
244- lift $ void $ hPutSome fs tb $ toStrictByteString $ mconcat [encK k <> encV v | (k, v) <- m]
244+ lift $ void $ hPutSome fs tb $ toStrictByteString $ mconcat [encK k <> encV v | (k, v) <- reverse m]
245245 go tb writeChunkSize mempty s'
246246 go tb n m s' = do
247247 mbs <- S. uncons s'
248248 case mbs of
249249 Nothing ->
250- lift $ void $ hPutSome fs tb $ toStrictByteString $ mconcat [encK k <> encV v | (k, v) <- m]
250+ lift $ void $ hPutSome fs tb $ toStrictByteString $ mconcat [encK k <> encV v | (k, v) <- reverse m]
251251 Just (item, s'') -> go tb (n - 1 ) (item : m) s''
0 commit comments