hydra-node
Safe HaskellSafe-Inferred
LanguageGHC2021

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

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

Instances details
Show ApiEncoding Source # 
Instance details

Defined in Hydra.API.WireFormat

Eq ApiEncoding Source # 
Instance details

Defined in Hydra.API.WireFormat

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).