anchor.diff:  
   
   parse_record_buf(Bytes) ->
  -    parse_record_buf(Bytes, []).
  -
  -parse_record_buf(<<>>, Accu) ->
  +    parse_record_buf_ordered(Bytes, []).
  +
  +parse_record_buf_ordered(<<>>, Accu) ->
       lists:reverse(Accu);
  -parse_record_buf(Bytes, Accu) ->
  -    {Value, Rest} = parse_field(Bytes),
  -    parse_record_buf(Rest, [Value | Accu]).
  +parse_record_buf_ordered(Bytes, Accu) ->
  +    {Field, Rest} = parse_field(Bytes),
  +    {Code, _Value} = Field,
  +    % check if the fields appear in order
  +    case Accu of
  +        [{PrevCode, _}|_] when PrevCode > Code ->
  +            % the field is out of order
  +            parse_record_buf_unordered(Rest, [Field | Accu]);
  +        _ ->
  +            parse_record_buf_ordered(Rest, [Field | Accu])
  +    end.
  +
  +parse_record_buf_unordered(<<>>, Accu) ->
  +    Res = lists:reverse(Accu),
  +    % stable-sort the obtained fields by codes
  +    lists:keysort(1, Res);
  +parse_record_buf_unordered(Bytes, Accu) ->
  +    {Field, Rest} = parse_field(Bytes),
  +    parse_record_buf_unordered(Rest, [Field | Accu]).
   
   
   parse_variant(X) ->
  
positive.code:         L :: [ parsed_field() ] ) ->
      { Found ::[ piqirun_return_buffer() ], Rest :: [ parsed_field() ]}.
  
  % find record fields by code
  find_fields(Code, L) ->
      {RevRes, Rest} = find_fields_rev(Code, L),
      {lists:reverse(RevRes), Rest}.
  
  
  % find record fields by code and return the list of found fields in reverse
  % order
  find_fields_rev(Code, L) ->
      find_fields_rev(Code, L, [], []).
  
  
  find_fields_rev(_Code, [], Accu, Rest) ->
      {Accu, lists:reverse(Rest)};
  find_fields_rev(Code, [{Code, X} | T], Accu, Rest) ->
      find_fields_rev(Code, T, [X | Accu], Rest);
  find_fields_rev(Code, [H | T], Accu, Rest) ->
      find_fields_rev(Code, T, Accu, [H | Rest]).
  
  
  -spec throw_error/1 :: (any()) -> no_return().
  
negative.code: 
  
  parse_optional_field(Code, ParseValue, L) ->
      {Field, Rest} = find_field(Code, L),
      Res = 
          case Field of
              'undefined' -> 'undefined';
              X ->
                  % NOTE: handling field duplicates without failure
                  % XXX, TODO: produce a warning
                  ParseValue(X)
  