hive

hive

Wanted: Tutorial on Pattern Matching to parse a binary protocol

Hi Folks,

Does anyone have a good pointer to a guide or tutorial on pattern matching to parse a binary protocol? I’m trying to monitor a serial protocol using Circuits.UART.

Here is an example of the protocol I’m trying to parse: Infinity Framing Protocol · nebulous/infinitude Wiki · GitHub

Thanks!

Most Liked

axelson

axelson

Scenic Core Team

Have you seen this blog post?

It’s my goto binary pattern matching blog post.

hauleth

hauleth

In this case parsing these messages is ultra easy:

def parse(<<destination_address,
            destination_bus,
            source_address,
            source_bus,
            length,
            pid,
            ext,
            function,
            data::binary-size(length),
            checksum::32>>
) do
  if valid_checksum?(<<destination_address,
            destination_bus,
            source_address,
            source_bus,
            length,
            pid,
            ext,
            function,
            data::binary>>) do
    {:ok, %{
      destination_address: destination_address,
      destination_bus: destination_bus,
      source_address: source_address,
      source_bus: source_bus,
      pid: pid,
      ext: ext,
      function: function,
      data: data
    }}
  else
    {:error, :invalid_checksum}
  end
end

Unfortunately, the spec didn’t specified which CRC16 they meant so I cannot provide that one.

tomkonidas

tomkonidas

Shows a nice way by using Mixin module. Highly recommend this talk

hive

hive

Thanks! That talk is very useful.

hive

hive

Nice. Thank you!

Where Next?

Popular in Chat/Questions Top

pietrofxq
I’ve bought the following books: Programming Elixir 1.6 Programming Phoenix 1.4 Programming Ecto Functional Web Development with Elixir...
New
wolfiton
Hi everyone, How can i retrieve the name from a structure like this? %{"id" =&gt; "1570", "name" =&gt; "Croque Monsieur"} My test loo...
New
zeroexcuses
Besides Basic types - The Elixir programming language are there any other well recommended “elixir by example” style resources / books ? ...
New
sadcad
I love the Phoenix and Elixir docs, but I always tend to learn faster when I watch a video of someone explaining things and then I implem...
New
svetarosemond
I’m planning on purchasing Elixir in action second edition, and I was wondering if anyone could tell me based off the first edition, does...
New
woohaaha
I’m coming from Ruby and Rails. I have read some Elixir and Phoenix books. They shed a lot of light about building applications in Elixir...
New
Nvim
Anybody know of a Pragmatic Studio 40% off coupon code for video course like Phoenix?
New
g5becks
Hello everyone. So I just got done reading all of the introduction to Elixir and working through the basics of the language. I am not new...
New
boddhisattva
Greetings everyone, At my current workplace we're evaluating different ways of building a microservices architecture for some parts rel...
New
SavagePixie
I was wondering if there are any beginner-friendly, exercise-based resources for learning Elixir out there. I’m looking for something lik...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
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
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

We're in Beta

About us Mission Statement