anchor.diff:      NewType = Type#type{tag=[]},
       gen_encode(Erules,NewTname,NewType).
   
  -gen_encode_user(Erules,D) when is_record(D,typedef) ->
  +gen_encode_user(Erules, #typedef{}=D, Wrapper) ->
       Typename = [D#typedef.name],
       Type = D#typedef.typespec,
       InnerType = asn1ct_gen:get_inner(Type#type.def),
  -    OTag = Type#type.tag,
  -    Tag = [encode_tag_val(decode_class(X#tag.class),X#tag.form,X#tag.number)|| X <- OTag],
       emit([nl,nl,"%%================================"]),
       emit([nl,"%%  ",Typename]),
       emit([nl,"%%================================",nl]),
  -    emit(["'enc_",asn1ct_gen:list2name(Typename),
  -	  "'(Val",") ->",nl]),
  -    emit(["    'enc_",asn1ct_gen:list2name(Typename),
  -	  "'(Val, ", {asis,lists:reverse(Tag)},").",nl,nl]),
  -    emit({"'enc_",asn1ct_gen:list2name(Typename),"'(Val, TagIn) ->",nl}),
  +    FuncName = "'enc_" ++ asn1ct_gen:list2name(Typename) ++ "'",
  +    case Wrapper of
  +	true ->
  +	    %% This is a top-level type. Generate an 'enc_Type'/1
  +	    %% wrapper.
  +	    OTag = Type#type.tag,
  +	    Tag0 = [encode_tag_val(decode_class(Class), Form, Number) ||
  +		       #tag{class=Class,form=Form,number=Number} <- OTag],
  +	    Tag = lists:reverse(Tag0),
  +	    emit([FuncName,"(Val) ->",nl,
  +		  "    ",FuncName,"(Val, ",{asis,Tag},").",nl,nl]);
  +	false ->
  +	    ok
  +    end,
  +    emit([FuncName,"(Val, TagIn) ->",nl]),
       CurrentMod = get(currmod),
       case asn1ct_gen:type(InnerType) of
   	{constructed,bif} ->
  
positive.code: gen_internal_funcs(_,[]) ->
      ok;
  gen_internal_funcs(Erules,[TypeDef|Rest]) ->
      gen_encode_user(Erules,TypeDef),
      emit([nl,nl,"'dec_",TypeDef#typedef.name,
  %	  "'(Tlv, OptOrMand, TagIn) ->",nl]),
  	  "'(Tlv, TagIn) ->",nl]),
      gen_decode_user(Erules,TypeDef),
      gen_internal_funcs(Erules,Rest).
  
  
negative.code: %% encode #{typedef, {pos, name, typespec}}
  %%===============================================================================
  
  gen_encode(Erules, #typedef{}=D) ->
      gen_encode_user(Erules, #typedef{}=D, true).
  
  %%===============================================================================
  %% encode #{type, {tag, def, constraint}}
  