0

Consider a client/server application in which the client and the server use a tcp connection to exchange messages. Messages can be of many types: text, video, picture, etc. Messages are transferred as Erlang terms.

e.g.

 client -->         {{username, "Romeo"}, {password, "secret"}}           --> server
 client <--                      {authresult, 'PASS'}                     <-- server
 client -->         {{toUser, "Juliet"}, {msg, {text, "hello!"}}}         --> server
 client --> {{toTopic, "ErlangCafe"}, {msg, {text, "i love gen_server}}}  --> server
 client --> {{toUser, "Francisco"}, {msg, {jpg, <<binary data>>}}}        --> server

Reasons why I'm thinking of erlang term for binary data format:

1) google protobuf and apache thrift complicate the code, and brings performance overhead to server side 2) json seems not very good for binary data 3) Erlang term() is simple and natural with erlang server side, and I think it brings less overhead than protobuf and thrift does

The server just encode the data by term_to_binary() before sending it, and decode received data by binary_to_term(). The client side uses a library to encode the data into a binary erlang term before sending it and decode received data.

My questions are:

1) Is it good design to use erlang term() as binary data format in this application scenario? 2) What libraries to use to encode/decode on mobile clients (Android and iOS)?

Romstar
  • 1,139
  • 3
  • 14
  • 21

1 Answers1

0

1,2. If it's only used between erlang applications it would be ok. But erlang's binary format isn't widely accepted and used. I would choose protobuffs or thrift.

Just for reference here's the binary format description http://erlang.org/doc/apps/erts/erl_ext_dist.html and here's an example of how you can manually encode python structure into erlang binary format (description in russian though).

Here's also some other options Erlang Universal Binary Format? Anyone using it?

Community
  • 1
  • 1
ten0s
  • 839
  • 8
  • 11