View Source Avrora.Schema.Encoder (avrora v0.28.0)

Encodes and parses Avro schemas from various formats, like JSON and erlavro into Avrora.Schema.

Summary

Functions

Convert erlavro format to the Schema struct.

Parse Avro schema JSON and convert to the Schema struct.

An example of a reference lookup which returns empty JSON body

Convert struct to erlavro format and look it up in avro_schema_store.

Types

Link to this type

reference_lookup_fun()

View Source
@type reference_lookup_fun() :: (String.t() -> {:ok, String.t()} | {:error, term()})

Functions

Link to this function

from_erlavro(schema, attributes \\ [])

View Source
@spec from_erlavro(term(), keyword()) :: {:ok, Avrora.Schema.t()} | {:error, term()}

Convert erlavro format to the Schema struct.

Examples

iex> payload =
...>   {:avro_record_type, "Payment", "io.confluent", "", [],
...>        [
...>          {:avro_record_field, "id", "", {:avro_primitive_type, "string", []}, :undefined,
...>           :ascending, []},
...>          {:avro_record_field, "amount", "", {:avro_primitive_type, "double", []}, :undefined,
...>           :ascending, []}
...>        ], "io.confluent.Payment", []}
iex> {:ok, schema} = Avrora.Schema.Encoder.from_erlavro(payload)
iex> schema.id
nil
iex> schema.full_name
"io.confluent.Payment"
Link to this function

from_json(payload, reference_lookup_fun \\ &Avrora.Schema.Encoder.reference_lookup/1)

View Source
@spec from_json(String.t(), reference_lookup_fun()) ::
  {:ok, Avrora.Schema.t()} | {:error, term()}

Parse Avro schema JSON and convert to the Schema struct.

Examples

iex> json = ~s({"namespace":"io.confluent","type":"record","name":"Payment","fields":[{"name":"id","type":"string"},{"name":"amount","type":"double"}]})
iex> {:ok, schema} = Avrora.Schema.Encoder.from_json(json)
iex> schema.full_name
"io.confluent.Payment"
@spec reference_lookup(String.t()) :: {:ok, String.t()} | {:error, term()}

An example of a reference lookup which returns empty JSON body

@spec to_erlavro(Avrora.Schema.t()) :: {:ok, term()} | {:error, term()}

Convert struct to erlavro format and look it up in avro_schema_store.

Examples

iex> json = ~s({"namespace":"io.confluent","type":"record","name":"Payment","fields":[{"name":"id","type":"string"},{"name":"amount","type":"double"}]})
iex> {:ok, schema} = Avrora.Schema.Encoder.from_json(json)
iex> {:ok, {type, _, _, _, _, _, full_name, _}} = Avrora.Schema.Encoder.to_erlavro(schema)
iex> full_name
"io.confluent.Payment"
iex> type
:avro_record_type