View Source AvroEx (AvroEx v1.2.0)
AvroEx is a library for encoding and decoding data with Avro schemas. Supports parsing schemas, encoding data, and decoding data.
For encoding and decoding, the following type chart should be referenced:
Avro Types | Elixir Types |
---|---|
boolean | boolean |
integer | integer |
long | integer |
float | decimal |
double | decimal |
bytes | binary |
string | String.t, atom |
null | nil |
Record | map |
Enum | String.t, atom (corresponding to the enum's symbol list) |
Link to this section Summary
Functions
Given an encoded message and its accompanying schema, decodes the message.
Checks to see if the given data is encodable using the given schema. Great in unit tests.
Given a %Schema{} and some data, takes the data and encodes it according to the schema. Checks that the data is encodable before beginning encoding.
Given a JSON-formatted schema, parses the schema and returns a %AvroEx.Schema{}
struct representing the schema.
Errors if the JSON is invalid, or if a named record is referenced that doesn't exist.
Same as AvroEx.parse_schema/1
, but raises an exception on failure instead of
returning an error tuple.
Link to this section Types
Specs
encoded_avro() :: binary()
Link to this section Functions
Specs
decode(AvroEx.Schema.t(), encoded_avro()) :: {:ok, term()} | {:error, term()}
Given an encoded message and its accompanying schema, decodes the message.
Checks to see if the given data is encodable using the given schema. Great in unit tests.
Specs
encode(AvroEx.Schema.t(), term()) :: {:ok, encoded_avro()} | {:error, :unmatching_schema} | {:error, term(), term()}
Given a %Schema{} and some data, takes the data and encodes it according to the schema. Checks that the data is encodable before beginning encoding.
Specs
named_type( AvroEx.Schema.full_name(), AvroEx.Schema.t() | AvroEx.Schema.Context.t() ) :: nil | AvroEx.Schema.schema_types()
Specs
parse_schema(AvroEx.Schema.json_schema()) :: {:ok, AvroEx.Schema.t()} | {:error, :unnamed_record} | {:error, :invalid_json}
Given a JSON-formatted schema, parses the schema and returns a %AvroEx.Schema{}
struct representing the schema.
Errors if the JSON is invalid, or if a named record is referenced that doesn't exist.
Specs
parse_schema!(AvroEx.Schema.json_schema()) :: AvroEx.Schema.t() | no_return()
Same as AvroEx.parse_schema/1
, but raises an exception on failure instead of
returning an error tuple.