Skir (skir_elixir_client v0.2.2)

Copy Markdown View Source

Native Elixir serialization 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. to_json/3 returns a JSON term.

Unknown fields are discarded by default. With unknown_fields: :preserve, they round-trip in their original format; changing formats then returns an error. Enable preservation only for trusted data. 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 debugging.

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.

Build an index for a keyed array. Duplicate keys raise rather than silently overwriting.

Converts a native value to a dense JSON term, or readable JSON 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 debugging.

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()]) :: map()

Build an index for a keyed array. Duplicate keys raise rather than silently overwriting.

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 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.