anchor.diff:         Fmt,
          Strict,
          Opts,
  +       Idx,
          AM) ->
       decode(Rest,
              Code,
  
positive.code: %% encountered. Failed-AVP should typically contain the first
  %% error encountered.
  
  %% decode/7
  
  decode(<<Code:32, V:1, M:1, P:1, _:5, Len:24, I:V/unit:32, Rest/binary>>,
         Name,
  
negative.code: set_failed(_, Opts) ->
      Opts.
  
  %% acc/9
  
  acc([AM | Acc], As, I, Name, AvpName, Arity, Strict, Mod, Opts) ->
      [AM | acc1(Acc, As, I, Name, AvpName, Arity, Strict, Mod, Opts)].
  
  %% acc1/9
  
  %% Faulty AVP, not grouped.
  acc1(Acc, {_RC, Avp} = E, _, _, _, _, _, _, _) ->
      [Avps, Failed | Rec] = Acc,
      [[Avp | Avps], [E | Failed] | Rec];
  
  %% Faulty component in grouped AVP.
  acc1(Acc, {RC, As, Avp}, _, _, _, _, _, _, _) ->
      [Avps, Failed | Rec] = Acc,
      [[As | Avps], [{RC, Avp} | Failed] | Rec];
  
  %% Grouped AVP ...
  acc1([Avps | Acc], [Avp|_] = As, I, Name, AvpName, Arity, Strict, Mod, Opts) ->
      [[As|Avps] | acc2(Acc, Avp, I, Name, AvpName, Arity, Strict, Mod, Opts)];
  
  %% ... or not.
  acc1([Avps | Acc], Avp, I, Name, AvpName, Arity, Strict, Mod, Opts) ->
      [[Avp|Avps] | acc2(Acc, Avp, I, Name, AvpName, Arity, Strict, Mod, Opts)].
  
  %% acc2/9
  
  %% No errors, but nowhere to pack.
  acc2(Acc, Avp, _, _, 'AVP', 0, _, _, _) ->
      [Failed | Rec] = Acc,
      [[{rc(Avp), Avp} | Failed] | Rec];
  
  %% No AVP of this name: try to pack as 'AVP'.
  acc2(Acc, Avp, I, Name, AvpName, 0, Strict, Mod, Opts) ->
      M = Avp#diameter_avp.is_mandatory,
      Arity = pack_arity(Name, AvpName, Opts, Mod, M),
      acc2(Acc, Avp, I, Name, 'AVP', Arity, Strict, Mod, Opts);
  
  %% Relaxed arities.
  acc2(Acc, Avp, _, _, AvpName, Arity, Strict, Mod, _)
    when Strict /= decode ->
      pack(Arity, AvpName, Avp, Mod, Acc);
  
  %% No maximum arity.
  acc2(Acc, Avp, _, _, AvpName, {_,'*'} = Arity, _, Mod, _) ->
      pack(Arity, AvpName, Avp, Mod, Acc);
  
  %% Or check.
  acc2(Acc, Avp, I, _, AvpName, Arity, _, Mod, _) ->
      Mx = max_arity(Arity),
      if Mx =< I ->
              [Failed | Rec] = Acc,
              [[{5009, Avp} | Failed] | Rec];
         true ->
  