Why does `erl_decode` return NULL when deserializing an Elixir map?

Viewed 55

I'm trying to move some data between an Elixir program and a C program. In Elixir, I have a struct of stuff I want to move over. I use :erlang.term_to_binary to convert it to a binary that I then mash over to C.

However, when I decode it, it just returns NULL?? And there's no error message or anything. A bunch of other elixir/erlang terms work fine; it specifically fails when I try to send over a map or a struct (which is a type of map).

I'm doing something like this in Elixir:

  msg = %Message{ title: "hello", body: "world" }
  binmsg = :erlang.term_to_binary(msg)
  send(state.port, {self(), {:command, binmsg}})

.. and in C (excluding the receiving of the message, which I have confirmed has arrived with the correct length, and even confirmed that the bytes are identical in C and elixir):

  uint8_t *buf = read_cmd();
  ETERM *map = erl_decode(buf);
  erl_print_term(map, stdout);
1 Answers
Related