Dextrin.Schema.Compiled (Dextrin v0.3.2)

Copy Markdown View Source

One version of one schema, compiled from a %schema(N){...} entry of a .dxns document (Dextrin.Schema.Compiler.compile/2) -- enough to both validate a decoded value and convert it both directions between .dxnb's always-positional wire shape and a named field map.

fields is ordered, and that order is the canonical position <-> name mapping .dxnb's positional struct encoding needs: the order the fields are written in the schema's body. version is the schema's version, 1 when its entry has no header (DXNS.md §8).

Summary

Functions

Reads application_struct's fields (an arbitrary Elixir struct — not a Dextrin.Struct) out in this schema's own canonical field order — the same order .dxnb's positional wire encoding needs. A field this schema declares but application_struct doesn't have is nil, same as any other absent field; extra struct fields the schema doesn't know about are simply not included.

Types

t()

@type t() :: %Dextrin.Schema.Compiled{
  annotations: %{optional(String.t()) => term()},
  fields: [Dextrin.Schema.Field.t()],
  name: String.t(),
  version: pos_integer()
}

Functions

field_names(compiled)

@spec field_names(t()) :: [String.t()]

field_values(compiled, application_struct)

@spec field_values(t(), struct()) :: [{String.t(), term()}]

Reads application_struct's fields (an arbitrary Elixir struct — not a Dextrin.Struct) out in this schema's own canonical field order — the same order .dxnb's positional wire encoding needs. A field this schema declares but application_struct doesn't have is nil, same as any other absent field; extra struct fields the schema doesn't know about are simply not included.

What lets Dextrin.Text.Printer/Dextrin.Binary.Encoder serialize a struct registered via Dextrin.Registry.put_struct_module/3 directly — without a caller needing to hand-build a Dextrin.Struct themselves first, closing the loop Dextrin.Schema.Reader.read/5 already closes on the way in.