immutant.codecs

Common codecs used when [de]serializing data structures.

The default registered codecs are:

  • :edn - encodes to/decodes from an EDN string
  • :json - encodes to/decodes from a JSON string. Requires cheshire as a dependency.
  • :none - performs no encoding

You can enable :fressian encoding by calling immutant.codecs.fressian/register-fressian-codec, or make custom codecs with make-codec.

codec-set

(codec-set)

Returns a set of names for available codecs.

decode

(decode data)(decode data encoding)

Decodes data using the codec for encoding.

encoding can be the name of the encoding or its content-type. encoding defaults to :edn.

encode

(encode data)(encode data encoding)

Encodes data using the codec for encoding.

encoding can be the name of the encoding or its content-type. encoding defaults to :edn.

make-codec

macro

(make-codec & settings)

Creates a codec instance for the given settings.

settings can be a map or kwargs, with these keys, most of which are required:

  • :name - The nickname for the codec. Can be a String or Keyword.
  • :content-type - The content type for the codec as a String.
  • :type - The type of data the codec encodes to/decodes from. Can be either :bytes or :string, and is optional, defaulting to :string.
  • :encode - A single-arity function that encodes its argument to the expected type.
  • :decode - A single-arity function that decodes its argument from the expected type to clojure data.

register-codec

(register-codec codec)

Registers a codec for use.

codec should be the result of make-codec.