joetjen.net
EN DE
← All libraries
Elixir

dextrin

The reference implementation of DXN (Data eXchange Notation) for Elixir: .dxn text, .dxnb binary, .dxns schema.

Intention

JSON is human-writable but loses precision; Protobuf is compact and typed but needs a compiler step and no human reads it. DXN’s premise is that a text document and a binary document should be the same value space — 31 types, precise enough for money and exact ratios, with structs and custom tags as first-class extension points. Schemas carry a version, so data written under an old one is still read and upgraded. A .dxn file people write can be edited by a program without losing a comment.

Example
Dextrin.decode(~s(%{x: 1, y: 2}))
#=> {:ok, %{%Dextrin.Keyword{name: "x"} => 1, %Dextrin.Keyword{name: "y"} => 2}}

# trusted input may become atoms
{:ok, value} = Dextrin.decode(~s(%{x: 1, y: 2}), trusted: true)
#=> {:ok, %{x: 1, y: 2}}

{:ok, bytes} = Dextrin.encode_binary(value)
Dextrin.decode_binary(bytes, trusted: true)
#=> {:ok, %{x: 1, y: 2}}
Install
{:dextrin, "~> 0.3.2"}
ElixirSerializationCBOR