Snex.Serde.Encoder protocol (Snex v0.4.1)

Copy Markdown View Source

Protocol for custom encoding of Elixir terms to a desired representation on the Python side used by Snex.Serde.

If no implementation is defined, structs will be encoded "as-is".

See the Snex module documentation for more detail.

Summary

Types

t()

All the types that implement this protocol.

Functions

A function invoked to encode the given term to a desired representation on the Python side.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

encode(term)

@spec encode(term()) :: term()

A function invoked to encode the given term to a desired representation on the Python side.

The return value will be subject to recursive encoding. For example, if encode/1 returns another struct that implements Snex.Serde.Encoder, encode/1 will be called again on the result.

If the return value is the same struct type (e.g. encode(%X{}) -> %X{}), it will be encoded like a generic struct (i.e. as a dict with __struct__ key).