HuwCampbell/avro/1.0.0

NOTE: the latest version is 1.0.1

Avro

This module contains top level functions for converting Avro data to and from typed Elm values.

It is designed to be used with the Avro.Codec module.

One should construct a Codec, then, use the functions below to read and write Avro encoded binary data.

Parsing and writing Avro data

makeDecoder : Codec a -> Schema -> Result SchemaMismatch (Decoder a)

Create a binary decoder for avro data given a Codec and the writer's Schema.

Fields in Avro data types are not tagged, and records can only be interpreted knowing the exact Schema with which they were written.

Therefore, building a binary decoder not requires a Codec for the type of interest, but also the writer of the data's Schema.

makeEncoder : Codec a -> a -> Encoder

Make a binary encoder for data using an Avro Codec

Working with named types

It is common when building Avro schemas traditionally to write small schemas for parts of a larger record or set of messages. To do this, one uses named types to create references so that schema definitions can be simplified and reused.

In this library, this can be quite simply done for Codecs by using the namedType function from the Codec module.

To read and write data which is separated in this manner, one should first construct an Environment for all named types used by the reader and writer. Then, use that environment when constructing a decoder.

type alias Environment =
{ readerEnvironment : List Schema
, writerEnvironment : List Schema
}

Schemas which can be referred to by name in either the readers and writers.

makeDecoderInEnvironment : Environment -> Codec a -> Schema -> Result SchemaMismatch (Decoder a)

Create a binary decoder for avro data given a Codec and the writer's Schema.

This function will generate a decoder after considering the Named types in the defined set of schemas.

Json

JSON decoder for an Avro Schema

JSON encoder for an Avro Schema

JSON decoder for an Avro Value

valueEncoder : Schema -> Value -> Value

JSON encoder for an Avro Value