Gleam Codec

A library for encoding and decoding Gleam data structures to Erlang and Elixir via codecs.

Example

import codec

type Person{
	Person(
		name: String
	)
}

let c = codec.record1(
    "Person",
    Person,
    codec.record_field(
        "name",
        fn(p: Person) { p.name },
        codec.string()
    ),
)

let sam = Person("Sam")

codec.encode(c, sam)

Returns an Elixir map like

%{ "__type__" => "Person", "name" => "Sam" }

Installation

If available in Hex this package can be installed by adding gleam_codec to your rebar.config dependencies:

{deps, [
    gleam_codec
]}.