diff --git a/README.md b/README.md index f7203fd..bc7b5d1 100644 --- a/README.md +++ b/README.md @@ -42,15 +42,10 @@ Use double: 直接存放64bit的值 bool: 占位8bit 如果为true 则存放的值为1 否则存放的值为0 record(struct): 如果是undefined 或者是空指针 则 8bit Tag 值为0, 否则 8bit的tag 值为1 + record的二进制数据 - list_+上面的数据类型的时候: 16bit的tag 用于存放 数组的长度 + 按数组顺序序列化每个元素的值的二进制数据 + list_+上面的数据类型的时候: 16bit的tag 用于存放 数组的长度 + 按数组顺序序列化每个元素的值的二进制数据(注意:如果列表类型为record(struct) 每个值序列化的时候并不会加 8bit的tag, 直接存record的二进制数据) ### maybe TODO - - 生成的protoMsg.erl - encode 函数参数列表太长时 换行显示 - encode返回的编码列表参数太多时 换行显示 - decodeBin simple类型解码列表过长时 换行显示 - decodeBin 返回元组元素太多时 换行显示 + lua 支持 integer number ### 关于消息接收转发解码和发送 diff --git a/src/genProto.erl b/src/genProto.erl index 2b3c83b..f19791c 100644 --- a/src/genProto.erl +++ b/src/genProto.erl @@ -9,87 +9,98 @@ -export([main/1]). -export([ - convertFile/1 - , convert/1 - , convertDir/0 - , convertDir/1 - , convertDir/3 + convertFile/1 + , convert/1 + , convertDir/0 + , convertDir/1 ]). main(Args) -> - case Args of - [] -> - convertDir(?DefProtoDir, ?DefErlDir, ?DefHrlDir); - _ -> - [ProtoDir, HrlDir, ErlDir] = Args, - convertDir(ProtoDir, HrlDir, ErlDir) - end. + case Args of + [] -> + convertDir(["./", "all", "./"]); + _ -> + convertDir(Args) + end. convertFile(File) -> - erlang:erase(), - erlang:put(pd_errlist, []), - erlang:put(pd_handler, []), - case filename:extension(File) == ".mpdf" of - true -> - io:format("Convert proto msg file: ~s ~n", [File]), - BaseName = filename:basename(File, ".mpdf"), - [ModIndex, ModName] = re:split(BaseName, "_"), - Index = binary_to_integer(ModIndex), - erlang:put(pd_messageid, Index * ?MsgIdSegSize + 1), - erlang:put(pd_handler, [{Index, ModName} | erlang:get(pd_handler)]), - erlang:put(pd_errcodeid, Index * ?MsgIdSegSize + 1), - SProto = protoParse:parseFile(File), - ErrCode = erlang:get(pd_errlist), - Handler = erlang:get(pd_handler), - {SProto, Handler, ErrCode}; - _ -> - io:format("not proto msg file: ~s ~n", [File]) - end. + erlang:erase(), + erlang:put(pd_errlist, []), + erlang:put(pd_handler, []), + case filename:extension(File) == ".mpdf" of + true -> + io:format("Convert proto msg file: ~s ~n", [File]), + BaseName = filename:basename(File, ".mpdf"), + [ModIndex, ModName] = re:split(BaseName, "_"), + Index = binary_to_integer(ModIndex), + erlang:put(pd_messageid, Index * ?MsgIdSegSize + 1), + erlang:put(pd_handler, [{Index, ModName} | erlang:get(pd_handler)]), + erlang:put(pd_errcodeid, Index * ?MsgIdSegSize + 1), + SProto = protoParse:parseFile(File), + ErrCode = erlang:get(pd_errlist), + Handler = erlang:get(pd_handler), + {SProto, Handler, ErrCode}; + _ -> + io:format("not proto msg file: ~s ~n", [File]) + end. -convert([ProtoDir, HrlDir, ErlDir]) -> - convertDir(atom_to_list(ProtoDir), atom_to_list(HrlDir), atom_to_list(ErlDir)). +convert(Args) -> + convertDir(Args). convertDir() -> - convertDir("./", "./", "./"). -convertDir(ProtoDir) -> - convertDir(ProtoDir, "./", "./"). -convertDir(ProtoDir, HrlDir, ErlDir) -> - erlang:erase(), - erlang:put(pd_errlist, []), - erlang:put(pd_handler, []), - FunRead = - fun(File, ProAcc) -> - case filename:extension(File) == ".mpdf" of - true -> - io:format("Convert proto msg file: ~s ~n", [File]), - BaseName = filename:basename(File, ".mpdf"), - [ModIndex, ModName] = re:split(BaseName, "_"), - Index = binary_to_integer(ModIndex), - erlang:put(pd_messageid, Index * ?MsgIdSegSize + 1), - erlang:put(pd_handler, [{Index, ModName} | erlang:get(pd_handler)]), - erlang:put(pd_errcodeid, Index * ?MsgIdSegSize + 1), - SProto = protoParse:parseFile(File), - ErrCode = erlang:get(pd_errlist), - Handler = erlang:get(pd_handler), - erlang:erase(), - erlang:put(pd_errlist, ErrCode), - erlang:put(pd_handler, Handler), - [SProto | ProAcc]; - _ -> - ProAcc - end - end, + convertDir(["./", "all", "./"]). +convertDir([ProtoDir | LeftArgs]) -> + erlang:erase(), + erlang:put(pd_errlist, []), + erlang:put(pd_handler, []), + FunRead = + fun(File, ProAcc) -> + case filename:extension(File) == ".mpdf" of + true -> + io:format("Convert proto msg file: ~s ~n", [File]), + BaseName = filename:basename(File, ".mpdf"), + [ModIndex, ModName] = re:split(BaseName, "_"), + Index = binary_to_integer(ModIndex), + erlang:put(pd_messageid, Index * ?MsgIdSegSize + 1), + erlang:put(pd_handler, [{Index, ModName} | erlang:get(pd_handler)]), + erlang:put(pd_errcodeid, Index * ?MsgIdSegSize + 1), + SProto = protoParse:parseFile(File), + ErrCode = erlang:get(pd_errlist), + Handler = erlang:get(pd_handler), + erlang:erase(), + erlang:put(pd_errlist, ErrCode), + erlang:put(pd_handler, Handler), + [SProto | ProAcc]; + _ -> + ProAcc + end + end, - SProtoListOfList = filelib:fold_files(ProtoDir, "\\.mpdf$", true, FunRead, []), - SProtoList = lists:append(SProtoListOfList), - ErrCodeList = erlang:get(pd_errlist), + SProtoListOfList = filelib:fold_files(ProtoDir, "\\.mpdf$", true, FunRead, []), + SProtoList = lists:append(SProtoListOfList), + ErrCodeList = erlang:get(pd_errlist), - SortedSProtoList = lists:sort(fun({_Name1, MessageId1, _FieldList1}, {_Name2, MessageId2, _FieldList2}) -> - MessageId1 < MessageId2 end, SProtoList), + SortedSProtoList = lists:sort(fun({_Name1, MessageId1, _FieldList1}, {_Name2, MessageId2, _FieldList2}) -> + MessageId1 < MessageId2 end, SProtoList), + SortedErrList = lists:sort(fun({_ErrName1, ErrCodeId1, _Desc1}, {_ErrName2, ErrCodeId2, _Desc2}) -> + ErrCodeId1 < ErrCodeId2 end, ErrCodeList), + genProto(LeftArgs, SortedSProtoList, SortedErrList). + +%% 如果有其他语言请在这里添加入口函数 +genProto([], _SortedSProtoList, _SortedErrList) -> + ok; +genProto(["all", AllDir], SortedSProtoList, SortedErrList) -> + gErlGen:genErl(SortedSProtoList, SortedErrList, AllDir, AllDir), + gCsGen:genCs(SortedSProtoList, SortedErrList, AllDir, AllDir), + gLuaGen:genLua(SortedSProtoList, SortedErrList, AllDir, AllDir); +genProto(["erl", HrlDir, ErlDir | LeftArgs], SortedSProtoList, SortedErrList) -> + gErlGen:genErl(SortedSProtoList, SortedErrList, HrlDir, ErlDir), + genProto(LeftArgs, SortedSProtoList, SortedErrList); +genProto(["cs", CsDir | LeftArgs], SortedSProtoList, SortedErrList) -> + gCsGen:genCs(SortedSProtoList, SortedErrList, CsDir, CsDir), + genProto(LeftArgs, SortedSProtoList, SortedErrList); +genProto(["lua", LuaDir | LeftArgs], SortedSProtoList, SortedErrList) -> + gLuaGen:genLua(SortedSProtoList, SortedErrList, LuaDir, LuaDir), + genProto(LeftArgs, SortedSProtoList, SortedErrList). - SortedErrList = lists:sort(fun({_ErrName1, ErrCodeId1, _Desc1}, {_ErrName2, ErrCodeId2, _Desc2}) -> - ErrCodeId1 < ErrCodeId2 end, ErrCodeList), - gErlGen:genErl(SortedSProtoList, SortedErrList, HrlDir, ErlDir), - gCsGen:genCs(SortedSProtoList, SortedErrList, HrlDir, ErlDir). -%% 如果有其他语言请在这里添加入口函数 \ No newline at end of file diff --git a/src/writeLua/gLuaField.erl b/src/writeLua/gLuaField.erl index dde1691..f000d67 100644 --- a/src/writeLua/gLuaField.erl +++ b/src/writeLua/gLuaField.erl @@ -3,87 +3,89 @@ -compile([export_all, nowarn_export_all]). -define(SimpleList, [ - <<"int8">> - , <<"uint8">> - , <<"int16">> - , <<"uint16">> - , <<"int32">> - , <<"uint32">> - , <<"int64">> - , <<"uint64">> - , <<"float">> - , <<"double">> + <<"int8">> + , <<"uint8">> + , <<"int16">> + , <<"uint16">> + , <<"int32">> + , <<"uint32">> + , <<"int64">> + , <<"uint64">> + , <<"float">> + , <<"double">> ]). -define(TypeValue, [ - {<<"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">>, <<"\"\"">>} + {<<"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">>, <<"\"\"">>} ]). builtMemberStr({TypeStr, NameStr}) -> - case lists:keyfind(TypeStr, 1, ?TypeValue) of - {TypeStr, _LuaTypeStr, DefValue} -> - <<"\tt.", NameStr/binary, " = ", DefValue/binary, "\n">>; - _ -> - <<"\tt.", NameStr/binary, " = {}", "\n">> - end. + case lists:keyfind(TypeStr, 1, ?TypeValue) of + {TypeStr, _LuaTypeStr, DefValue} -> + <<"\tt.", NameStr/binary, " = ", DefValue/binary, "\n">>; + _ -> + <<"\tt.", NameStr/binary, " = {}", "\n">> + end. builtEncodeStr({TypeStr, NameStr}) -> - ok. -%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成encode%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% byteArray.write_uint16(account.size()); -%% for(int i=0; i + <<"\t\tbyteArray.write_", LuaTypeStr/binary, "(tb.", NameStr/binary, ")\n">>; + _ -> + case TypeStr of + <<"list[", LeftStr/binary>> -> + [SubTypeStr | _] = re:split(LeftStr, <<"\\]">>, [{return, binary}]), + case lists:keyfind(SubTypeStr, 1, ?TypeValue) of + {SubTypeStr, LuaTypeStr, _DefValue} -> + <<"\t\tbyteArray.write_uint16(#(tb.", NameStr/binary, "))\n", + "\t\tfor k, v in pairs (tb.", NameStr/binary, ") do\n", + "\t\t\tbyteArray.write_", LuaTypeStr/binary, "(v)\n", + "\t\tend\n">>; + _ -> + <<"\t\tbyteArray.write_uint16(#(tb.", NameStr/binary, "))\n", + "\t\tfor k, v in pairs(tb.", NameStr/binary, ") do\n", + "\t\t\tbyteArray = v.encode(byteArray)\n" + "\t\tend\n">> + end; + _ -> + <<"\t\tif tb.", NameStr/binary, " and next(tb.", NameStr/binary, ") then\n\t\t\tbyteArray.write_uint8(1)\n\t\t\ttb.", NameStr/binary, ".encode(byteArray)\n\t\telse\n\t\t\tbyteArray.write_uint8(0)\n\t\tend\n">> + end + end. -%% 生成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". +builtDecodeStr({TypeStr, NameStr}) -> + case lists:keyfind(TypeStr, 1, ?TypeValue) of + {TypeStr, LuaTypeStr, _DefValue} -> + <<"\t\ttb.", NameStr/binary, " = byteArray.read_", LuaTypeStr/binary, "()\n">>; + _ -> + case TypeStr of + <<"list[", LeftStr/binary>> -> + [SubTypeStr | _] = re:split(LeftStr, <<"\\]">>, [{return, binary}]), + case lists:keyfind(SubTypeStr, 1, ?TypeValue) of + {SubTypeStr, LuaTypeStr, _DefValue} -> + CntName = <<"cntOf", NameStr/binary>>, + ReadCnt = <<"\t\tlocal ", CntName/binary, " = byteArray.read_uint16()\n\t\ttb.", NameStr/binary, " = {}\n">>, + <>; + _ -> + CntName = <<"cntOf", NameStr/binary>>, + ReadCnt = <<"\t\tlocal ", CntName/binary, " = byteArray.read_uint16()\n\t\ttb.", NameStr/binary, " = {}\n">>, + <> + end; + _ -> + NotNilName = <<"isNil", NameStr/binary>>, + NotNil = <<"\t\tlocal ", NotNilName/binary, " = byteArray.read_uint8()\n">>, + ReadTable = <<"\t\t\ttb.", NameStr/binary, " = ", TypeStr/binary, "()\n\t\t\ttb.", NameStr/binary, ".decode(byteArray)\n">>, + < 0 then\n", ReadTable/binary, "\t\telse\n\t\t\ttb.", NameStr/binary, " = {}\n\t\tend\n">> + end + end. diff --git a/src/writeLua/gLuaGen.erl b/src/writeLua/gLuaGen.erl index cfa7db3..b465d45 100644 --- a/src/writeLua/gLuaGen.erl +++ b/src/writeLua/gLuaGen.erl @@ -5,7 +5,7 @@ ]). spellFunHead(MsgName, MsgId) -> - <<"function", MsgName/binary, "()\n\tlocal tb = {}\n\ttb.msgId =", (integer_to_binary(MsgId))/binary, "\n">>. + <<"function ", MsgName/binary, "()\n\tlocal tb = {}\n\ttb.msgId =", (integer_to_binary(MsgId))/binary, "\n">>. spellMember(FieldList) -> <<<<(gLuaField:builtMemberStr(OneTypeName))/binary>> || OneTypeName <- FieldList>>. @@ -16,6 +16,21 @@ spellEncode(FieldList) -> EnEnd = <<"\t\treturn byteArray\n\tend\n\n">>, <>. +spellDecode(FieldList) -> + EnHead = <<"\ttb.decode = function(byteArray)\n">>, + EnBody = <<<<(gLuaField:builtDecodeStr(OneTypeName))/binary>> || OneTypeName <- FieldList>>, + EnEnd = <<"\tend\n\n">>, + <>. + +spellBuild(MsgId) -> + <<"\ttb.build = function(byteArray)\n\t\tbyteArray.write_uint16(", (integer_to_binary(MsgId))/binary, ")\n\t\treturn tb.encode(byteArray)\n\tend\n\n">>. + +spellEnd() -> + <<"\treturn tb\nend\n\n">>. + +spellMsgName(MsgId, MsgName) -> + <<"\t[", (integer_to_binary(MsgId))/binary, "] = \"", MsgName/binary, "\",\n">>. + genLua(SortedSProtoList, _SortedErrList, LuaDir, _) -> FunSpell = fun({MsgName, MsgId, FieldList}, {TableBinAcc, MsgNameBinAcc}) -> diff --git a/src/writeLua/gLuaGen1.erl b/src/writeLua/gLuaGen1.erl deleted file mode 100644 index e478211..0000000 --- a/src/writeLua/gLuaGen1.erl +++ /dev/null @@ -1,367 +0,0 @@ --module(gLuaGen1). - --export([ - genLua/4 -]). - --export([start/0]). --export([test/0]). -%% -%% API Functions -%% - -start() -> - StructList = protocol_def:get_struct_def(), - TypeList = gen_common:get_type(), - FileStr = make_protocal(StructList, "", TypeList), - file:write_file("NetPacket.lua", FileStr), - - MsgTypeStr = make_protocal_msg_type(StructList, "", 1), - file:write_file("protoName.lua", MsgTypeStr). - -make_protocal([], StructStr, _TypeList) -> - StructStr; -make_protocal([Struct | Structs], StructStr, TypeList) -> - [StructName | NewStructList] = Struct, - VariableStr = make_protocal_Variable(NewStructList, "", TypeList), - EncodeStr = make_protocal_encode(NewStructList, "", TypeList), - DecodeStr = make_protocal_decode(NewStructList, "", TypeList), - BuildStr = make_protocal_build(StructName), - CreateStr = make_protocal_create(StructName), - StructStr1 = StructStr ++ "\nfunction " ++ atom_to_list(StructName) ++ " ()" ++ - "\n" ++ - " local tb = {}\n" ++ - make_getmsgid(StructName) ++ - %% " public int getMsgID()\n" ++ - %% " {\n" ++ - %% " return NetMsgType.msg_" ++ atom_to_list(StructName) ++ ";\n" ++ - %% " }\n" ++ - VariableStr ++ EncodeStr ++ DecodeStr ++ BuildStr ++ CreateStr ++ "\nend\n", - make_protocal(Structs, StructStr1, TypeList). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成变量%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -make_protocal_Variable([], VariableStr, _TypeList) -> - VariableStr; -make_protocal_Variable([{Type, Name} | Vars], VariableStr, TypeList) -> - VariableStr1 = - case lists:keyfind(Type, 1, TypeList) of - {_Type1, base_type} -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = 0\n"; - {_Type1, string_type} -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = \"\"\n"; - {_Type, enum_type} -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = 0\n"; - _ -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = {}\n" - end, - make_protocal_Variable(Vars, VariableStr1, TypeList); - -make_protocal_Variable([{Type, Name, DefaultValue} | Vars], VariableStr, TypeList) - when Type =/= array -> - VariableStr1 = - case lists:keyfind(Type, 1, TypeList) of - {_Type1, base_type} -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = " ++ get_default_value(Type, DefaultValue) ++ "\n"; - {_Type1, string_type} -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = " ++ get_default_value(Type, DefaultValue) ++ ";\n"; - {_Type, enum_type} -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = 0\n"; - _ -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = {}\n" - end, - make_protocal_Variable(Vars, VariableStr1, TypeList); - -make_protocal_Variable([{array, Type, Name} | Vars], VariableStr, TypeList) -> - VariableStr1 = - case lists:keyfind(Type, 1, TypeList) of - {_Type1, base_type} -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = {}\n"; - {_Type1, string_type} -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = {}\n"; - {_Type, enum_type} -> - VariableStr ++ " tb." ++ atom_to_list(Name) ++ " = {}\n"; - _ -> - VariableStr ++ " tb." ++ get_csharp_Var(Name) ++ " = {}\n" - end, - make_protocal_Variable(Vars, VariableStr1, TypeList). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -make_protocal_build(StructName) -> - "\n tb.build = function(byteArray)\n" ++ - " byteArray.write_uint16(NetMsgType[\"msg_" ++ atom_to_list(StructName) ++ "\"])\n" ++ - " return tb.encode(byteArray)\n" ++ - " end\n". - -make_protocal_create(_StructName)-> - "\n return tb\n". - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成encode%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% byteArray.write_uint16(account.size()); -%% for(int i=0; i - "\n tb.encode = function(byteArray)\n" - ++ EncodeStr ++ " return byteArray\n" - ++ " end\n\n"; -make_protocal_encode([Struct | Vars], EncodeStr, TypeList) -> - EncodeStr1 = EncodeStr ++ make_protocal_encode_item(Struct, TypeList), - make_protocal_encode(Vars, EncodeStr1, TypeList). - -%% 生成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". - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成decode%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -make_protocal_decode([], DecodeStr, _TypeList) -> - " tb.decode = function(byteArray)\n" ++ DecodeStr ++ " end\n"; -make_protocal_decode([Struct | Vars], DecodeStr, TypeList) -> - DecodeStr1 = DecodeStr ++ make_protocal_decode_item(Struct, TypeList), - make_protocal_decode(Vars, DecodeStr1, TypeList). - -make_protocal_decode_item({Type, Name}, TypeList) -> - case lists:keyfind(Type, 1, TypeList) of - {Type1, base_type} -> - " tb." ++ get_csharp_Var(Name) ++ " = byteArray.read_"++ atom_to_list(Type1) ++"();\n"; - {Type1, string_type} -> - " tb." ++ get_csharp_Var(Name) ++ " = byteArray.read_"++ atom_to_list(Type1) ++"();\n"; - {_Type, enum_type} -> - make_protocal_decode_item({int, Name}, TypeList); - _ -> - TypeString = get_csharp_type(Type), - " tb." ++ get_csharp_Var(Name) ++ " = " ++ TypeString ++ "();\n" ++ - " tb." ++ get_csharp_Var(Name) ++ ".decode(byteArray);\n" - %%" " ++ get_csharp_Var(Name) ++ ".decode(byteArray);\n" - end; -make_protocal_decode_item({Type, Name, _DefaultValue}, TypeList) - when Type /= array-> - make_protocal_decode_item({Type, Name}, TypeList); -make_protocal_decode_item({array, Type, Name}, TypeList) -> - case lists:keyfind(Type, 1, TypeList) of - {Type1, base_type} -> - make_protocal_encode_item_decode_type(Name, Type1); - {Type1, string_type} -> - make_protocal_encode_item_decode_type(Name, Type1); - {_Type, enum_type} -> - make_protocal_decode_item({array, int, Name}, TypeList); - _ -> - TypeString = get_csharp_type(Type), - NameStr = get_csharp_Var(Name), - CountString = "countOf" ++ NameStr, - _ArrayString = "arrayOf" ++ NameStr, - " local " ++ CountString ++ " = byteArray.read_uint16()\n" ++ - " tb."++NameStr++" = {}\n" ++ - " for i = 1, " ++ CountString ++ " do\n" ++ - " local temp = " ++ TypeString ++ "()\n" ++ - " temp.decode(byteArray)\n" ++ - " table.insert(tb."++NameStr++", temp)\n" ++ - " end\n" - end. - -make_protocal_encode_item_decode_type(Name, Type) -> - NameStr = get_csharp_Var(Name), - TypeStr = atom_to_list(Type), - CountString = "countOf" ++ NameStr, - " local " ++ CountString ++ " = byteArray.read_uint16()\n" ++ - " tb."++NameStr++" = {}\n" ++ - " for i = 1, " ++ CountString ++ " do\n" ++ - " table.insert(tb." ++ NameStr ++ ", byteArray.read_" ++ TypeStr ++ "())\n" ++ - " end\n". - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成网络类型%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -make_protocal_msg_type([], MsgTypeStr, _Index) -> - "NetMsgType = \n" ++ - "{\n" ++ - MsgTypeStr ++ - "}"; -make_protocal_msg_type([Struct|Structs], MsgTypeStr, Index) -> - [StructName | _NewStructList] = Struct, - case Structs == [] of - true -> - make_protocal_msg_type(Structs, MsgTypeStr ++ " [\"msg_" ++ atom_to_list(StructName) ++ "\"] = "++integer_to_list(Index)++"\n", Index+1); - false -> - make_protocal_msg_type(Structs, MsgTypeStr ++ " [\"msg_" ++ atom_to_list(StructName) ++ "\"] = "++integer_to_list(Index)++",\n", Index+1) - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%生成枚举类型%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -make_protocal_const(Ver) -> - "function get_proto_version() - - return "++integer_to_list(Ver)++"; -end\n". - -make_protocal_enum([], EnumStr) -> - EnumStr; -make_protocal_enum([Enum | Enums], EnumStr) -> - {EnumName , EnumItems} = Enum, - EnumStr1 = EnumStr ++ - string:to_lower(atom_to_list(EnumName)) ++ " = \n{\n" ++ - make_protocal_enum_item(EnumItems, 1, "") ++ "}\n", - make_protocal_enum(Enums, EnumStr1). - -make_protocal_enum_item([EnumItem | []], Index, EnumItemStr) -> - EnumItemStr ++ " [\"" ++ atom_to_list(EnumItem) ++ "\"] = "++integer_to_list(Index)++"\n"; -make_protocal_enum_item([EnumItem | EnumItems], Index, EnumItemStr) -> - EnumItemStr1 = EnumItemStr ++ " [\"" ++ atom_to_list(EnumItem) ++ "\"]= "++integer_to_list(Index)++",\n", - make_protocal_enum_item(EnumItems, Index + 1, EnumItemStr1). - -get_csharp_Var(Type)-> - TypeString = atom_to_list(Type), - case lists:keyfind(TypeString, 1, get_keyword_mapping()) of - {TypeString, CSharpTypeString}-> - CSharpTypeString; - _ -> - TypeString - end. -get_csharp_type(Type) -> - TypeString = atom_to_list(Type), - case lists:keyfind(TypeString, 1, get_cshapr_type_mapping()) of - {TypeString, CSharpTypeString}-> - CSharpTypeString; - _ -> - TypeString - end. - -get_cshapr_type_mapping()-> - [ - {"uint", "UInt"}, - {"int16", "Int16"}, - {"uint16", "UInt16"}, - {"int64", "Int64"}, - {"uint64", "uint64"}, - {"uchar", "char"} - ]. - -get_keyword_mapping() -> - [ - {"lock", "Lock"}, - {"params", "Params"} - ]. - -make_getmsgid(StructName)-> - " tb.getMsgID = function()\n" ++ - " " ++ - " return NetMsgType[\"msg_" ++ atom_to_list(StructName) ++ "\"]\n" ++ - " end\n". - -get_default_value(Type, DefaultValue) - when (Type == int orelse - Type == uint orelse - Type == uint64 orelse - Type == uint16 orelse - Type == int64 orelse - Type == short orelse - Type == int16) - andalso is_integer(DefaultValue)-> - integer_to_list(DefaultValue); -get_default_value(Type, DefaultValue) - when (Type == float orelse - Type == long orelse - Type == double orelse - Type == uint16 orelse - Type == int64 orelse - Type == int16) - andalso is_float(DefaultValue)-> - float_to_list(DefaultValue); -get_default_value(char, DefaultValue) - when is_list(DefaultValue)-> - "'" ++ DefaultValue ++ "'"; -get_default_value(string, DefaultValue) - when is_atom(DefaultValue)-> - get_default_value(string, atom_to_list(DefaultValue)); -get_default_value(string, DefaultValue) - when is_list(DefaultValue)-> - "\"" ++ DefaultValue ++ "\"". -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%测试函数%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -test() -> - %% test_make_protocal_encode_item(), - %% test_make_protocal_decode_item(), - %% test_make_protocal_encode(), - %% test_make_protocal_decode(). - start(). - -%% test_make_protocal_encode_item() -> -%% "\t\tbyteArray.write_uint16(result.size());\n\t\tfor(int i=0; i -%% "uint16 size = byteArray.read_uint16();\naccount.reserve(size);\nfor(int i=0; i -%% Result = make_protocal_encode([{array, string, account}, -%% {string, pwd}, -%% {player_data, data}, -%% {array, notify_login_result, result}], "", gen_common:get_type()), -%% io:format("~p~n", [Result]). -%% -%% test_make_protocal_decode() -> -%% Result = make_protocal_decode([{array, string, account}, -%% {string, pwd}, -%% {player_data, data}, -%% {array, notify_login_result, result}], "", gen_common:get_type()), -%% io:format("~p~n", [Result]). -%% -%% test_make_protocal_Variable() -> -%% Result = make_protocal_Variable([{array, string, account}, -%% {string, pwd}, -%% {player_data, data}, -%% {array, notify_login_result, result}], "", gen_common:get_type()), -%% io:format("~p~n", [Result]). diff --git a/test/protoMsg.lua b/test/protoMsg.lua new file mode 100644 index 0000000..5a48d22 --- /dev/null +++ b/test/protoMsg.lua @@ -0,0 +1,1853 @@ +function test() + local tb = {} + tb.msgId =1 + t.aa = "" + + tb.encode = function(byteArray) + byteArray.write_string(tb.aa) + return byteArray + end + + tb.decode = function(byteArray) + tb.aa = byteArray.read_string() + end + + tb.build = function(byteArray) + byteArray.write_uint16(1) + return tb.encode(byteArray) + end + + return tb +end + +function phoneNumber() + local tb = {} + tb.msgId =2 + t.number = {} + t.type = 0 + + tb.encode = function(byteArray) + if tb.number and next(tb.number) then + byteArray.write_uint8(1) + tb.number.encode(byteArray) + else + byteArray.write_uint8(0) + end + byteArray.write_int32(tb.type) + return byteArray + end + + tb.decode = function(byteArray) + local isNilnumber = byteArray.read_uint8() + if isNilnumber > 0 then + tb.number = test() + tb.number.decode(byteArray) + else + tb.number = {} + end + tb.type = byteArray.read_int32() + end + + tb.build = function(byteArray) + byteArray.write_uint16(2) + return tb.encode(byteArray) + end + + return tb +end + +function person() + local tb = {} + tb.msgId =3 + t.name = "" + t.id = 0 + t.email = "" + t.phone = {} + + tb.encode = function(byteArray) + byteArray.write_string(tb.name) + byteArray.write_int32(tb.id) + byteArray.write_string(tb.email) + byteArray.write_uint16(#(tb.phone)) + for k, v in pairs(tb.phone) do + byteArray = v.encode(byteArray) + end + return byteArray + end + + tb.decode = function(byteArray) + tb.name = byteArray.read_string() + tb.id = byteArray.read_int32() + tb.email = byteArray.read_string() + local cntOfphone = byteArray.read_uint16() + tb.phone = {} + for i = 1, cntOfphone do + local temp = phoneNumber() + temp.decode(byteArray) + table.insert(tb.phone, temp) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(3) + return tb.encode(byteArray) + end + + return tb +end + +function addressBook() + local tb = {} + tb.msgId =4 + t.person = {} + t.other = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.person)) + for k, v in pairs(tb.person) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.other)) + for k, v in pairs(tb.other) do + byteArray = v.encode(byteArray) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfperson = byteArray.read_uint16() + tb.person = {} + for i = 1, cntOfperson do + local temp = person() + temp.decode(byteArray) + table.insert(tb.person, temp) + end + local cntOfother = byteArray.read_uint16() + tb.other = {} + for i = 1, cntOfother do + local temp = person() + temp.decode(byteArray) + table.insert(tb.other, temp) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(4) + return tb.encode(byteArray) + end + + return tb +end + +function union() + local tb = {} + tb.msgId =5 + t.test = "" + t.type = 0 + + tb.encode = function(byteArray) + byteArray.write_string(tb.test) + byteArray.write_int32(tb.type) + return byteArray + end + + tb.decode = function(byteArray) + tb.test = byteArray.read_string() + tb.type = byteArray.read_int32() + end + + tb.build = function(byteArray) + byteArray.write_uint16(5) + return tb.encode(byteArray) + end + + return tb +end + +function tbool() + local tb = {} + tb.msgId =6 + t.bool = false + + tb.encode = function(byteArray) + byteArray.write_bool(tb.bool) + return byteArray + end + + tb.decode = function(byteArray) + tb.bool = byteArray.read_bool() + end + + tb.build = function(byteArray) + byteArray.write_uint16(6) + return tb.encode(byteArray) + end + + return tb +end + +function tint8() + local tb = {} + tb.msgId =7 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_int8(tb.int1) + byteArray.write_int8(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_int8() + tb.int2 = byteArray.read_int8() + end + + tb.build = function(byteArray) + byteArray.write_uint16(7) + return tb.encode(byteArray) + end + + return tb +end + +function tuint8() + local tb = {} + tb.msgId =8 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_uint8(tb.int1) + byteArray.write_uint8(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_uint8() + tb.int2 = byteArray.read_uint8() + end + + tb.build = function(byteArray) + byteArray.write_uint16(8) + return tb.encode(byteArray) + end + + return tb +end + +function tint16() + local tb = {} + tb.msgId =9 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_int16(tb.int1) + byteArray.write_int16(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_int16() + tb.int2 = byteArray.read_int16() + end + + tb.build = function(byteArray) + byteArray.write_uint16(9) + return tb.encode(byteArray) + end + + return tb +end + +function tuint16() + local tb = {} + tb.msgId =10 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_uint16(tb.int1) + byteArray.write_uint16(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_uint16() + tb.int2 = byteArray.read_uint16() + end + + tb.build = function(byteArray) + byteArray.write_uint16(10) + return tb.encode(byteArray) + end + + return tb +end + +function tint32() + local tb = {} + tb.msgId =11 + t.int1 = 0 + t.int2 = 0 + t.int3 = 0 + t.int4 = 0 + t.int5 = 0 + t.int6 = 0 + t.int7 = 0 + t.int8 = 0 + t.int9 = 0 + t.int10 = 0 + + tb.encode = function(byteArray) + byteArray.write_int32(tb.int1) + byteArray.write_int32(tb.int2) + byteArray.write_int32(tb.int3) + byteArray.write_int32(tb.int4) + byteArray.write_int32(tb.int5) + byteArray.write_int32(tb.int6) + byteArray.write_int32(tb.int7) + byteArray.write_int32(tb.int8) + byteArray.write_int32(tb.int9) + byteArray.write_int32(tb.int10) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_int32() + tb.int2 = byteArray.read_int32() + tb.int3 = byteArray.read_int32() + tb.int4 = byteArray.read_int32() + tb.int5 = byteArray.read_int32() + tb.int6 = byteArray.read_int32() + tb.int7 = byteArray.read_int32() + tb.int8 = byteArray.read_int32() + tb.int9 = byteArray.read_int32() + tb.int10 = byteArray.read_int32() + end + + tb.build = function(byteArray) + byteArray.write_uint16(11) + return tb.encode(byteArray) + end + + return tb +end + +function tuint32() + local tb = {} + tb.msgId =12 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_uint32(tb.int1) + byteArray.write_uint32(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_uint32() + tb.int2 = byteArray.read_uint32() + end + + tb.build = function(byteArray) + byteArray.write_uint16(12) + return tb.encode(byteArray) + end + + return tb +end + +function tint64() + local tb = {} + tb.msgId =13 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_int64(tb.int1) + byteArray.write_int64(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_int64() + tb.int2 = byteArray.read_int64() + end + + tb.build = function(byteArray) + byteArray.write_uint16(13) + return tb.encode(byteArray) + end + + return tb +end + +function tuint64() + local tb = {} + tb.msgId =14 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_uint64(tb.int1) + byteArray.write_uint64(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_uint64() + tb.int2 = byteArray.read_uint64() + end + + tb.build = function(byteArray) + byteArray.write_uint16(14) + return tb.encode(byteArray) + end + + return tb +end + +function tinteger() + local tb = {} + tb.msgId =15 + t.int1 = {} + t.int2 = {} + t.int3 = {} + t.int4 = {} + t.int5 = {} + t.int6 = {} + t.int7 = {} + t.int8 = {} + + tb.encode = function(byteArray) + if tb.int1 and next(tb.int1) then + byteArray.write_uint8(1) + tb.int1.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int2 and next(tb.int2) then + byteArray.write_uint8(1) + tb.int2.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int3 and next(tb.int3) then + byteArray.write_uint8(1) + tb.int3.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int4 and next(tb.int4) then + byteArray.write_uint8(1) + tb.int4.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int5 and next(tb.int5) then + byteArray.write_uint8(1) + tb.int5.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int6 and next(tb.int6) then + byteArray.write_uint8(1) + tb.int6.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int7 and next(tb.int7) then + byteArray.write_uint8(1) + tb.int7.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int8 and next(tb.int8) then + byteArray.write_uint8(1) + tb.int8.encode(byteArray) + else + byteArray.write_uint8(0) + end + return byteArray + end + + tb.decode = function(byteArray) + local isNilint1 = byteArray.read_uint8() + if isNilint1 > 0 then + tb.int1 = integer() + tb.int1.decode(byteArray) + else + tb.int1 = {} + end + local isNilint2 = byteArray.read_uint8() + if isNilint2 > 0 then + tb.int2 = integer() + tb.int2.decode(byteArray) + else + tb.int2 = {} + end + local isNilint3 = byteArray.read_uint8() + if isNilint3 > 0 then + tb.int3 = integer() + tb.int3.decode(byteArray) + else + tb.int3 = {} + end + local isNilint4 = byteArray.read_uint8() + if isNilint4 > 0 then + tb.int4 = integer() + tb.int4.decode(byteArray) + else + tb.int4 = {} + end + local isNilint5 = byteArray.read_uint8() + if isNilint5 > 0 then + tb.int5 = integer() + tb.int5.decode(byteArray) + else + tb.int5 = {} + end + local isNilint6 = byteArray.read_uint8() + if isNilint6 > 0 then + tb.int6 = integer() + tb.int6.decode(byteArray) + else + tb.int6 = {} + end + local isNilint7 = byteArray.read_uint8() + if isNilint7 > 0 then + tb.int7 = integer() + tb.int7.decode(byteArray) + else + tb.int7 = {} + end + local isNilint8 = byteArray.read_uint8() + if isNilint8 > 0 then + tb.int8 = integer() + tb.int8.decode(byteArray) + else + tb.int8 = {} + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(15) + return tb.encode(byteArray) + end + + return tb +end + +function tnumber() + local tb = {} + tb.msgId =16 + t.int1 = {} + t.int2 = {} + t.int3 = {} + t.int4 = {} + t.int5 = {} + t.int6 = {} + t.int7 = {} + t.int8 = {} + t.float1 = {} + t.float2 = {} + + tb.encode = function(byteArray) + if tb.int1 and next(tb.int1) then + byteArray.write_uint8(1) + tb.int1.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int2 and next(tb.int2) then + byteArray.write_uint8(1) + tb.int2.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int3 and next(tb.int3) then + byteArray.write_uint8(1) + tb.int3.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int4 and next(tb.int4) then + byteArray.write_uint8(1) + tb.int4.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int5 and next(tb.int5) then + byteArray.write_uint8(1) + tb.int5.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int6 and next(tb.int6) then + byteArray.write_uint8(1) + tb.int6.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int7 and next(tb.int7) then + byteArray.write_uint8(1) + tb.int7.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.int8 and next(tb.int8) then + byteArray.write_uint8(1) + tb.int8.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.float1 and next(tb.float1) then + byteArray.write_uint8(1) + tb.float1.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.float2 and next(tb.float2) then + byteArray.write_uint8(1) + tb.float2.encode(byteArray) + else + byteArray.write_uint8(0) + end + return byteArray + end + + tb.decode = function(byteArray) + local isNilint1 = byteArray.read_uint8() + if isNilint1 > 0 then + tb.int1 = number() + tb.int1.decode(byteArray) + else + tb.int1 = {} + end + local isNilint2 = byteArray.read_uint8() + if isNilint2 > 0 then + tb.int2 = number() + tb.int2.decode(byteArray) + else + tb.int2 = {} + end + local isNilint3 = byteArray.read_uint8() + if isNilint3 > 0 then + tb.int3 = number() + tb.int3.decode(byteArray) + else + tb.int3 = {} + end + local isNilint4 = byteArray.read_uint8() + if isNilint4 > 0 then + tb.int4 = number() + tb.int4.decode(byteArray) + else + tb.int4 = {} + end + local isNilint5 = byteArray.read_uint8() + if isNilint5 > 0 then + tb.int5 = number() + tb.int5.decode(byteArray) + else + tb.int5 = {} + end + local isNilint6 = byteArray.read_uint8() + if isNilint6 > 0 then + tb.int6 = number() + tb.int6.decode(byteArray) + else + tb.int6 = {} + end + local isNilint7 = byteArray.read_uint8() + if isNilint7 > 0 then + tb.int7 = number() + tb.int7.decode(byteArray) + else + tb.int7 = {} + end + local isNilint8 = byteArray.read_uint8() + if isNilint8 > 0 then + tb.int8 = number() + tb.int8.decode(byteArray) + else + tb.int8 = {} + end + local isNilfloat1 = byteArray.read_uint8() + if isNilfloat1 > 0 then + tb.float1 = number() + tb.float1.decode(byteArray) + else + tb.float1 = {} + end + local isNilfloat2 = byteArray.read_uint8() + if isNilfloat2 > 0 then + tb.float2 = number() + tb.float2.decode(byteArray) + else + tb.float2 = {} + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(16) + return tb.encode(byteArray) + end + + return tb +end + +function tfloat() + local tb = {} + tb.msgId =17 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_float(tb.int1) + byteArray.write_float(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_float() + tb.int2 = byteArray.read_float() + end + + tb.build = function(byteArray) + byteArray.write_uint16(17) + return tb.encode(byteArray) + end + + return tb +end + +function tdouble() + local tb = {} + tb.msgId =18 + t.int1 = 0 + t.int2 = 0 + + tb.encode = function(byteArray) + byteArray.write_double(tb.int1) + byteArray.write_double(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_double() + tb.int2 = byteArray.read_double() + end + + tb.build = function(byteArray) + byteArray.write_uint16(18) + return tb.encode(byteArray) + end + + return tb +end + +function tstring() + local tb = {} + tb.msgId =19 + t.int1 = "" + t.int2 = "" + + tb.encode = function(byteArray) + byteArray.write_string(tb.int1) + byteArray.write_string(tb.int2) + return byteArray + end + + tb.decode = function(byteArray) + tb.int1 = byteArray.read_string() + tb.int2 = byteArray.read_string() + end + + tb.build = function(byteArray) + byteArray.write_uint16(19) + return tb.encode(byteArray) + end + + return tb +end + +function tlistbool() + local tb = {} + tb.msgId =20 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_bool(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_bool()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(20) + return tb.encode(byteArray) + end + + return tb +end + +function tlistint8() + local tb = {} + tb.msgId =21 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_int8(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_int8()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(21) + return tb.encode(byteArray) + end + + return tb +end + +function tlistuint8() + local tb = {} + tb.msgId =22 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_uint8(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_uint8()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(22) + return tb.encode(byteArray) + end + + return tb +end + +function tlistint16() + local tb = {} + tb.msgId =23 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_int16(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_int16()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(23) + return tb.encode(byteArray) + end + + return tb +end + +function tlistuint16() + local tb = {} + tb.msgId =24 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_uint16(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_uint16()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(24) + return tb.encode(byteArray) + end + + return tb +end + +function tlistint32() + local tb = {} + tb.msgId =25 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_int32(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_int32()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(25) + return tb.encode(byteArray) + end + + return tb +end + +function tlistuint32() + local tb = {} + tb.msgId =26 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_uint32(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_uint32()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(26) + return tb.encode(byteArray) + end + + return tb +end + +function tlistint64() + local tb = {} + tb.msgId =27 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_int64(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_int64()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(27) + return tb.encode(byteArray) + end + + return tb +end + +function tlistuint64() + local tb = {} + tb.msgId =28 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_uint64(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_uint64()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(28) + return tb.encode(byteArray) + end + + return tb +end + +function tlistinteger() + local tb = {} + tb.msgId =29 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs(tb.int1) do + byteArray = v.encode(byteArray) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + local temp = integer() + temp.decode(byteArray) + table.insert(tb.int1, temp) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(29) + return tb.encode(byteArray) + end + + return tb +end + +function tlistnumber() + local tb = {} + tb.msgId =30 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs(tb.int1) do + byteArray = v.encode(byteArray) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + local temp = number() + temp.decode(byteArray) + table.insert(tb.int1, temp) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(30) + return tb.encode(byteArray) + end + + return tb +end + +function tlistfloat() + local tb = {} + tb.msgId =31 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_float(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_float()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(31) + return tb.encode(byteArray) + end + + return tb +end + +function tlistdouble() + local tb = {} + tb.msgId =32 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_double(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_double()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(32) + return tb.encode(byteArray) + end + + return tb +end + +function tliststring() + local tb = {} + tb.msgId =33 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs (tb.int1) do + byteArray.write_string(v) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + table.insert(tb.int1, byteArray.read_string()) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(33) + return tb.encode(byteArray) + end + + return tb +end + +function tlistunion() + local tb = {} + tb.msgId =34 + t.int1 = {} + + tb.encode = function(byteArray) + byteArray.write_uint16(#(tb.int1)) + for k, v in pairs(tb.int1) do + byteArray = v.encode(byteArray) + end + return byteArray + end + + tb.decode = function(byteArray) + local cntOfint1 = byteArray.read_uint16() + tb.int1 = {} + for i = 1, cntOfint1 do + local temp = union() + temp.decode(byteArray) + table.insert(tb.int1, temp) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(34) + return tb.encode(byteArray) + end + + return tb +end + +function allType() + local tb = {} + tb.msgId =35 + t.bool = false + t.int8 = 0 + t.uint8 = 0 + t.int16 = 0 + t.uint16 = 0 + t.int32 = 0 + t.uint32 = 0 + t.int64 = 0 + t.uint64 = 0 + t.inte8 = {} + t.uinte8 = {} + t.inte16 = {} + t.uinte16 = {} + t.inte32 = {} + t.uinte32 = {} + t.inte64 = {} + t.uinte64 = {} + t.num8 = {} + t.unum8 = {} + t.num16 = {} + t.unum16 = {} + t.num32 = {} + t.unum32 = {} + t.num64 = {} + t.unum64 = {} + t.numfloat = {} + t.numdouble = {} + t.float = 0 + t.double = 0 + t.string1 = "" + t.string2 = "" + t.union = {} + t.lbool = {} + t.lint8 = {} + t.luint8 = {} + t.lint16 = {} + t.luint16 = {} + t.lint32 = {} + t.luint32 = {} + t.lint64 = {} + t.luint64 = {} + t.linte8 = {} + t.linte16 = {} + t.linte32 = {} + t.linte64 = {} + t.lnum8 = {} + t.lnum16 = {} + t.lnum32 = {} + t.lnum64 = {} + t.lnfloat32 = {} + t.lnfloat64 = {} + t.lfloat = {} + t.ldouble = {} + t.lstring = {} + t.lunion = {} + + tb.encode = function(byteArray) + byteArray.write_bool(tb.bool) + byteArray.write_int8(tb.int8) + byteArray.write_uint8(tb.uint8) + byteArray.write_int16(tb.int16) + byteArray.write_uint16(tb.uint16) + byteArray.write_int32(tb.int32) + byteArray.write_uint32(tb.uint32) + byteArray.write_int64(tb.int64) + byteArray.write_uint64(tb.uint64) + if tb.inte8 and next(tb.inte8) then + byteArray.write_uint8(1) + tb.inte8.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.uinte8 and next(tb.uinte8) then + byteArray.write_uint8(1) + tb.uinte8.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.inte16 and next(tb.inte16) then + byteArray.write_uint8(1) + tb.inte16.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.uinte16 and next(tb.uinte16) then + byteArray.write_uint8(1) + tb.uinte16.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.inte32 and next(tb.inte32) then + byteArray.write_uint8(1) + tb.inte32.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.uinte32 and next(tb.uinte32) then + byteArray.write_uint8(1) + tb.uinte32.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.inte64 and next(tb.inte64) then + byteArray.write_uint8(1) + tb.inte64.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.uinte64 and next(tb.uinte64) then + byteArray.write_uint8(1) + tb.uinte64.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.num8 and next(tb.num8) then + byteArray.write_uint8(1) + tb.num8.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.unum8 and next(tb.unum8) then + byteArray.write_uint8(1) + tb.unum8.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.num16 and next(tb.num16) then + byteArray.write_uint8(1) + tb.num16.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.unum16 and next(tb.unum16) then + byteArray.write_uint8(1) + tb.unum16.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.num32 and next(tb.num32) then + byteArray.write_uint8(1) + tb.num32.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.unum32 and next(tb.unum32) then + byteArray.write_uint8(1) + tb.unum32.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.num64 and next(tb.num64) then + byteArray.write_uint8(1) + tb.num64.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.unum64 and next(tb.unum64) then + byteArray.write_uint8(1) + tb.unum64.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.numfloat and next(tb.numfloat) then + byteArray.write_uint8(1) + tb.numfloat.encode(byteArray) + else + byteArray.write_uint8(0) + end + if tb.numdouble and next(tb.numdouble) then + byteArray.write_uint8(1) + tb.numdouble.encode(byteArray) + else + byteArray.write_uint8(0) + end + byteArray.write_float(tb.float) + byteArray.write_double(tb.double) + byteArray.write_string(tb.string1) + byteArray.write_string(tb.string2) + if tb.union and next(tb.union) then + byteArray.write_uint8(1) + tb.union.encode(byteArray) + else + byteArray.write_uint8(0) + end + byteArray.write_uint16(#(tb.lbool)) + for k, v in pairs (tb.lbool) do + byteArray.write_bool(v) + end + byteArray.write_uint16(#(tb.lint8)) + for k, v in pairs (tb.lint8) do + byteArray.write_int8(v) + end + byteArray.write_uint16(#(tb.luint8)) + for k, v in pairs (tb.luint8) do + byteArray.write_uint8(v) + end + byteArray.write_uint16(#(tb.lint16)) + for k, v in pairs (tb.lint16) do + byteArray.write_int16(v) + end + byteArray.write_uint16(#(tb.luint16)) + for k, v in pairs (tb.luint16) do + byteArray.write_uint16(v) + end + byteArray.write_uint16(#(tb.lint32)) + for k, v in pairs (tb.lint32) do + byteArray.write_int32(v) + end + byteArray.write_uint16(#(tb.luint32)) + for k, v in pairs (tb.luint32) do + byteArray.write_uint32(v) + end + byteArray.write_uint16(#(tb.lint64)) + for k, v in pairs (tb.lint64) do + byteArray.write_int64(v) + end + byteArray.write_uint16(#(tb.luint64)) + for k, v in pairs (tb.luint64) do + byteArray.write_uint64(v) + end + byteArray.write_uint16(#(tb.linte8)) + for k, v in pairs(tb.linte8) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.linte16)) + for k, v in pairs(tb.linte16) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.linte32)) + for k, v in pairs(tb.linte32) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.linte64)) + for k, v in pairs(tb.linte64) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.lnum8)) + for k, v in pairs(tb.lnum8) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.lnum16)) + for k, v in pairs(tb.lnum16) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.lnum32)) + for k, v in pairs(tb.lnum32) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.lnum64)) + for k, v in pairs(tb.lnum64) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.lnfloat32)) + for k, v in pairs(tb.lnfloat32) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.lnfloat64)) + for k, v in pairs(tb.lnfloat64) do + byteArray = v.encode(byteArray) + end + byteArray.write_uint16(#(tb.lfloat)) + for k, v in pairs (tb.lfloat) do + byteArray.write_float(v) + end + byteArray.write_uint16(#(tb.ldouble)) + for k, v in pairs (tb.ldouble) do + byteArray.write_double(v) + end + byteArray.write_uint16(#(tb.lstring)) + for k, v in pairs (tb.lstring) do + byteArray.write_string(v) + end + byteArray.write_uint16(#(tb.lunion)) + for k, v in pairs(tb.lunion) do + byteArray = v.encode(byteArray) + end + return byteArray + end + + tb.decode = function(byteArray) + tb.bool = byteArray.read_bool() + tb.int8 = byteArray.read_int8() + tb.uint8 = byteArray.read_uint8() + tb.int16 = byteArray.read_int16() + tb.uint16 = byteArray.read_uint16() + tb.int32 = byteArray.read_int32() + tb.uint32 = byteArray.read_uint32() + tb.int64 = byteArray.read_int64() + tb.uint64 = byteArray.read_uint64() + local isNilinte8 = byteArray.read_uint8() + if isNilinte8 > 0 then + tb.inte8 = integer() + tb.inte8.decode(byteArray) + else + tb.inte8 = {} + end + local isNiluinte8 = byteArray.read_uint8() + if isNiluinte8 > 0 then + tb.uinte8 = integer() + tb.uinte8.decode(byteArray) + else + tb.uinte8 = {} + end + local isNilinte16 = byteArray.read_uint8() + if isNilinte16 > 0 then + tb.inte16 = integer() + tb.inte16.decode(byteArray) + else + tb.inte16 = {} + end + local isNiluinte16 = byteArray.read_uint8() + if isNiluinte16 > 0 then + tb.uinte16 = integer() + tb.uinte16.decode(byteArray) + else + tb.uinte16 = {} + end + local isNilinte32 = byteArray.read_uint8() + if isNilinte32 > 0 then + tb.inte32 = integer() + tb.inte32.decode(byteArray) + else + tb.inte32 = {} + end + local isNiluinte32 = byteArray.read_uint8() + if isNiluinte32 > 0 then + tb.uinte32 = integer() + tb.uinte32.decode(byteArray) + else + tb.uinte32 = {} + end + local isNilinte64 = byteArray.read_uint8() + if isNilinte64 > 0 then + tb.inte64 = integer() + tb.inte64.decode(byteArray) + else + tb.inte64 = {} + end + local isNiluinte64 = byteArray.read_uint8() + if isNiluinte64 > 0 then + tb.uinte64 = integer() + tb.uinte64.decode(byteArray) + else + tb.uinte64 = {} + end + local isNilnum8 = byteArray.read_uint8() + if isNilnum8 > 0 then + tb.num8 = number() + tb.num8.decode(byteArray) + else + tb.num8 = {} + end + local isNilunum8 = byteArray.read_uint8() + if isNilunum8 > 0 then + tb.unum8 = number() + tb.unum8.decode(byteArray) + else + tb.unum8 = {} + end + local isNilnum16 = byteArray.read_uint8() + if isNilnum16 > 0 then + tb.num16 = number() + tb.num16.decode(byteArray) + else + tb.num16 = {} + end + local isNilunum16 = byteArray.read_uint8() + if isNilunum16 > 0 then + tb.unum16 = number() + tb.unum16.decode(byteArray) + else + tb.unum16 = {} + end + local isNilnum32 = byteArray.read_uint8() + if isNilnum32 > 0 then + tb.num32 = number() + tb.num32.decode(byteArray) + else + tb.num32 = {} + end + local isNilunum32 = byteArray.read_uint8() + if isNilunum32 > 0 then + tb.unum32 = number() + tb.unum32.decode(byteArray) + else + tb.unum32 = {} + end + local isNilnum64 = byteArray.read_uint8() + if isNilnum64 > 0 then + tb.num64 = number() + tb.num64.decode(byteArray) + else + tb.num64 = {} + end + local isNilunum64 = byteArray.read_uint8() + if isNilunum64 > 0 then + tb.unum64 = number() + tb.unum64.decode(byteArray) + else + tb.unum64 = {} + end + local isNilnumfloat = byteArray.read_uint8() + if isNilnumfloat > 0 then + tb.numfloat = number() + tb.numfloat.decode(byteArray) + else + tb.numfloat = {} + end + local isNilnumdouble = byteArray.read_uint8() + if isNilnumdouble > 0 then + tb.numdouble = number() + tb.numdouble.decode(byteArray) + else + tb.numdouble = {} + end + tb.float = byteArray.read_float() + tb.double = byteArray.read_double() + tb.string1 = byteArray.read_string() + tb.string2 = byteArray.read_string() + local isNilunion = byteArray.read_uint8() + if isNilunion > 0 then + tb.union = union() + tb.union.decode(byteArray) + else + tb.union = {} + end + local cntOflbool = byteArray.read_uint16() + tb.lbool = {} + for i = 1, cntOflbool do + table.insert(tb.lbool, byteArray.read_bool()) + end + local cntOflint8 = byteArray.read_uint16() + tb.lint8 = {} + for i = 1, cntOflint8 do + table.insert(tb.lint8, byteArray.read_int8()) + end + local cntOfluint8 = byteArray.read_uint16() + tb.luint8 = {} + for i = 1, cntOfluint8 do + table.insert(tb.luint8, byteArray.read_uint8()) + end + local cntOflint16 = byteArray.read_uint16() + tb.lint16 = {} + for i = 1, cntOflint16 do + table.insert(tb.lint16, byteArray.read_int16()) + end + local cntOfluint16 = byteArray.read_uint16() + tb.luint16 = {} + for i = 1, cntOfluint16 do + table.insert(tb.luint16, byteArray.read_uint16()) + end + local cntOflint32 = byteArray.read_uint16() + tb.lint32 = {} + for i = 1, cntOflint32 do + table.insert(tb.lint32, byteArray.read_int32()) + end + local cntOfluint32 = byteArray.read_uint16() + tb.luint32 = {} + for i = 1, cntOfluint32 do + table.insert(tb.luint32, byteArray.read_uint32()) + end + local cntOflint64 = byteArray.read_uint16() + tb.lint64 = {} + for i = 1, cntOflint64 do + table.insert(tb.lint64, byteArray.read_int64()) + end + local cntOfluint64 = byteArray.read_uint16() + tb.luint64 = {} + for i = 1, cntOfluint64 do + table.insert(tb.luint64, byteArray.read_uint64()) + end + local cntOflinte8 = byteArray.read_uint16() + tb.linte8 = {} + for i = 1, cntOflinte8 do + local temp = integer() + temp.decode(byteArray) + table.insert(tb.linte8, temp) + end + local cntOflinte16 = byteArray.read_uint16() + tb.linte16 = {} + for i = 1, cntOflinte16 do + local temp = integer() + temp.decode(byteArray) + table.insert(tb.linte16, temp) + end + local cntOflinte32 = byteArray.read_uint16() + tb.linte32 = {} + for i = 1, cntOflinte32 do + local temp = integer() + temp.decode(byteArray) + table.insert(tb.linte32, temp) + end + local cntOflinte64 = byteArray.read_uint16() + tb.linte64 = {} + for i = 1, cntOflinte64 do + local temp = integer() + temp.decode(byteArray) + table.insert(tb.linte64, temp) + end + local cntOflnum8 = byteArray.read_uint16() + tb.lnum8 = {} + for i = 1, cntOflnum8 do + local temp = number() + temp.decode(byteArray) + table.insert(tb.lnum8, temp) + end + local cntOflnum16 = byteArray.read_uint16() + tb.lnum16 = {} + for i = 1, cntOflnum16 do + local temp = number() + temp.decode(byteArray) + table.insert(tb.lnum16, temp) + end + local cntOflnum32 = byteArray.read_uint16() + tb.lnum32 = {} + for i = 1, cntOflnum32 do + local temp = number() + temp.decode(byteArray) + table.insert(tb.lnum32, temp) + end + local cntOflnum64 = byteArray.read_uint16() + tb.lnum64 = {} + for i = 1, cntOflnum64 do + local temp = number() + temp.decode(byteArray) + table.insert(tb.lnum64, temp) + end + local cntOflnfloat32 = byteArray.read_uint16() + tb.lnfloat32 = {} + for i = 1, cntOflnfloat32 do + local temp = number() + temp.decode(byteArray) + table.insert(tb.lnfloat32, temp) + end + local cntOflnfloat64 = byteArray.read_uint16() + tb.lnfloat64 = {} + for i = 1, cntOflnfloat64 do + local temp = number() + temp.decode(byteArray) + table.insert(tb.lnfloat64, temp) + end + local cntOflfloat = byteArray.read_uint16() + tb.lfloat = {} + for i = 1, cntOflfloat do + table.insert(tb.lfloat, byteArray.read_float()) + end + local cntOfldouble = byteArray.read_uint16() + tb.ldouble = {} + for i = 1, cntOfldouble do + table.insert(tb.ldouble, byteArray.read_double()) + end + local cntOflstring = byteArray.read_uint16() + tb.lstring = {} + for i = 1, cntOflstring do + table.insert(tb.lstring, byteArray.read_string()) + end + local cntOflunion = byteArray.read_uint16() + tb.lunion = {} + for i = 1, cntOflunion do + local temp = union() + temp.decode(byteArray) + table.insert(tb.lunion, temp) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(35) + return tb.encode(byteArray) + end + + return tb +end + +function testnull() + local tb = {} + tb.msgId =36 + + tb.encode = function(byteArray) + return byteArray + end + + tb.decode = function(byteArray) + end + + tb.build = function(byteArray) + byteArray.write_uint16(36) + return tb.encode(byteArray) + end + + return tb +end + +function person1() + local tb = {} + tb.msgId =1001 + t.name = "" + t.id = 0 + t.email = "" + t.phone = {} + + tb.encode = function(byteArray) + byteArray.write_string(tb.name) + byteArray.write_int32(tb.id) + byteArray.write_string(tb.email) + byteArray.write_uint16(#(tb.phone)) + for k, v in pairs(tb.phone) do + byteArray = v.encode(byteArray) + end + return byteArray + end + + tb.decode = function(byteArray) + tb.name = byteArray.read_string() + tb.id = byteArray.read_int32() + tb.email = byteArray.read_string() + local cntOfphone = byteArray.read_uint16() + tb.phone = {} + for i = 1, cntOfphone do + local temp = phoneNumber() + temp.decode(byteArray) + table.insert(tb.phone, temp) + end + end + + tb.build = function(byteArray) + byteArray.write_uint16(1001) + return tb.encode(byteArray) + end + + return tb +end + diff --git a/test/protoName.lua b/test/protoName.lua new file mode 100644 index 0000000..6fa1aab --- /dev/null +++ b/test/protoName.lua @@ -0,0 +1,40 @@ +ProtoMsgName = +{ + [1] = "test", + [2] = "phoneNumber", + [3] = "person", + [4] = "addressBook", + [5] = "union", + [6] = "tbool", + [7] = "tint8", + [8] = "tuint8", + [9] = "tint16", + [10] = "tuint16", + [11] = "tint32", + [12] = "tuint32", + [13] = "tint64", + [14] = "tuint64", + [15] = "tinteger", + [16] = "tnumber", + [17] = "tfloat", + [18] = "tdouble", + [19] = "tstring", + [20] = "tlistbool", + [21] = "tlistint8", + [22] = "tlistuint8", + [23] = "tlistint16", + [24] = "tlistuint16", + [25] = "tlistint32", + [26] = "tlistuint32", + [27] = "tlistint64", + [28] = "tlistuint64", + [29] = "tlistinteger", + [30] = "tlistnumber", + [31] = "tlistfloat", + [32] = "tlistdouble", + [33] = "tliststring", + [34] = "tlistunion", + [35] = "allType", + [36] = "testnull", + [1001] = "person1", +} \ No newline at end of file