Hi !

I took a more basic method for encoding, without many classes or structs. I match on the runtime value types and generate a corresponding ipc binary form. All forms are stored in recursive lists. Then I flatten all of this and glue thoses binaries.

I will move on and try to communicate with the server and write a binary decoder. Then write an encoder for collections.

  def serialize(list) when is_list(list),
    do: serialize_list(list, @value_type_none)

  def serialize(n) when is_integer(n),
    do: [@value_type_integer, int64(n)]

  def serialize(str) when is_binary(str) do
    len = byte_size(str)
    [@value_type_string, int32(len), str]
  end

  def serialize_list(list, subtype) when is_list(list) do
    len = length(list)
    items =
      for item <- list do
        serialize(item)
      end
    [@value_type_list, subtype, int32(len) | items]
  end

  def encode(term) do
    term
    |> serialize()
    |> :lists.flatten
    |> join_binaries
  end

I don't know if I will ever rewrite genipc in elixir, I don't mind having a python script in my codebase and it works well. It lacks parsing of enums though.

Thanks everyone for your help !

If you are interested in Elixir, the code that generate modules is available here : https://github.com/niahoo/exmms2/blob/master/lib/exmms2/ipc/compiler.ex

Generated modules do not send messages or generate binaries. They are purely functional and just return message structures, like :

Exmms2.IPC.Message.Main.hello(24, "myClient")
=> %{object_id: 1, command_id: 32, cookie: -1, payload: …}

Such functions are as small as possible. They still validate values. This is the decompiled form of the generated function hello! :

'hello!'(_@1, _@2) ->
    'Elixir.Exmms2.IPC':'validate_value!'(_@1, int),
    'Elixir.Exmms2.IPC':'validate_value!'(_@2, string),
    #{'__struct__' => 'Elixir.Exmms2.IPC.Message',
      cookie => -1, object_id => 1, command_id => 32,
      payload => [_@1, _@2], is_signal => false,
      '__struct__' => 'Elixir.Exmms2.IPC.Message'}.

(hello returns errors and hello! throws)

Cheers,


Le 04/07/2017 à 20:14, Daniel Svensson a écrit :
On Tue, Jul 4, 2017 at 5:14 PM, niahoo osef <ludo...@laposte.net> wrote:
I learned that C enums increment values from the first name (which is
defined to 32 in some enums in ipc.xml but not for the methods).

I'm not confident enough to rewrite genipc.py in Elixir, so I will use it
with a custom code_generator.py that just outputs a new data structure with
actual object_id and command_id numbers.

Then, I will write an Elixir module that reads the data structure and
creates the appropriate modules with macros.
Here's yet another example, in Go this time:

https://github.com/dsvensson/go-xmmsclient

Code generation comes from genipc/*, with some ugliness in favor of
better typing in the generated code, and the generated code are
xmmsclient/auto_*.

The auto_* files have all the obj/cmd ids as numbers due to
generation, so that might be useful to check.



--
_______________________________________________
Xmms2-devel mailing list
Xmms2-devel@lists.xmms2.org
https://lists.xmms2.org/cgi-bin/mailman/listinfo/xmms2-devel

Reply via email to