|
|
@ -16,35 +16,74 @@ |
|
|
|
]). |
|
|
|
|
|
|
|
-define(TypeValue, [ |
|
|
|
{<<"bool">>, <<"bool">>} |
|
|
|
, {<<"int8">>, <<"int8">>} |
|
|
|
, {<<"uint8">>, <<"uint8">>} |
|
|
|
, {<<"int16">>, <<"int16">>} |
|
|
|
, {<<"uint16">>, <<"uint16">>} |
|
|
|
, {<<"int32">>, <<"int32">>} |
|
|
|
, {<<"uint32">>, <<"uint32">>} |
|
|
|
, {<<"int64">>, <<"int64">>} |
|
|
|
, {<<"uint64">>, <<"uint64">>} |
|
|
|
, {<<"float">>, <<"float">>} |
|
|
|
, {<<"double">>, <<"double">>} |
|
|
|
, {<<"string">>, <<"string">>} |
|
|
|
{<<"bool">>, <<"bool">>, <<"false">>} |
|
|
|
, {<<"int8">>, <<"int8">>, <<"0">>} |
|
|
|
, {<<"uint8">>, <<"uint8">>, <<"0">>} |
|
|
|
, {<<"int16">>, <<"int16">>, <<"0">>} |
|
|
|
, {<<"uint16">>, <<"uint16">>, <<"0">>} |
|
|
|
, {<<"int32">>, <<"int32">>, <<"0">>} |
|
|
|
, {<<"uint32">>, <<"uint32">>, <<"0">>} |
|
|
|
, {<<"int64">>, <<"int64">>, <<"0">>} |
|
|
|
, {<<"uint64">>, <<"uint64">>, <<"0">>} |
|
|
|
, {<<"float">>, <<"float">>, <<"0">>} |
|
|
|
, {<<"double">>, <<"double">>, <<"0">>} |
|
|
|
, {<<"string">>, <<"string">>, <<"\"\"">>} |
|
|
|
]). |
|
|
|
|
|
|
|
builtRecStr({TypeStr, NameStr}) -> |
|
|
|
builtMemberStr({TypeStr, NameStr}) -> |
|
|
|
case lists:keyfind(TypeStr, 1, ?TypeValue) of |
|
|
|
{TypeStr, CSTypeStr} -> |
|
|
|
<<"\t\tpublic ", CSTypeStr/binary, " ", NameStr/binary, ";;\n">>; |
|
|
|
{TypeStr, _LuaTypeStr, DefValue} -> |
|
|
|
<<"\tt.", NameStr/binary, " = ", DefValue/binary, "\n">>; |
|
|
|
_ -> |
|
|
|
case TypeStr of |
|
|
|
<<"list[", LeftStr/binary>> -> |
|
|
|
[SubTypeStr | _] = re:split(LeftStr, <<"\\]">>, [{return, binary}]), |
|
|
|
case lists:keyfind(SubTypeStr, 1, ?TypeValue) of |
|
|
|
{SubTypeStr, SubCSTypeStr} -> |
|
|
|
<<"\t\tpublic List<", SubCSTypeStr/binary, "> ", NameStr/binary, ";\n">>; |
|
|
|
_ -> |
|
|
|
<<"\t\tpublic List<", SubTypeStr/binary, "> ", NameStr/binary, ";\n">> |
|
|
|
end; |
|
|
|
_ -> |
|
|
|
<<"\t\tpublic ", TypeStr/binary, " ", NameStr/binary, ";\n">> |
|
|
|
end |
|
|
|
<<"\tt.", NameStr/binary, " = {}", "\n">> |
|
|
|
end. |
|
|
|
|
|
|
|
builtEncodeStr({TypeStr, NameStr}) -> |
|
|
|
ok. |
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成encode%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
|
|
%% byteArray.write_uint16(account.size()); |
|
|
|
%% for(int i=0; i<account.size();i++) |
|
|
|
%% { |
|
|
|
%% byteArray.write_string(account[i]); |
|
|
|
%% } |
|
|
|
|
|
|
|
%% 生成decode中的数组 |
|
|
|
make_protocal_encode_item({Type, Name}, TypeList) -> |
|
|
|
case lists:keyfind(Type, 1, TypeList) of |
|
|
|
{Type, base_type} -> |
|
|
|
" \tbyteArray.write_"++ atom_to_list(Type) ++"(tb." ++ get_csharp_Var(Name) ++ ")\n"; |
|
|
|
{Type, string_type} -> |
|
|
|
" \tbyteArray.write_"++ atom_to_list(Type) ++"(tb." ++ get_csharp_Var(Name) ++ ")\n"; |
|
|
|
{_Type, enum_type} -> |
|
|
|
make_protocal_encode_item({int, Name}, TypeList); |
|
|
|
_ -> |
|
|
|
" tb." ++ get_csharp_Var(Name) ++ ".encode(byteArray);\n" |
|
|
|
%%" " ++ get_csharp_Var(Name) ++ ".encode(byteArray)\n\n" |
|
|
|
end; |
|
|
|
make_protocal_encode_item({Type, Name, _DefaultValue}, TypeList) |
|
|
|
when Type /= array-> |
|
|
|
make_protocal_encode_item({Type, Name}, TypeList); |
|
|
|
make_protocal_encode_item({array, Type, Name}, TypeList) -> |
|
|
|
case lists:keyfind(Type, 1, TypeList) of |
|
|
|
{Type1, base_type} -> |
|
|
|
make_protocal_encode_item_base_type(Name, Type1); |
|
|
|
{Type1, string_type} -> |
|
|
|
make_protocal_encode_item_base_type(Name, Type1); |
|
|
|
{_Type, enum_type} -> |
|
|
|
make_protocal_encode_item({array, int, Name}, TypeList); |
|
|
|
_ -> |
|
|
|
NameStr = get_csharp_Var(Name), |
|
|
|
" byteArray.write_uint16(#(tb." ++ NameStr ++ "))\n" ++ |
|
|
|
" for k, v in pairs(tb." ++ NameStr ++ ") do\n" ++ |
|
|
|
" byteArray = v.encode(byteArray)\n" ++ |
|
|
|
" end\n" |
|
|
|
end. |
|
|
|
|
|
|
|
make_protocal_encode_item_base_type(Name, Type) -> |
|
|
|
NameStr = get_csharp_Var(Name), |
|
|
|
TypeStr = get_csharp_type(Type), |
|
|
|
" byteArray.write_uint16(#(tb." ++ NameStr ++ "))\n" ++ |
|
|
|
" for k, v in pairs (tb." ++ NameStr ++ ") do\n" ++ |
|
|
|
" byteArray.write_" ++ TypeStr ++ "(v)\n" ++ |
|
|
|
" end\n". |
|
|
|
|