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 TypesElixir Types
booleanboolean
integerinteger
longinteger
floatdecimal
doubledecimal
bytesbinary
stringString.t, atom
nullnil
Recordmap
EnumString.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.

Link to this function

encodable?(schema, data)

View Source

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.

Link to this function

named_type(name, context)

View Source

Specs

Link to this function

parse_schema(json_schema)

View Source

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.

Link to this function

parse_schema!(json_schema)

View Source

Specs

Same as AvroEx.parse_schema/1, but raises an exception on failure instead of returning an error tuple.