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 Types | Elixir Types |
---|---|
boolean | boolean |
integer | integer |
long | integer |
float | decimal |
double | decimal |
bytes | binary |
string | String.t |
null | nil |
Record | map |
Enum | String (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 section Functions
decode(AvroEx.Schema.t(), encoded_avro()) :: {:ok, term()} | {:error, AvroEx.Decode.reason()}
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.
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.
named_type(AvroEx.Schema.full_name(), AvroEx.Schema.t() | AvroEx.Schema.Context.t()) :: nil | AvroEx.Schema.schema_types()
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.
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.