Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huwcampbell/avro
Avro library for Elm
https://github.com/huwcampbell/avro
avro
Last synced: about 1 month ago
JSON representation
Avro library for Elm
- Host: GitHub
- URL: https://github.com/huwcampbell/avro
- Owner: HuwCampbell
- License: mit
- Created: 2024-01-22T02:39:50.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-09-10T12:04:02.000Z (2 months ago)
- Last Synced: 2024-09-10T13:40:49.059Z (2 months ago)
- Topics: avro
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/HuwCampbell/avro/latest/
- Size: 215 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Avro
[Apache Avro™ ](https://avro.apache.org/) support for Elm.
Apache Avro™ is a leading serialisation format for record data,
with a powerful type system, and great support for schema evolution.This library offers comprehensive support for reading and writing
Avro binary data to Elm types, through the definition of
[`Codecs`](https://package.elm-lang.org/packages/HuwCampbell/avro/1.0.1/Avro-Codec/#Codec).
These describe Avro Schemas, as well as encoders and decoders for
Avro values.As a simple example, below we define an Elm record with a type alias,
and then build a binary Codec for it.```elm
import Avro
import Avro.Codec exposing (..)
import Avro.Schema exposing (Schema, SchemaMismatch)
import Bytes.Decode exposing (Decoder)
import Bytes.Encode exposing (Encoder){-| Declaration of the data type we want to encode and decode.
-}
type alias Person =
{ name : String, age : Maybe Int }{-| Build the Codec for it.
This type includes a Schema, encoder, and decoder.
-}
personCodec : Codec Person
personCodec =
success Person
|> requiring "name" string .name
|> optional "age" int .age
|> record { baseName = "person", nameSpace = ["demo"] }{-| A byte encoder for a person.
-}
encodePerson : Person -> Encoder
encodePerson =
Avro.makeEncoder personCodec{-| Build a decoder for data written using a schema.
-}
decodePerson : Schema -> Result SchemaMismatch (Decoder Person)
decodePerson writerSchema =
Avro.makeDecoder personCodec writerSchema
```