| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Hydra.API.WireFormat
Description
Wire encodings of the client API: JSON (the default) or native CBOR.
This module is the single home for the encode/decode primitives shared by
the WebSocket server, the HTTP server and the clients; call sites resolve
the negotiated ApiEncoding once and stay dispatch-free afterwards.
Synopsis
- data ApiEncoding
- encodeWire :: (ToJSON a, ToCBOR a) => ApiEncoding -> a -> ByteString
- decodeWire :: (FromJSON a, FromCBOR a) => ApiEncoding -> ByteString -> Either String a
- describeWire :: ApiEncoding -> ByteString -> Text
Documentation
data ApiEncoding Source #
Which wire encoding a client negotiated: JSON (the default) or native
CBOR. WebSocket clients opt in via the ?encoding=cbor query parameter,
HTTP clients via Accept @Content-Type: applicationcbor@ headers.
Constructors
| JsonEncoding | |
| CborEncoding |
Instances
| Show ApiEncoding Source # | |
Defined in Hydra.API.WireFormat | |
| Eq ApiEncoding Source # | |
Defined in Hydra.API.WireFormat Methods (==) :: ApiEncoding -> ApiEncoding -> Bool Source # (/=) :: ApiEncoding -> ApiEncoding -> Bool Source # | |
encodeWire :: (ToJSON a, ToCBOR a) => ApiEncoding -> a -> ByteString Source #
Encode a value in the given wire encoding.
decodeWire :: (FromJSON a, FromCBOR a) => ApiEncoding -> ByteString -> Either String a Source #
Decode a value in the given wire encoding.
describeWire :: ApiEncoding -> ByteString -> Text Source #
Echo received bytes in a readable form: raw text for JSON, base16 for CBOR (which is not valid UTF-8).