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 Libraries Top

tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
pkrawat1
Presenting Aviacommerce, open source e-commerce platform in Elixir Aviacommerce is an open source e-commerce platform in Elixir. We at...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
Crowdhailer
I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention. Assuming you have...
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Sub Categories:

We're in Beta

About us Mission Statement