{{declare}} 
{%-if package%}
package {{package}};
{%-endif%}
{%for pkg in imports %}
import  "{{pkg}}.proto";
{%- endfor %}
{% for df in defs %}
//////////////BEGIN /// @{{df.type}}:{{df.name}}://{{df.cn}}//{{df.desc}} 
{%- if df.type  == 'msg' %}
message {{df.name}} {
    {%-for fd in df.fields %}
    {%if fd.repeat %}repeated{%elif fd.required %}required{%else%}optional{%endif%}    {{fd.t}}    {{fd.n}} = {{loop.index}}; //{{fd.cn}}//{{fd.desc}}
    {%-endfor%}
};
{%- elif df.type == 'enum' %}
enum {{df.name}} {
{%- if df.options.alias %}
    option allow_alias=true;
{% endif %}
    {%-for fd in df.fields %}
    {{fd.n}} = {{fd.v}}; //{{fd.cn}}//{{fd.desc}}
    {%-endfor%}
};
{%-elif df.type == 'rpc' %}
//RPC.REQUEST
message {{df.name}}Req { 
    {%-for fd in df.req %}
    {%if fd.repeat %}repeated{%elif fd.required %}required{%else%}optional{%endif%}    {{fd.t}}    {{fd.n}} = {{loop.index}}; //{{fd.cn}}//{{fd.desc}}
    {%-endfor%}
};
//RPC.RESPONSE
message {{df.name}}Res {
    {%-for fd in df.res %}
    {%if fd.repeat %}repeated{%elif fd.required %}required{%else%}optional{%endif%}    {{fd.t}}    {{fd.n}} = {{loop.index}}; //{{fd.cn}}//{{fd.desc}}
    {%-endfor%}
};
//RPC.BODY
message {{df.name}} {
    optional    {{df.name}}Req    req = 1; //REQUEST
    optional    {{df.name}}Res    res = 2; //RESPONSE
};
{%-elif df.type == 'service' %}
enum {{df.name}}Cmd {
    {%-for fd in df.fields %}
    {{fd.t|rpc_cmd(df.name, df.options.cmd_pre)}}_REQ = {{loop.index*2-1}}; //RPC:{{df.name}} REQUEST
    {{fd.t|rpc_cmd(df.name, df.options.cmd_pre)}}_RES = {{loop.index*2}}; //RPC:{{df.name}} RESPONSE
    {%-endfor%}
};
message {{df.name}} {
    required    {{df.name}}Head     head = 1;
    {%-for fd in df.fields %}
    optional    {{fd.t}}    {{fd.t|rpc_name(df.name)}} = {{loop.index+1}}; //{{fd.t|rpc_cmd(df.name, df.options.cmd_pre)}}_RE[QS]:{{fd.cn}}//{{fd.desc}}
    {%-endfor%}
};
{%-elif df.type == 'table' %}
//index by {{df.options.idx}}
message {{df.name}}Desc {
    {%-for fd in df.fields %}
    {%if fd.repeat %}repeated{%elif fd.required %}required{%else%}optional{%endif%}    {{fd.t}}    {{fd.n}} = {{loop.index}}; //{{fd.cn}}//{{fd.desc}}
    {%-endfor%}
};
message TB{{df.name}}Desc {
    repeated     {{df.name}}Desc    list = 1; //table entry rows
};
{%- endif %}
//////////////END///// @{{df.type}}:{{df.name}}://{{df.cn}}//{{df.desc}} 


{%endfor %}

