pipes-cborg-0.1: Encode and decode cborg streams using the pipes and cborg libraries.

Pipes.CBOR

Contents

Description

pipes utilities for encoding and decoding values as byte streams in CBOR format using the cborg library.

Synopsis

Encoding

Arguments

 :: (Serialise x, Monad m) => x -> Producer' ByteString m ()

Renders x to a byte stream using its Serialise instance.

Arguments

 :: Monad m => Encoding -> Producer' ByteString m ()

Renders an Encoding to a byte stream.

Decoding

Arguments

 :: (MonadIO m, Serialise a) => Parser ByteString m (Either DeserialiseFailure (ByteOffset, a))

Parses x from a byte stream using its Serialise instance.

Also returns the number of bytes consumed in order to to decode the value.

Implementation note: No, ideally this function shouldn't run in IO. But unfortunately, the underlying deserialiseIncremental and its use of ST, which becomes both covariant and contravariant in Parser, make removing the IO tricky. The only IO this function performs is stToIO.

Arguments

 :: MonadIO m => (forall s. Decoder s x) -> Parser ByteString m (Either DeserialiseFailure (ByteOffset, x))

Parses @x“ from a byte stream using the given Decoder.

Also returns the number of bytes consumed in order to to decode the value.

Implementation note: No, ideally this function shouldn't run in IO. But unfortunately, the underlying deserialiseIncremental and its use of ST, which becomes both covariant and contravariant in Parser, make removing the IO tricky. The only IO this function performs is stToIO.