ouroboros-consensus- Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone



Incremental parsing in I/O

data IDecodeIO a Source #


Partial (Maybe ByteStringIO (IDecodeIO a)) 
Done !ByteString !ByteOffset a 
Fail !ByteString !ByteOffset DeserialiseFailure 

deserialiseIncrementalIO ∷ (∀ s. Decoder s a) → IO (IDecodeIO a) Source #

fromIDecode ∷ IDecode RealWorld a → IDecodeIO a Source #

Higher-level incremental interface

data Decoder m Source #




initDecoderIOIO ByteStringIO (Decoder IO) Source #

Construct incremental decoder given a way to get chunks

Resulting decoder is not thread safe.

Decode as FlatTerm

decodeAsFlatTermByteStringEither DeserialiseFailure FlatTerm Source #

HasFS interaction

data ReadIncrementalErr Source #


ReadFailed DeserialiseFailure

Could not deserialise the data

TrailingBytes ByteString

Deserialisation was successful, but there was additional data

readIncremental ∷ ∀ m a. IOLike m ⇒ SomeHasFS m → (∀ 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 ∷ ∀ 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

decodeList ∷ Decoder s a → Decoder s [a] Source #

decodeMaybe ∷ Decoder s a → Decoder s (Maybe a) Source #

decodeSeq ∷ Decoder s a → Decoder s (StrictSeq a) Source #

decodeWithOrigin ∷ Decoder s a → Decoder s (WithOrigin a) Source #

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

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

encodeSeq ∷ (a → Encoding) → StrictSeq a → Encoding Source #

encodeWithOrigin ∷ (a → Encoding) → WithOrigin a → Encoding Source #