anchor.diff:  -export([start_link/1]).
   -export([get_frame/1]).
   -export([get_readystate/1]).
  +-export([decode_len/1]).
   
   %% gen_server callbacks
   -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
  
positive.code: 
  encode_len(Len) when Len < 126 ->
      << Len:7 >>;
  encode_len(Len) when Len =< 65535 ->
      << 126:7, Len:16 >>;
  encode_len(Len) when Len =< 18446744073709551615 ->
      << 127:7, Len:64 >>.
  
  decode_len(<<127:7, Len:64, Rest/bytes>>) ->
  
negative.code: mask(<<>>, _) ->
      <<>>;
  mask(<<D:24>>, <<M:24, _:8>>) ->
      crypto:exor(<<D:24>>, <<M:24>>);
  mask(<<D:16>>, <<M:16, _:16>>) ->
      crypto:exor(<<D:16>>, <<M:16>>);
  mask(<<D>>, <<M, _:24>>) ->
      crypto:exor(<<D:8>>, <<M:8>>);
  mask(<<D:32, Rest/bits >>, M) ->
      Data = crypto:exor(<<D:32>>, M),
      MaskedRest = mask(Rest, M),
      << Data:32/bits, MaskedRest/bits >>.
  
  unmask(0, Data) ->
      Data;
  unmask(1, << Mask:32, Data/bits >> ) ->
      mask(Data, <<Mask:32>>).
  
  op_to_atom(?OP_CONT) -> cont;
  op_to_atom(?OP_TEXT) -> text;
  op_to_atom(?OP_BINARY) -> binary;
  op_to_atom(?OP_PING) -> ping;
  op_to_atom(?OP_PONG) -> pong;
  op_to_atom(?OP_CLOSE) -> close.
  
  contains_full_frame(Data) when byte_size(Data) < 2 ->
       false;
  contains_full_frame(<< _:9, Data/bits >>) ->
      case decode_len(Data) of
  	error -> 
  	    false;
  	{Len, Rest} -> 
  	    byte_size(Rest) >= Len
      end.
    
  recv_data(Sock, Buf) ->
      {Stat, B} = gen_tcp:recv(Sock, 0),
      case Stat of
           ok ->
              NewBuf = << Buf/binary, B/binary >>, 
  	    case contains_full_frame(NewBuf) of
  		true ->
  		    unframe(NewBuf);
  		_ ->
  		    recv_data(Sock, NewBuf)
  	    end; 
  	error -> error
      end.
  
  unframe(<< F:1, _:3, Op:4, M:1, Data/bits >>) ->
      {Len, Buf} = decode_len(Data),
      <<Payload:Len/bytes,RestBuf/bytes>> = Buf,
      {op_to_atom(Op),unmask(M,Payload),F,RestBuf}.
  
  frame(Op, Data) ->
      F = 1,
  