ouroboros-consensus-0.21.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Consensus.Util.CBOR

Synopsis

Incremental parsing in I/O

Higher-level incremental interface

data Decoder m Source #

Constructors

Decoder 

Fields

initDecoderIOIO ByteStringIO (Decoder IO) Source #

Construct incremental decoder given a way to get chunks

Resulting decoder is not thread safe.

Decode as FlatTerm

HasFS interaction

data ReadIncrementalErr Source #

Constructors

ReadFailed DeserialiseFailure

Could not deserialise the data

TrailingBytes ByteString

Deserialisation was successful, but there was additional data

readIncremental ∷ ∀ m a. IOLike m ⇒ SomeHasFS m → Decoder (PrimState m) 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 ∷ ∀ m h a r. (IOLike m, HasCallStack) ⇒ HasFS m h → (∀ s. Decoder s (ByteString → a)) → FsPath → (Stream (Of (Word64, (Word64, a))) m (Maybe (ReadIncrementalErr, Word64)) → m r) → m r Source #

Read multiple as 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 as, 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

decodeListDecoder s a → Decoder s [a] Source #

encodeList ∷ (a → Encoding) → [a] → Encoding Source #

encodeMaybe ∷ (a → Encoding) → Maybe a → Encoding Source #