anchor.diff:  -compile([export_all, {no_auto_import, [error/2]}]).
   -include_lib("eunit/include/eunit.hrl").
   
  -%%%%%%%%%%%%%
  -%%% The socket.io server-side protocol as processed by https://github.com/3rd-Eden/Socket.IO-node/blob/master/lib/parser.js
  -%%%%%%%%%%%%%
  -
  -%% Framing is only given when no other suitable mode exists. In this case,
  -%% XHR-multipart will already frame these.
  -%% It is not defined whether we should 
  +%% The source code was taken and modified from https://github.com/yrashk/socket.io-erlang/blob/master/src/socketio_data_v1.erl
  +
   -define(FRAME, 16#fffd).
  --define(BINFRAME, <<65533>>).
  --define(RESERVED_EVENTS, [<<"message">>, <<"connect">>, <<"disconnect">>,
  -                          <<"open">>, <<"close">>, <<"error">>, <<"retry">>,
  -                          <<"reconnect">>]).
  -disconnect("") -> <<"0">>;
  -disconnect(Endpoint) -> [<<"0::">>,Endpoint].
  -
  -heartbeat() -> <<"2">>.
  +
  +disconnect(<<>>) ->
  +    <<"0">>;
  +disconnect(Endpoint) ->
  +    <<"0::", Endpoint/binary>>.
  +
  +heartbeat() ->
  +    <<"2">>.
   
   message(Id, EndPoint, Msg) when is_integer(Id) ->
  -    [<<"3:">>, integer_to_list(Id), $:, EndPoint, $:, Msg];
  -message(Id, EndPoint, Msg) when is_list(Id) ->
  -    [<<"3:">>, Id, $:, EndPoint, $:, Msg].
  +    IdBin = binary:list_to_bin(integer_to_list(Id)),
  +    <<"3:", IdBin/binary, ":", EndPoint/binary, ":", Msg/binary>>;
  +message(Id, EndPoint, Msg) when is_binary(Id) ->
  +    <<"3:", Id/binary, ":", EndPoint/binary, ":", Msg/binary>>.
   
   json(Id, EndPoint, Msg) when is_integer(Id) ->
  -    [<<"4:">>, integer_to_list(Id), $:, EndPoint, $:, jsx:term_to_json(Msg)];
  -json(Id, EndPoint, Msg) when is_list(Id) ->
  -    [<<"4:">>, Id, $:, EndPoint, $:, jsx:term_to_json(Msg)].
  -
  -event(Id, EndPoint, Event, Msg) when is_integer(Id) ->
  -    case lists:member(iolist_to_binary(Event), ?RESERVED_EVENTS) of
  -        true -> erlang:error(badarg);
  -        false ->
  -            [<<"5:">>, integer_to_list(Id), $:, EndPoint, $:, Event,
  -                ?BINFRAME, jsx:term_to_json(Msg)]
  -    end;
  -event(Id, EndPoint, Event, Msg) when is_list(Id) ->
  -    case lists:member(iolist_to_binary(Event), ?RESERVED_EVENTS) of
  -        true -> erlang:error(badarg);
  -        false ->
  -            [<<"5:">>, Id, $:, EndPoint, $:, Event,
  -                ?BINFRAME, jsx:term_to_json(Msg)]
  -    end.
  -
  -ack(Id) -> [<<"6:::">>, integer_to_list(Id)].
  -
  -ack(Id, Data) ->
  -    [<<"6:::">>, integer_to_list(Id), $+, jsx:term_to_json(Data)].
  +    IdBin = binary:list_to_bin(integer_to_list(Id)),
  +    JsonBin = jsx:term_to_json(Msg),
  +    <<"4:", IdBin/binary, ":", EndPoint/binary, ":", JsonBin/binary>>;
  +json(Id, EndPoint, Msg) when is_binary(Id) ->
  +    JsonBin = jsx:term_to_json(Msg),
  +    <<"4:", Id/binary, ":", EndPoint/binary, ":", JsonBin/binary>>.
   
   error(EndPoint, Reason) ->
       [<<"7::">>, EndPoint, $:, Reason].
  -
   error(EndPoint, Reason, Advice) ->
       [<<"7::">>, EndPoint, $:, Reason, $+, Advice].
   
  
positive.code: id_test_() ->
      [
       ?_assertEqual({12, <<"rest">>}, id(<<"12:rest">>)),
       ?_assertEqual({[], <<"rest">>}, id(<<":rest">>))
      ].
  
  decode_frame_test_() ->
      [
       ?_assertEqual([{message, 1, [], <<"blabla">>}], decode(<<?FRAME/utf8, "12", ?FRAME/utf8, "3:1::blabla">>)),
       ?_assertEqual([{json, 1, [], [{<<"a">>, <<"b">>}]},
  		    {message, 1, [], <<"blabla">>}],
  		   decode(<<?FRAME/utf8, "14", ?FRAME/utf8, "4:1::{\"a\":\"b\"}",
  			    ?FRAME/utf8, "12", ?FRAME/utf8, "3:1::blabla">>))
      ].
  
negative.code:     end.
  
  id(X) -> id(X, "").
  id(<<$:, Rest/binary>>, "") ->
      {<<>>, Rest};
  id(<<$:, Rest/binary>>, Acc) ->
      L = lists:reverse(Acc),
      {list_to_integer(L), Rest};
  