Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data IDecodeIO a
- = Partial (Maybe ByteString → IO (IDecodeIO a))
- | Done !ByteString !ByteOffset a
- | Fail !ByteString !ByteOffset DeserialiseFailure
- deserialiseIncrementalIO ∷ (∀ s. Decoder s a) → IO (IDecodeIO a)
- fromIDecode ∷ IDecode RealWorld a → IDecodeIO a
- data Decoder m = Decoder {
- decodeNext ∷ ∀ a. (∀ s. Decoder s a) → m a
- initDecoderIO ∷ IO ByteString → IO (Decoder IO)
- decodeAsFlatTerm ∷ ByteString → Either DeserialiseFailure FlatTerm
- data ReadIncrementalErr
- readIncremental ∷ ∀ m a. IOLike m ⇒ SomeHasFS m → Bool → Decoder (PrimState m) a → FsPath → m (Either ReadIncrementalErr (a, Maybe CRC))
- 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
- decodeList ∷ Decoder s a → Decoder s [a]
- decodeMaybe ∷ Decoder s a → Decoder s (Maybe a)
- decodeSeq ∷ Decoder s a → Decoder s (StrictSeq a)
- decodeWithOrigin ∷ Decoder s a → Decoder s (WithOrigin a)
- encodeList ∷ (a → Encoding) → [a] → Encoding
- encodeMaybe ∷ (a → Encoding) → Maybe a → Encoding
- encodeSeq ∷ (a → Encoding) → StrictSeq a → Encoding
- encodeWithOrigin ∷ (a → Encoding) → WithOrigin a → Encoding
Incremental parsing in I/O
Partial (Maybe ByteString → IO (IDecodeIO a)) | |
Done !ByteString !ByteOffset a | |
Fail !ByteString !ByteOffset DeserialiseFailure |
Higher-level incremental interface
Decoder | |
|
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
data ReadIncrementalErr Source #
ReadFailed DeserialiseFailure | Could not deserialise the data |
TrailingBytes ByteString | Deserialisation was successful, but there was additional data |
Instances
Show ReadIncrementalErr Source # | |
Defined in Ouroboros.Consensus.Util.CBOR showsPrec ∷ Int → ReadIncrementalErr → ShowS # show ∷ ReadIncrementalErr → String # showList ∷ [ReadIncrementalErr] → ShowS # | |
Eq ReadIncrementalErr Source # | |
Defined in Ouroboros.Consensus.Util.CBOR |
readIncremental ∷ ∀ m a. IOLike m ⇒ SomeHasFS m → Bool → Decoder (PrimState m) a → FsPath → m (Either ReadIncrementalErr (a, Maybe CRC)) Source #
Read a file incrementally, optionally calculating the CRC checksum.
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 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
decodeList ∷ Decoder s a → Decoder s [a] Source #
decodeWithOrigin ∷ Decoder s a → Decoder s (WithOrigin a) Source #
encodeList ∷ (a → Encoding) → [a] → Encoding Source #
encodeWithOrigin ∷ (a → Encoding) → WithOrigin a → Encoding Source #