rahultumpala

rahultumpala

Dsm - Declarative finite state machines and pipelines

Hello,

I’m excited to introduce dsm, a zero-dependency abstraction library that allows you to define Finite State Machines and pipelines in a declarative manner.

Why?

I was building a networking app that dealt with enveloped messages. Upon receiving a message the app has to unwrap the message, read the type of the message, decode the message and then process accordingly. There were about 15 different message types and I ended up writing 15 case statements. While the code looked good, I yearned for a better way to describe the transformations and the processing sequence. dsm was built for this.

How is this different from other FSM libraries?

All FSMs and associated FSM libraries expect an input event which tiggers a state transition.

I’ve observed that many libraries expect this event to be defined while defining the state machine. My issue with this was that I couldn’t define an event at compile time, instead I wanted to define functions that decide whether the input event is valid and a state transition can be triggered.

An example dsm definition to read and parse a .wav file would look like the following snippet

defmodule Example.Demo do
  import Example.WaveFormat
  import Example.Validations
  use Dsm

  dsm do
    [
      name: "wav-file-reader-state-machine",
      initial_state: :ready,
      all_states: [:ready]
    ]
  end

  dsm_state :ready do
    [
      transformations: [&read_file_to_bytes/1],
      msg_handler_pipeline: [
        {&valid_read_output?/1, &read_riff_chunk/1},
        {&valid_intermediate_output?/1, &read_fmt_subChunk/1},
        {&valid_intermediate_output?/1, &read_data_subChunk/1}
      ],
      error_handlers: [],
      telemetry: &__MODULE__.telemetry/2
    ]
  end

  def telemetry({state, m, f, a}, data) do
    IO.inspect({"Telemetry Data for state :#{state} -- #{m}.#{f}/#{a}", data})
  end
end

I would very much appreciate it if you could use dsm and provide any feedback you may have on this.

The components and structure are documented in detail in my Github and on Hexdocs.

Thanks!

Hex url: dsm | Hex

Github:

Most Liked

rahultumpala

rahultumpala

I appreciate the honesty. As it appears, I do seem to lack a concrete understanding of what FSMs are not. I will read through the material. I’m not a CS student, I’m trying to figure things out on my own, but it’s not an excuse. Based on our discussion, I feel “declarative pipelines” would be a better fit. About testing, I am yet to figure it out. Let me see what I can do to make it better.

Where Next?

Popular in Announcing Top

kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
kip
ex_cldr provides localisation and internationalisation support based upon the data from the Unicode CLDR project. Unicode released CLDR ...
407 13056 120
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 19010 194
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
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
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
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
dominicletz
Hi, I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New

Other popular topics Top

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
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
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
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42158 114
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
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
New

We're in Beta

About us Mission Statement