Skir (skir_elixir v1.0.0)

Copy Markdown View Source

Official Elixir runtime for generated Skir schemas.

Non-bang functions return {:ok, value} or {:error, %Skir.Error{}}. Bang functions raise Skir.Error. encode/3 produces framed Skir binary; encode_json/3 produces a UTF-8 JSON string (format: :dense by default, or 2-space indented format: :readable for debugging). to_json/3 returns an Elixir JSON term.

Unknown fields are discarded by default on decode. With unknown_fields: :preserve, unrecognized dense-JSON and binary values are preserved across round-trips in the same wire format and silently dropped when serializing to another format or to readable JSON. No atom is created from untrusted input. SkirRPC lives under Skir.RPC.

Summary

Functions

Decodes framed Skir binary or JSON bytes, validating the input and enforcing resource limits.

Like decode/3, but returns the value directly and raises Skir.Error on failure.

Decodes a UTF-8 JSON string, accepting dense and readable JSON and enforcing resource limits.

Like decode_json/3, but returns the value directly and raises Skir.Error on failure.

Returns the zero/default value for a primitive, composite, or generated record type.

Encodes a value as Skir binary with the skir prefix. This is not Erlang external-term format.

Like encode/3, but returns the value directly and raises Skir.Error on failure.

Encodes a value as a UTF-8 JSON string. Dense JSON is the default; use format: :readable for 2-space indented JSON.

Like encode_json/3, but returns the value directly and raises Skir.Error on failure.

Decodes a dense or readable JSON term. Unknown fields are discarded by default.

Like from_json/3, but returns the value directly and raises Skir.Error on failure.

Builds a map index for a keyed array. When duplicate keys exist, the last item wins.

Converts a native value to a dense JSON term, or readable JSON term with format: :readable.

Like to_json/3, but returns the value directly and raises Skir.Error on failure.

Types

float_value()

@type float_value() :: float() | integer() | :nan | :infinity | :neg_infinity

primitive()

@type primitive() ::
  :bool
  | :int32
  | :int64
  | :hash64
  | :float32
  | :float64
  | :timestamp
  | :string
  | :bytes

result(value)

@type result(value) :: {:ok, value} | {:error, Skir.Error.t()}

type()

@type type() ::
  primitive()
  | {:optional, type()}
  | {:array, type()}
  | {:array, type(), String.t()}
  | {:record, module()}

Functions

decode(type, bytes, opts \\ [])

@spec decode(type(), binary(), keyword()) :: result(term())

Decodes framed Skir binary or JSON bytes, validating the input and enforcing resource limits.

decode!(type, value, opts \\ [])

@spec decode!(type(), term(), keyword()) :: term()

Like decode/3, but returns the value directly and raises Skir.Error on failure.

decode_json(type, code, opts \\ [])

@spec decode_json(type(), binary(), keyword()) :: result(term())

Decodes a UTF-8 JSON string, accepting dense and readable JSON and enforcing resource limits.

decode_json!(type, value, opts \\ [])

@spec decode_json!(type(), term(), keyword()) :: term()

Like decode_json/3, but returns the value directly and raises Skir.Error on failure.

default(type)

@spec default(type()) :: term()

Returns the zero/default value for a primitive, composite, or generated record type.

encode(type, value, opts \\ [])

@spec encode(type(), term(), keyword()) :: result(binary())

Encodes a value as Skir binary with the skir prefix. This is not Erlang external-term format.

encode!(type, value, opts \\ [])

@spec encode!(type(), term(), keyword()) :: term()

Like encode/3, but returns the value directly and raises Skir.Error on failure.

encode_json(type, value, opts \\ [])

@spec encode_json(type(), term(), keyword()) :: result(binary())

Encodes a value as a UTF-8 JSON string. Dense JSON is the default; use format: :readable for 2-space indented JSON.

encode_json!(type, value, opts \\ [])

@spec encode_json!(type(), term(), keyword()) :: term()

Like encode_json/3, but returns the value directly and raises Skir.Error on failure.

from_json(type, value, opts \\ [])

@spec from_json(type(), term(), keyword()) :: result(term())

Decodes a dense or readable JSON term. Unknown fields are discarded by default.

from_json!(type, value, opts \\ [])

@spec from_json!(type(), term(), keyword()) :: term()

Like from_json/3, but returns the value directly and raises Skir.Error on failure.

index_by(values, path)

@spec index_by(list(), [atom() | {atom(), module()}]) :: map()

Builds a map index for a keyed array. When duplicate keys exist, the last item wins.

to_json(type, value, opts \\ [])

@spec to_json(type(), term(), keyword()) :: result(term())

Converts a native value to a dense JSON term, or readable JSON term with format: :readable.

to_json!(type, value, opts \\ [])

@spec to_json!(type(), term(), keyword()) :: term()

Like to_json/3, but returns the value directly and raises Skir.Error on failure.