hauleth

hauleth

BARE encoding library

I do not know how many of you are familiar with BARE encoding format which was designed by Drew DeVault. It is super simple format for binary encoding of messages with structure known ahead-of-time (so it isn’t self-descriptive like CBOR). Now it got Erlang implementation (currently without compiler for building structure definition form text definitions).

Library usage is pretty simple (here with Elixir syntax):

spec = {:struct, [foo: :uint, bar: :string]}

encoded = :bare.encode(%{foo: 10, bar: "Hełło"}, spec)
:bare.decode(encoded, spec)
#=> {:ok, %{foo: 10, bar: "Hełło"}, <<>>}

Supported types are:

  • :uint/:int - variable width unsigned/signed integer (specs limit size of these integers to max 64-bit integers)
  • :u8/:u16/:u32/:u64 - fixed width unsigned integers
  • :i8/:i16/:i32/:i64 - fixed width signed integers
  • :bool - boolean values (aka true and false atoms)
  • :f32/:f64 - floating points of given size, currently encoding is limited to finite values, but encoding supports not-finite values which are returned as atoms
  • {:enum, [atom(), ...]} - which will encode known set of atoms as uint
  • :data and data<N> - which will encode arbitrary/fixed-length binaries
  • :string - UTF-8 encoded chartist or binary
  • :void - empty type that can encode only []
  • {:optional, type} - optional value of type
  • {:array, type} - list of type
  • {:array, type, size} - fixed length list of type
  • {:map, key_type, value_type} - map with keys of key_type and values of value_type
  • {:union, [type(), ...]} - tagged union of types which can encode values in form of {type(), data} where data is of type()
  • {:struct, keyword(type())} - structure with given keys that can encode maps with atom keys and values of specified types

Let me know what you think about it, either here or via mailing list.


In future I plan to implement web tokens with BARE and PASETO to make web tokens implementation that for me will be near ideal solution. I will ping you back when I will have something done.

Where Next?

Popular in Announcing Top

Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Thank...
New
zorbash
I created Kitto a framework for dashboards inspired by Dashing. The distributed characteristics of Elixir and the low memory footprint...
New
versilov
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 11220 107
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement