anchor.diff:      Payload/binary>>}) ->
   
       {ok,ClientId, Rest} = parse_string(S#parse_state{buffer=Payload}), %% 3.1.3.1 does not place strict limitations on the ClientId
  -    {ok, WillDetails,Rest3} = parse_will_details_maybe(WillFlag,WillRetain,WillQoS,Rest),
  -    {Username,Rest4} = parse_string_maybe(UsernameFlag,Rest3),
  -    {Password,<<>>} =  parse_string_maybe(PasswordFlag,Rest4),
  +    {ok, WillDetails,Rest3} = maybe_parse_will_details(WillFlag,WillRetain,WillQoS,Rest),
  +    {Username,Rest4} = maybe_parse_string(UsernameFlag,Rest3),
  +    {Password,<<>>} =  maybe_parse_string(PasswordFlag,Rest4),
       #'CONNECT'{
           protocol_name = ProtocolName,
           protocol_version = ProtocolLevel,
  
positive.code:     {ok,Str,Rest};
  
  parse_string(_PartialString) ->
      {error,incomplete}
  .
  
  parse_string_maybe(Flag, Buffer) ->
      case Flag of
          0 ->
              {undefined,Buffer};
  
negative.code:     throw({error,malformed_packet}).
  
  %% If the Will Flag is set to 0, then the Will QoS MUST be set to 0 (0x00) [MQTT-3.1.2-13]
  maybe_parse_will_details(_WillFlag = 0,_WillRetain,_WillQoS = 0,Buffer) ->
      {ok,undefined,Buffer};
  
  maybe_parse_will_details(_WillFlag = 1,WillRetain,WillQoS,Buffer) when WillQoS =< 2 ->
      {ok,WillTopic, Rest1} =  parse_string(Buffer),
      {ok,WillMessage, Rest2} =  parse_string(Rest1),
      {
  