I am working on a web app that uses a WebSocket to log in users. I would like to minimize bandwidth usage by using binary messages. I came up with the following, and would like to know whether there is something better I could be doing:
-define(LOGIN, 1).
websocket_handle({binary, <<?LOGIN:8,LengthUser:8, Rest/bitstring>>}, Req, State) ->
LU2 = LengthUser*8,
<<Username:LU2/bitstring, Password/bitstring>> = Rest,
% Do the actual logging in...
I did a decent amount of research, and couldn't find a way to avoid using the Rest
piece in order to accommodate variable length bitstring patterns. The web app uses an ArrayBuffer
and a few DataView
s in order to construct the message.