anchor.diff:                SubMsgNames).
   
   format_sint_encoder() ->
  -    [f("e_type_sint(Value, Bin) when Value >= 0 ->~n"),
  -     f("    e_varint(Value * 2, Bin);~n"),
  -     f("e_type_sint(Value, Bin) ->~n"),
  -     f("    e_varint(Value * -2 - 1, Bin).~n~n")].
  +    gpb_codegen:format_fn(
  +      e_type_sint,
  +      fun(Value, Bin) when Value >= 0 ->
  +              e_varint(Value * 2, Bin);
  +         (Value, Bin) ->
  +              e_varint(Value * -2 - 1, Bin)
  +      end).
   
   format_int_encoder(Type, BitLen) ->
  -    FnName = mk_fn(e_type_, Type),
  -    [f("~p(Value, Bin) when 0 =< Value, Value =< 127 ->~n", [FnName]),
  -     f("    <<Bin/binary, Value>>; %% fast path~n"),
  -     f("~p(Value, Bin) ->~n", [FnName]),
  -     f("    <<N:~w/unsigned-native>> = <<Value:~w/signed-native>>,~n",
  -       [BitLen, BitLen]),
  -     f("    e_varint(N, Bin).~n~n")].
  +    gpb_codegen:format_fn(
  +      mk_fn(e_type_, Type),
  +      fun(Value, Bin) when 0 =< Value, Value =< 127 ->
  +              <<Bin/binary, Value>>; %% fast path
  +         (Value, Bin) ->
  +              <<N:'<Sz>'/unsigned-native>> = <<Value:'<Sz>'/signed-native>>,
  +              e_varint(N, Bin)
  +      end,
  +      [replace_term('<Sz>', BitLen)]).
   
   format_bool_encoder() ->
  -    [f("e_type_bool(true, Bin)  -> <<Bin/binary, 1>>;~n"),
  -     f("e_type_bool(false, Bin) -> <<Bin/binary, 0>>.~n~n")].
  +    gpb_codegen:format_fn(
  +      e_type_bool,
  +      fun(true, Bin)  -> <<Bin/binary, 1>>;
  +         (false, Bin) -> <<Bin/binary, 0>>
  +      end).
   
   format_fixed_encoder(Type, BitLen, BitType) ->
  -    FnName = mk_fn(e_type_, Type),
  -    [f("~p(Value, Bin) ->~n", [FnName]),
  -     f("    <<Bin/binary, Value:~p/~s>>.~n~n", [BitLen, BitType])].
  +    gpb_codegen:format_fn(
  +      mk_fn(e_type_, Type),
  +      fun(Value, Bin) ->
  +              <<Bin/binary, Value:'<Sz>'/'<T>'>>
  +      end,
  +      [replace_term('<Sz>', BitLen),
  +       splice_trees('<T>', [erl_syntax:atom(T) || T <- BitType])]).
   
   format_string_encoder() ->
  -    [f("e_type_string(S, Bin) ->~n"),
  -     f("    Utf8 = unicode:characters_to_binary(S),~n"),
  -     f("    Bin2 = e_varint(byte_size(Utf8), Bin),~n"),
  -     f("    <<Bin2/binary, Utf8/binary>>.~n~n")].
  +    gpb_codegen:format_fn(
  +      e_type_string,
  +      fun(S, Bin) ->
  +              Utf8 = unicode:characters_to_binary(S),
  +              Bin2 = e_varint(byte_size(Utf8), Bin),
  +              <<Bin2/binary, Utf8/binary>>
  +      end).
   
   format_bytes_encoder() ->
  -    [f("e_type_bytes(Bytes, Bin) ->~n"),
  -     f("    Bin2 = e_varint(byte_size(Bytes), Bin),~n"),
  -     f("    <<Bin2/binary, Bytes/binary>>.~n~n")].
  +    gpb_codegen:format_fn(
  +      e_type_bytes,
  +      fun(Bytes, Bin) ->
  +              Bin2 = e_varint(byte_size(Bytes), Bin),
  +              <<Bin2/binary, Bytes/binary>>
  +      end).
   
   format_varint_encoder() ->
  -    [f("e_varint(N, Bin) when N =< 127 ->~n"),
  -     f("    <<Bin/binary, N>>;~n"),
  -     f("e_varint(N, Bin) ->~n"),
  -     f("    Bin2 = <<Bin/binary, (N band 127 bor 128)>>,~n"),
  -     f("    e_varint(N bsr 7, Bin2).~n~n")].
  +    gpb_codegen:format_fn(
  +      e_varint,
  +      fun(N, Bin) when N =< 127 ->
  +              <<Bin/binary, N>>;
  +         (N, Bin) ->
  +              Bin2 = <<Bin/binary, (N band 127 bor 128)>>,
  +              call_self(N bsr 7, Bin2)
  +      end).
   
   %% -- decoders -----------------------------------------------------
   
  
positive.code:     NeedsFixed64  = needs_f_enc(fixed64, AnRes),
      NeedsSFixed64 = needs_f_enc(sfixed64, AnRes),
      NeedsDouble   = needs_f_enc(double, AnRes),
      [[format_fixed_encoder(fixed32,  32, 'little')        || NeedsFixed32],
       [format_fixed_encoder(sfixed32, 32, 'little-signed') || NeedsSFixed32],
       [format_fixed_encoder(float,    32, 'little-float')  || NeedsFloat],
       [format_fixed_encoder(fixed64,  64, 'little')        || NeedsFixed64],
       [format_fixed_encoder(sfixed64, 64, 'little-signed') || NeedsSFixed64],
       [format_fixed_encoder(double,   64, 'little-float')  || NeedsDouble]].
  
  needs_f_enc(FixedType, #anres{used_types=UsedTypes, fixlen_types=FTypes}) ->
      %% If a fixlength-type occurs _only_ as a packed repeated field,
  
negative.code:     Key = (FNum bsl 3) bor gpb:encode_wiretype(Type),
      varint_to_binary_fields(Key).
  
  mk_field_encode_fn_name(MsgName, #field{occurrence=repeated, name=FName}) ->
      mk_fn(e_field_, MsgName, FName);
  mk_field_encode_fn_name(MsgName, #field{type={msg,_Msg}, name=FName}) ->
  