avro_ex v0.1.0-beta.6 AvroEx

The main interface for the library. 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
nullnil
Recordmap
EnumString (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 %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

Link to this type encoded_avro()
encoded_avro() :: binary()

Link to this section Functions

Link to this function decode(schema, message)
decode(AvroEx.Schema.t(), encoded_avro()) ::
  {:ok, term()} |
  {:error, AvroEx.Decode.reason()}

Given an encoded message and its accompanying schema, decodes the message.

Link to this function encodable?(schema, data)

Checks to see if the given data is encodable using the given schema. Great in unit tests.

Link to this function encode(schema, data)
encode(AvroEx.Schema.t(), term()) ::
  {:ok, encoded_avro()} |
  {:error, :unmatching_schema} |
  {:error, AvroEx.Encode.reason(), 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 parse_schema(json_schema)
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 %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)
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.