ArchAstro. Codec
(archastro v0.2.0)
Copy Markdown
Converts between ArchAstro structs and their JSON wire representations.
Generated resource and channel modules use descriptor values to validate and decode nested API payloads. Most applications use those generated modules rather than calling this low-level codec directly.
Summary
Types
@type descriptor() :: :void | :unknown | :string | :integer | :float | :boolean | :datetime | {:list, descriptor()} | {:map, descriptor()} | {:ref, module()} | {:enum, [String.t()]} | {:union, [descriptor()]} | {:union, [descriptor()], {String.t(), %{optional(String.t()) => module()}}} | {:nullable, descriptor()} | {:optional, descriptor()} | {:object, [{String.t(), descriptor()}]}
@type field_descriptor() :: {atom(), {String.t(), descriptor()}}
Functions
@spec decode(ArchAstro.JSON.t(), descriptor()) :: ArchAstro.JSON.t() | struct() | DateTime.t() | :ok
@spec encode( ArchAstro.JSON.t() | ArchAstro.Unset.t() | struct() | Date.t() | DateTime.t() ) :: ArchAstro.JSON.t()
@spec matches?(ArchAstro.JSON.t(), descriptor()) :: boolean()
@spec put_optional( ArchAstro.JSON.object(), String.t(), ArchAstro.JSON.t() | ArchAstro.Unset.t() | struct() ) :: ArchAstro.JSON.object()
@spec struct_from_map(module(), ArchAstro.JSON.object(), [field_descriptor()]) :: struct()
@spec struct_to_map( struct(), [field_descriptor()] ) :: ArchAstro.JSON.object()