unison-share-api-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Util.Servant.CBOR

Description

Servant configuration for the CBOR media type

Adapted from https://hackage.haskell.org/package/servant-serialization-0.3/docs/Servant-API-ContentTypes-SerialiseCBOR.html via MIT license

Synopsis

Documentation

data CBOR Source #

Content-type for encoding and decoding objects as their CBOR representations

Instances

Instances details
Accept CBOR Source #

Mime-type for CBOR and additional ones using the word "hackage" and the name of the package "serialise".

Instance details

Defined in Unison.Util.Servant.CBOR

Serialise a => MimeRender CBOR a Source #
>>> mimeRender (Proxy :: Proxy CBOR) ("Hello" :: String)
"eHello"
Instance details

Defined in Unison.Util.Servant.CBOR

Methods

mimeRender :: Proxy CBOR -> a -> ByteString #

Serialise a => MimeUnrender CBOR a Source #
>>> let bsl = mimeRender (Proxy :: Proxy CBOR) (3.14 :: Float)
>>> mimeUnrender (Proxy :: Proxy CBOR) bsl :: Either String Float
Right 3.14
>>> mimeUnrender (Proxy :: Proxy CBOR) (bsl <> "trailing garbage") :: Either String Float
Right 3.14
>>> mimeUnrender (Proxy :: Proxy CBOR) ("preceding garbage" <> bsl) :: Either String Float
Left "Codec.Serialise.deserialiseOrFail: expected float at byte-offset 0"
Instance details

Defined in Unison.Util.Servant.CBOR

newtype CBORBytes t Source #

Wrapper for CBOR data that has already been serialized. In our case, we use this because we may load pre-serialized CBOR directly from the database, but it's also useful in allowing us to more quickly seek through a CBOR stream, since we only need to decode the CBOR when/if we actually need to use it, and can skip past it using a byte offset otherwise.

The t phantom type is the type of the data encoded in the bytestring.

Constructors

CBORBytes ByteString 

Instances

Instances details
Show (CBORBytes t) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

Eq (CBORBytes t) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

Methods

(==) :: CBORBytes t -> CBORBytes t -> Bool #

(/=) :: CBORBytes t -> CBORBytes t -> Bool #

Ord (CBORBytes t) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

Serialise (CBORBytes t) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

newtype CBORStream a Source #

Wrapper for a stream of CBOR data. Each chunk may not be a complete CBOR value, but the concatenation of all the chunks is a valid CBOR stream.

Constructors

CBORStream ByteString 

Instances

Instances details
MimeRender OctetStream (CBORStream a) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

MimeUnrender OctetStream (CBORStream a) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

Show (CBORStream a) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

Eq (CBORStream a) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

Methods

(==) :: CBORStream a -> CBORStream a -> Bool #

(/=) :: CBORStream a -> CBORStream a -> Bool #

Ord (CBORStream a) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

Serialise (CBORStream a) Source # 
Instance details

Defined in Unison.Util.Servant.CBOR

deserialiseOrFailCBORBytes :: Serialise t => CBORBytes t -> Either DeserialiseFailure t Source #

Deserialize a CBORBytes value into its tagged type, throwing an error if the deserialization fails.