|
8 | 8 | module Ouroboros.Consensus.Util.StreamingLedgerTables where
|
9 | 9 |
|
10 | 10 | import Cardano.Slotting.Slot
|
11 |
| -import Codec.CBOR.Decoding (Decoder, decodeBreakOr, decodeMapLenIndef) |
| 11 | +import Codec.CBOR.Decoding (Decoder, decodeBreakOr, decodeMapLenOrIndef) |
12 | 12 | import Codec.CBOR.Encoding (Encoding, encodeBreak, encodeMapLenIndef)
|
13 | 13 | import Codec.CBOR.Read
|
14 | 14 | import Codec.CBOR.Write
|
15 | 15 | import Control.Concurrent.Class.MonadMVar
|
16 |
| -import Control.Monad (unless) |
| 16 | +import Control.Monad (replicateM_, unless) |
17 | 17 | import Control.Monad.Class.MonadAsync
|
18 | 18 | import Control.Monad.Class.MonadST
|
19 | 19 | import Control.Monad.Class.MonadSTM
|
@@ -87,15 +87,17 @@ yieldCborMapS ::
|
87 | 87 | Stream (Of ByteString) m () ->
|
88 | 88 | Stream (Of (a, b)) m (Stream (Of ByteString) m ())
|
89 | 89 | yieldCborMapS decK decV = execStateT $ do
|
90 |
| - hoist lift $ decodeCbor decodeMapLenIndef |
91 |
| - go |
| 90 | + hoist lift (decodeCbor decodeMapLenOrIndef) >>= \case |
| 91 | + Nothing -> go |
| 92 | + Just n -> replicateM_ n yieldKV |
92 | 93 | where
|
| 94 | + yieldKV = do |
| 95 | + kv <- hoist lift $ decodeCbor $ (,) <$> decK <*> decV |
| 96 | + lift $ S.yield kv |
| 97 | + |
93 | 98 | go = do
|
94 | 99 | doBreak <- hoist lift $ decodeCbor decodeBreakOr
|
95 |
| - unless doBreak $ do |
96 |
| - kv <- hoist lift $ decodeCbor $ (,) <$> decK <*> decV |
97 |
| - lift $ S.yield kv |
98 |
| - go |
| 100 | + unless doBreak $ yieldKV *> go |
99 | 101 |
|
100 | 102 | maybeToEither :: a -> Maybe b -> Either a b
|
101 | 103 | maybeToEither _ (Just b) = Right b
|
|
0 commit comments