Conduit v0.12.10 Conduit.Encoding behaviour View Source

Encodes and decodes a message body based on the content encoding given.

Custom content encodings can be specified in your configuration.

config :conduit, Conduit.Encoding, [{"custom", MyApp.CustomEncoding}]

Note that any new content encodings specified in this way will require a recompile of Conduit.

$ mix deps.clean conduit --build
$ mix deps.get

Any custom content encodings should implement the Conduit.ContentType behaviour. See Conduit.Encoding.GZip for an example.

Link to this section Summary

Functions

Decodes the message body with the specified content encoding

Encodes the message body with the specified content encoding

Link to this section Functions

Decodes the message body with the specified content encoding.

Examples

iex> import Conduit.Message
iex> body = <<31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 171, 174, 5, 0, 67, 191, 166, 163, 2, 0, 0, 0>>
iex> message =
iex>   %Conduit.Message{}
iex>   |> put_body(body)
iex>   |> Conduit.Encoding.decode("gzip", [])
iex> message.body
"{}"

Encodes the message body with the specified content encoding.

Examples

iex> import Conduit.Message
iex> message =
iex>   %Conduit.Message{}
iex>   |> put_body("{}")
iex>   |> Conduit.Encoding.encode("gzip", [])
iex> :zlib.gunzip(message.body)
"{}"

Link to this section Callbacks