ouroboros-consensus- Consensus layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010



Incremental parsing in I/O

Higher-level incremental interface

data Decoder m Source #




initDecoderIO :: IO ByteString -> IO ( Decoder IO ) Source #

Construct incremental decoder given a way to get chunks

Resulting decoder is not thread safe.

Decode as FlatTerm

HasFS interaction

readIncremental :: forall m a. IOLike m => SomeHasFS m -> ( forall s. Decoder s a) -> FsPath -> m ( Either ReadIncrementalErr a) Source #

Read a file incrementally

NOTE: The MonadThrow constraint is only needed for bracket . This function does not actually throw anything.

NOTE: This uses a chunk size of roughly 32k. If we use this function to read small things this might not be ideal.

NOTE: This currently expects the file to contain precisely one value; see also withStreamIncrementalOffsets .

withStreamIncrementalOffsets :: forall m h a r. ( IOLike m, HasCallStack ) => HasFS m h -> ( forall s. Decoder s ( ByteString -> a)) -> FsPath -> ( Stream ( Of ( Word64 , ( Word64 , a))) m ( Maybe ( ReadIncrementalErr , Word64 )) -> m r) -> m r Source #

Read multiple a s incrementally from a file in a streaming way.

Continuation-passing style to ensure proper closure of the file.

Reads the offset ( Word64 ) of the start of each a , the size ( Word64 ) of each a , and each a itself. When deserialising fails, it passes all already deserialised a s, the error, and the offset after which the failure occurred.

NOTE: f we introduce user-facing streaming API also, the fact that we are using streaming here should not dictate that we should stick with it later; rather, we should revisit this code at that point.

Encoding/decoding containers