anchor.diff:  
   
   
  -
   decode_varint(Bin) -> de_vi(Bin, 0, 0).
   
   de_vi(<<1:1, X:7, Rest/binary>>, N, Acc) -> de_vi(Rest, N+1, X bsl (N*7) + Acc);
  
positive.code:               NewSeq  = element(RNum, NewMsg),
                setelement(RNum, AccRecord, PrevSeq ++ NewSeq);
           (#field{rnum=RNum, type={msg,_FieldMsgName}}, AccRecord) ->
                PrevSubMsg = element(RNum, AccRecord),
                NewSubMsg  = element(RNum, NewMsg),
                MergedSubMsg = merge_msgs(PrevSubMsg, NewSubMsg, MsgDefs),
                setelement(RNum, AccRecord, MergedSubMsg);
           (#field{rnum=RNum}, AccRecord) ->
                case element(RNum, NewMsg) of
                    undefined -> AccRecord;
  
negative.code:                                        occurrence=repeated, opts=[packed]}]}]),
      ok.
  
  merging_second_required_integer_overrides_first_test() ->
      #m1{a=20} = merge_msgs(#m1{a=10}, #m1{a=20},
                             [{{msg,m1},[#field{name=a,rnum=#m1.a,type=uint32,
                                                occurrence=required,opts=[]}]}]).
  
  merging_second_optional_integer_overrides_undefined_test() ->
      #m1{a=22} = merge_msgs(#m1{a=undefined}, #m1{a=22},
                             [{{msg,m1},[#field{name=a,rnum=#m1.a,type=uint32,
                                                occurrence=optional,opts=[]}]}]).
  
  merging_undefined_does_not_overrides_defined_integer_test() ->
      #m1{a=25} = merge_msgs(#m1{a=25}, #m1{a=undefined},
                             [{{msg,m1},[#field{name=a,rnum=#m1.a,type=uint32,
                                                occurrence=optional,opts=[]}]}]).
  
  merging_sequences_test() ->
      #m1{a=[11,12, 21,22]} =
          merge_msgs(#m1{a=[11,12]}, #m1{a=[21,22]},
                     [{{msg,m1},[#field{name=a,rnum=#m1.a,type=uint32,
                                        occurrence=repeated,opts=[]}]}]).
  
  -record(m4, {x,y}).
  
  merging_messages_recursively_test() ->
      #m1{a=#m4{x = 210,
                y = [111, 112, 211, 212]}} =
          merge_msgs(#m1{a = #m4{x = 110,
                                 y = [111, 112]}},
                     #m1{a = #m4{x = 210,
                                 y = [211, 212]}},
                     [{{msg,m1}, [#field{name=a,fnum=1, rnum=#m1.a,
                                         type={msg,m4},
                                         occurrence=required, opts=[]}]},
                      {{msg,m4}, [#field{name=x, fnum=1, rnum=#m4.x, type=uint32,
                                         occurrence=optional, opts=[]},
                                  #field{name=y, fnum=w, rnum=#m4.y, type=uint32,
                                         occurrence=repeated, opts=[]}]}]).
  
  merging_optional_messages_recursively1_test() ->
      #m1{a=#m4{x = 110,
                y = [111, 112]}} =
          merge_msgs(#m1{a = #m4{x = 110,
                                 y = [111, 112]}},
                     #m1{a = undefined},
                     [{{msg,m1}, [#field{name=a,fnum=1, rnum=#m1.a,
                                         type={msg,m4},
                                         occurrence=optional, opts=[]}]},
                      {{msg,m4}, [#field{name=x, fnum=1, rnum=#m4.x, type=uint32,
                                         occurrence=optional, opts=[]},
                                  #field{name=y, fnum=w, rnum=#m4.y, type=uint32,
                                         occurrence=repeated, opts=[]}]}]).
  
  merging_optional_messages_recursively2_test() ->
      #m1{a=#m4{x = 210,
                y = [211, 212]}} =
          merge_msgs(#m1{a = undefined},
                     #m1{a = #m4{x = 210,
                                 y = [211, 212]}},
                     [{{msg,m1}, [#field{name=a,fnum=1, rnum=#m1.a,
                                         type={msg,m4},
                                         occurrence=optional, opts=[]}]},
                      {{msg,m4}, [#field{name=x, fnum=1, rnum=#m4.x, type=uint32,
                                         occurrence=optional, opts=[]},
                                  #field{name=y, fnum=w, rnum=#m4.y, type=uint32,
                                         occurrence=repeated, opts=[]}]}]).
  