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