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)?