anchor.diff:  -include_lib("diameter/include/diameter.hrl").
   -include("diameter_internal.hrl").
   
  --define(MASK(N,I), ((I) band (1 bsl (N)))).
   -define(PAD(Len), ((4 - (Len rem 4)) rem 4)).
  +-define(BIT(B), (if B -> 1; true -> 0 end)).
  +-define(FLAGS(R,P,E,T), ?BIT(R):1, ?BIT(P):1, ?BIT(E):1, ?BIT(T):1, 0:4).
  +-define(FLAG(B,D), (if is_boolean(B) -> B; true -> 0 /= (D) end)).
   
   -type u32() :: 0..16#FFFFFFFF.
   -type u24() :: 0..16#FFFFFF.
  
positive.code: msg_id(#diameter_header{application_id = A,
                          cmd_code = C,
                          is_request = R}) ->
      {A, C, if R -> 1; true -> 0 end};
  
  msg_id(<<_:32, Rbit:1, _:7, CmdCode:24, ApplId:32, _/binary>>) ->
      {ApplId, CmdCode, Rbit}.
  
negative.code: e(_, #diameter_packet{msg = [#diameter_header{} = Hdr | As]} = Pkt) ->
      try encode_avps(reorder(As)) of
          Avps ->
              Len = 20 + size(Avps),
  
              #diameter_header{version = Vsn,
                               is_request = R,
                               is_proxiable = P,
                               is_error = E,
                               is_retransmitted = T,
                               cmd_code = Code,
                               application_id = Aid,
                               hop_by_hop_id  = Hid,
                               end_to_end_id  = Eid}
                  = Hdr,
  
              Pkt#diameter_packet{header = Hdr,
                                  bin = <<Vsn:8, Len:24,
                                          ?FLAGS(R,P,E,T), Code:24,
                                          Aid:32,
                                          Hid:32,
                                          Eid:32,
  