anchor.diff:                 '<enc>'('<F>', <<'<Bin>'/binary, '<Key>'>>),
                  Transforms)
       end;
  -field_encode_expr(MsgName, #gpb_oneof{fields=OFields}, FVar, PrevBVar) ->
  +field_encode_expr(MsgName, MsgVar, #gpb_oneof{name=FName, fields=OFields}, FVar,
  +                  PrevBVar, Opts) ->
       OFVar = prefix_var("O", FVar),
       OneofClauseTransform =
           repeat_clauses(
             '<oneof...>',
             [begin
  -               MatchPattern = ?expr({'<oneof-name>', '<OF>'},
  -                                    [replace_term('<oneof-name>', Name),
  -                                     replace_tree('<OF>', OFVar)]),
  +               MatchPattern =
  +                   case get_mapping_and_unset_by_opts(Opts) of
  +                       X when X == records;
  +                              X == {maps, present_undefined} ->
  +                           ?expr({'<oneof-name>', '<OF>'},
  +                                 [replace_term('<oneof-name>', Name),
  +                                  replace_tree('<OF>', OFVar)]);
  +                       {maps, omitted} ->
  +                           ?expr({ok, {'<oneof-name>', '<OF>'}},
  +                                 [replace_term('<oneof-name>', Name),
  +                                  replace_tree('<OF>', OFVar)])
  +                   end,
                  %% undefined is already handled, we have a match,
                  %% the field occurs, as if it had been required
                  OField2 = OField#?gpb_field{occurrence=required},
  -               EncExpr = field_encode_expr(MsgName, OField2, OFVar, PrevBVar),
  +               EncExpr = field_encode_expr(MsgName, MsgVar, OField2, OFVar,
  +                                           PrevBVar, Opts),
                  [replace_tree('<oneof...>', MatchPattern),
                   replace_tree('<expr>', EncExpr)]
              end
              || #?gpb_field{name=Name}=OField <- OFields]),
  -    ?expr(case '<F>' of
  -              undefined    -> '<Bin>';
  -              '<oneof...>' -> '<expr>'
  -          end,
  -          [replace_tree('<F>', FVar),
  -           replace_tree('<Bin>', PrevBVar),
  -           OneofClauseTransform]).
  -%%).
  +    case get_mapping_and_unset_by_opts(Opts) of
  +        X when X == records;
  +               X == {maps, present_undefined} ->
  +            ?expr(case '<F>' of
  +                      undefined    -> '<Bin>';
  +                      '<oneof...>' -> '<expr>'
  +                  end,
  +                  [replace_tree('<F>', FVar),
  +                   replace_tree('<Bin>', PrevBVar),
  +                   OneofClauseTransform]);
  +        {maps, omitted} ->
  +            ?expr(case maps:find('fieldname', 'M') of
  +                      error        -> '<Bin>';
  +                      '<oneof...>' -> '<expr>'
  +                  end,
  +                  [replace_term('fieldname', FName),
  +                   replace_tree('M', MsgVar),
  +                   replace_tree('<Bin>', PrevBVar),
  +                   OneofClauseTransform])
  +    end.
   
   mk_field_encode_fn_name(MsgName, #?gpb_field{occurrence=repeated, name=FName}) ->
       mk_fn(e_field_, MsgName, FName);
  
positive.code:     FNames = get_field_names(MsgDef),
      FVars = [var_f_n(I) || I <- lists:seq(1, length(FNames))],
      BVars = [var_b_n(I) || I <- lists:seq(1, length(FNames)-1)] ++ [last],
      {EncodeExprs, _} =
          lists:mapfoldl(
            fun({NewBVar, Field, FVar}, PrevBVar) when NewBVar /= last ->
                    EncExpr = field_encode_expr(MsgName, Field, FVar, PrevBVar),
                    E = ?expr('<NewB>' = '<encode-expr>',
                              [replace_tree('<NewB>', NewBVar),
                               replace_tree('<encode-expr>', EncExpr)]),
                    {E, NewBVar};
               ({last, Field, FVar}, PrevBVar) ->
                    EncExpr = field_encode_expr(MsgName, Field, FVar, PrevBVar),
                    {EncExpr, dummy}
            end,
            ?expr(Bin),
            lists:zip3(BVars, MsgDef, FVars)),
      FnName = mk_fn(e_msg_, MsgName),
      [gpb_codegen:format_fn(
         FnName,
         fun(Msg) ->
  
negative.code:        fun('<msg-matching>', Bin) ->
                 '<encode-param-exprs>'
         end,
         [replace_tree('<msg-matching>', FieldMatching),
          splice_trees('<encode-param-exprs>', EncodeExprs)])].
  
  get_field_names(MsgDef) ->
  