diff --git a/proto/0_test.mpdf b/proto/0_test.mpdf index 114bb3d..bd44970 100644 --- a/proto/0_test.mpdf +++ b/proto/0_test.mpdf @@ -239,3 +239,6 @@ allType{ list[string] lstring; list[union] lunion; } + +testnull { +} diff --git a/src/genProto.erl b/src/genProto.erl index 388c4a1..a04dc94 100644 --- a/src/genProto.erl +++ b/src/genProto.erl @@ -70,9 +70,9 @@ convertDir(ProtoDir, HrlDir, ErlDir) -> ErrCodeList = erlang:get(pd_errlist), SortedSProtoList = lists:sort(fun({_Name1, MessageId1, _FieldList1}, {_Name2, MessageId2, _FieldList2}) -> - MessageId1 > MessageId2 end, SProtoList), + MessageId1 < MessageId2 end, SProtoList), SortedErrList = lists:sort(fun({_ErrName1, ErrCodeId1, _Desc1}, {_ErrName2, ErrCodeId2, _Desc2}) -> - ErrCodeId1 > ErrCodeId2 end, ErrCodeList), + ErrCodeId1 < ErrCodeId2 end, ErrCodeList), gErlGen:genErl(SortedSProtoList, SortedErrList, HrlDir, ErlDir). %% 如果有其他语言请在这里添加入口函数 \ No newline at end of file diff --git a/src/writeErl/gErlField.erl b/src/writeErl/gErlField.erl index 2a9f920..2a17fb3 100644 --- a/src/writeErl/gErlField.erl +++ b/src/writeErl/gErlField.erl @@ -3,89 +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(TypeList, [ - "bool" - , "int8" - , "uint8" - , "int16" - , "uint16" - , "int32" - , "uint32" - , "int64" - , "uint64" - , "integer" - , "number" - , "float" - , "double" - , "string" + <<"bool">> + , <<"int8">> + , <<"uint8">> + , <<"int16">> + , <<"uint16">> + , <<"int32">> + , <<"uint32">> + , <<"int64">> + , <<"uint64">> + , <<"integer">> + , <<"number">> + , <<"float">> + , <<"double">> + , <<"string">> ]). -define(TypeValue, [ - {"bool", "false", "boolean()"} - , {"int8", "0", "int8()"} - , {"uint8", "0", "uint8()"} - , {"int16", "0", "int16()"} - , {"uint16", "0", "uint16()"} - , {"int32", "0", "int32()"} - , {"uint32", "0", "uint32()"} - , {"int64", "0", "int64()"} - , {"uint64", "0", "uint64()"} - , {"integer", "0", "integer()"} - , {"number", "0", "number()"} - , {"float", "0.0", "float()"} - , {"double", "0.0", "double()"} - , {"string", "\"\"", "string()"} + {<<"bool">>, <<"false">>, <<"boolean()">>} + , {<<"int8">>, <<"0">>, <<"int8()">>} + , {<<"uint8">>, <<"0">>, <<"uint8()">>} + , {<<"int16">>, <<"0">>, <<"int16()">>} + , {<<"uint16">>, <<"0">>, <<"uint16()">>} + , {<<"int32">>, <<"0">>, <<"int32()">>} + , {<<"uint32">>, <<"0">>, <<"uint32()">>} + , {<<"int64">>, <<"0">>, <<"int64()">>} + , {<<"uint64">>, <<"0">>, <<"uint64()">>} + , {<<"integer">>, <<"0">>, <<"integer()">>} + , {<<"number">>, <<"0">>, <<"number()">>} + , {<<"float">>, <<"0.0">>, <<"float()">>} + , {<<"double">>, <<"0.0">>, <<"double()">>} + , {<<"string">>, <<"\"\"">>, <<"string()">>} ]). builtRecStr({TypeStr, NameStr}) -> case lists:keyfind(TypeStr, 1, ?TypeValue) of {TypeStr, DefValueStr, DefTypeStr} -> - NameStr ++ " = " ++ DefValueStr ++ " :: " ++ DefTypeStr ++ "\n"; + <>; _ -> case TypeStr of - "list[" ++ LeftStr -> - [SubTypeStr | _] = re:split(LeftStr, "\\]", [{return, list}]), + <<"list[", LeftStr/binary>> -> + [SubTypeStr | _] = re:split(LeftStr, <<"\\]">>, [{return, binary}]), case lists:keyfind(SubTypeStr, 1, ?TypeValue) of {SubTypeStr, _DefSubValueStr, DefSubTypeStr} -> - NameStr ++ " = [] " ++ ":: [" ++ DefSubTypeStr ++ "]\n"; + <>; _ -> - NameStr ++ " = [] " ++ ":: [#" ++ SubTypeStr ++ "{}]\n" + <> end; _ -> - NameStr ++ " = undefined " ++ ":: #" ++ TypeStr ++ "{}\n" + <> end end. builtPackStr(TypeStr) -> case lists:member(TypeStr, ?TypeList) of true -> - "?" ++ TypeStr ++ "("; + <<"?", TypeStr/binary, "(">>; _ -> case TypeStr of - "list[" ++ LeftStr -> - [SubTypeStr | _] = re:split(LeftStr, "\\]", [{return, list}]), + <<"list[", LeftStr/binary>> -> + [SubTypeStr | _] = re:split(LeftStr, <<"\\]">>, [{return, binary}]), SubStr = case lists:member(SubTypeStr, ?TypeList) of true -> SubTypeStr; _ -> - "record" + <<"record">> end, - "?list_" ++ SubStr ++ "("; + <<"?list_", SubStr/binary, "(">>; _ -> - "?record(" + <<"?record(">> end end. diff --git a/src/writeErl/gErlGen.erl b/src/writeErl/gErlGen.erl index 11dbbba..004a1e8 100644 --- a/src/writeErl/gErlGen.erl +++ b/src/writeErl/gErlGen.erl @@ -6,18 +6,18 @@ ]). protoHrlHeader() -> - "-opaque int8() :: -128..127. - -opaque int16() :: -32768..32767. - -opaque int32() :: -2147483648..2147483647. - -opaque int64() :: -9223372036854775808..9223372036854775807. - -opaque uint8() :: 0..255. - -opaque uint16() :: 0..65536. - -opaque uint32() :: 0..4294967295. - -opaque uint64() :: 0..18446744073709551615. - -opaque double() :: float().\n\n". +<<"-opaque int8() :: -128..127. +-opaque int16() :: -32768..32767. +-opaque int32() :: -2147483648..2147483647. +-opaque int64() :: -9223372036854775808..9223372036854775807. +-opaque uint8() :: 0..255. +-opaque uint16() :: 0..65536. +-opaque uint32() :: 0..4294967295. +-opaque uint64() :: 0..18446744073709551615. +-opaque double() :: float().\n\n">>. protoErlHeader() -> -"-module(protoMsg).\n\n +<<"-module(protoMsg).\n\n -compile([nowarn_unused_vars]). -export([encodeIol/1, encodeBin/1, encodeIol/2, subEncode/1, subEncode/2, decode/1, decodeBin/2]). @@ -174,65 +174,68 @@ encodeBin(RecMsg) -> erlang:iolist_to_binary(encodeIol(RecMsg)). subEncode(RecMsg) -> - subEncode(erlang:element(1, RecMsg), RecMsg).\n\n". + subEncode(erlang:element(1, RecMsg), RecMsg).\n\n">>. -genMsgHrl(FieldInfo, {Index, Len, AccList}) -> +genMsgHrl([], _Index, _Len, HrlBinStr) -> + HrlBinStr; +genMsgHrl([FieldInfo | FieldList], Index, Len, HrlBinStr) -> TemStr = case Index of - 1 -> - ""; + Len -> + <<"">>; _ -> - ", " + <<", ">> end, - RecStr = TemStr ++ gErlField:builtRecStr(FieldInfo) ++ (case Index == Len of true -> ""; _ -> "\t" end), - {Index - 1, Len, [RecStr | AccList]}. - -genErrCodeHrl({ErrName, ErrCodeId, ComDesc}, AccList) -> - Str = "-define(" ++ ErrName ++ ", " ++ integer_to_list(ErrCodeId) ++ ").\t\t%% " ++ ComDesc ++ "\n", - [Str | AccList]. + RecStr = < <<"">>; _ -> <<"\t">> end)/binary>>, + genMsgHrl(FieldList, Index - 1, Len, <>). + +spellHead([], _Index, HeadBinStr) -> + HeadBinStr; +spellHead([_FieldInfo | FieldList], Index, HeadBinStr) -> + spellHead(FieldList, Index + 1, <>). + +spellBody([], _Index, BodyBinStr) -> + BodyBinStr; +spellBody([{FieldType, _FieldName}], Index, BodyBinStr) -> + TemV = <<"V", (integer_to_binary(Index))/binary>>, + <>; +spellBody([{FieldType, _FieldName} | FieldList], Index, BodyBinStr) -> + TemV = <<"V", (integer_to_binary(Index))/binary>>, + NewBodyBinStr = <>, + spellBody(FieldList, Index + 1, NewBodyBinStr). + +spellErrCodeHrl([], ErrBinStr) -> + ErrBinStr; +spellErrCodeHrl([{ErrName, ErrCodeId, ComDesc} | SortedErrList], ErrBinStr) -> + ErrStr = <<"-define(", ErrName/binary, ", ", (integer_to_binary(ErrCodeId))/binary, ").\t\t%% ", ComDesc/binary, "\n">>, + spellErrCodeHrl(SortedErrList, <>). genEncodeRec({MsgName, MsgId, FieldList}, IsForBin) -> FieldLen = length(FieldList), - FunHead = - fun(_, {Index, StrAcc}) -> - {Index - 1, ", V" ++ integer_to_list(Index) ++ StrAcc} - end, - {_, TemStr} = lists:foldr(FunHead, {FieldLen, "}) ->\n\t"}, FieldList), + TemStr = spellHead(FieldList, 1, <<"">>), HeadStr = case IsForBin of true -> - "encodeIol(" ++ MsgName ++ ", {_" ++ TemStr; + <<"encodeIol(", MsgName/binary, ", {_", TemStr/binary, "}) ->\n\t">>; _ -> - "subEncode(" ++ MsgName ++ ", {_" ++ TemStr + <<"subEncode(", MsgName/binary, ", {_", TemStr/binary, "}) ->\n\t">> end, - FunBody = - fun({FieldType, _FieldName}, {Index, PStrAcc}) -> - TemV = "V" ++ integer_to_list(Index), - PackStr = gErlField:builtPackStr(FieldType) ++ TemV ++ ")", - case Index == 1 of - true -> - {Index - 1, PackStr ++ PStrAcc}; - _ -> - {Index - 1, ", " ++ PackStr ++ PStrAcc} - - end - end, - {_, BodyStr} = lists:foldr(FunBody, {FieldLen, ""}, FieldList), + BodyStr = spellBody(FieldList, 1, <<"">>), case IsForBin of true -> case FieldLen > 0 of true -> - HeadStr ++ "[<<" ++ integer_to_list(MsgId) ++ ":16/big-unsigned>>, " ++ BodyStr ++ "];\n"; + <>, ", BodyStr/binary, "];\n">>; _ -> - HeadStr ++ "[<<" ++ integer_to_list(MsgId) ++ ":16/big-unsigned>>];\n" + <>];\n">> end; _ -> case FieldLen > 0 of true -> - HeadStr ++ "[" ++ BodyStr ++ "];\n"; + <>; _ -> - HeadStr ++ "[];\n" + <> end end. @@ -249,12 +252,12 @@ resetPd() -> getIndexStr(Type) -> Index = erlang:get(Type), - erlang:integer_to_list(Index). + integer_to_binary(Index). useIndexStr(Type) -> Index = erlang:get(Type) + 1, erlang:put(Type, Index), - erlang:integer_to_list(Index). + integer_to_binary(Index). isCalcRefSize() -> erlang:get(pd_isCalcRefSize) > 0. @@ -265,6 +268,12 @@ initSubRec() -> getSubRec() -> erlang:get(pd_subRec). +initSubSubRec() -> + erlang:put(pd_subSubRec, []). + +getSubSubRec() -> + erlang:get(pd_subSubRec). + addSubRec({MsgName, _MsgId, _FieldList} = Info, IsForBin) when IsForBin -> OldList = erlang:get(pd_subRec), case lists:keyfind(MsgName, 1, OldList) of @@ -273,157 +282,170 @@ addSubRec({MsgName, _MsgId, _FieldList} = Info, IsForBin) when IsForBin -> _ -> ignore end; -addSubRec(_Info, _IsForBin) -> - ignore. +addSubRec({MsgName, _MsgId, _FieldList} = Info, _IsForBin) -> + OldAllList = erlang:get(pd_subRec), + case lists:keyfind(MsgName, 1, OldAllList) of + false -> + erlang:put(pd_subRec, [Info | OldAllList]), + OldSubList = erlang:get(pd_subSubRec), + case lists:keyfind(MsgName, 1, OldSubList) of + false -> + erlang:put(pd_subSubRec, [Info | OldSubList]); + _ -> + ignore + end; + _ -> + ignore + end. genDecodeBin({MsgName, MsgId, FieldList}, SortedSProtoList, IsForBin) -> FieldLen = length(FieldList), case IsForBin of true -> - HeadStr = "decodeBin(" ++ integer_to_list(MsgId) ++ ", LeftBin" ++ getIndexStr(pd_leftBin) ++ ") ->\n"; + HeadStr = <<"decodeBin(", (integer_to_binary(MsgId))/binary, ", LeftBin", (getIndexStr(pd_leftBin))/binary, ") ->\n">>; _ -> - HeadStr = "decodeRec(" ++ integer_to_list(MsgId) ++ ", LeftBin" ++ getIndexStr(pd_leftBin) ++ ") ->\n" + HeadStr = <<"decodeRec(", (integer_to_binary(MsgId))/binary, ", LeftBin", (getIndexStr(pd_leftBin))/binary, ") ->\n">> end, FunBody = fun({FieldType, _FieldName}, {IsSimple, StrAcc}) -> case FieldType of - "bool" -> + <<"bool">> -> TemStr = case IsSimple of true -> GetLeftBinStr1 = getIndexStr(pd_leftBin), UseLeftBinStr1 = useIndexStr(pd_leftBin), - "LeftBin" ++ UseLeftBinStr1 ++ "/binary>> = LeftBin" ++ GetLeftBinStr1 ++ ",\n"; + <<"LeftBin", UseLeftBinStr1/binary, "/binary>> = LeftBin", GetLeftBinStr1/binary, ",\n">>; _ -> - "" + <<"">> end, UseBoolStr = useIndexStr(pd_bool), GetLeftBinStr2 = getIndexStr(pd_leftBin), UseLeftBinStr2 = useIndexStr(pd_leftBin), - BoolStr = "\t<> = LeftBin" ++ GetLeftBinStr2 ++ ",\n", + BoolStr = <<"\t<> = LeftBin", GetLeftBinStr2/binary, ",\n">>, UseVStr = useIndexStr(pd_v), - VStr = "\tV" ++ UseVStr ++ " = Bool" ++ UseBoolStr ++ " =:= 1,\n", - {false, StrAcc ++ TemStr ++ BoolStr ++ VStr}; - "int8" -> + VStr = <<"\tV", UseVStr/binary, " = Bool", UseBoolStr/binary, " =:= 1,\n">>, + {false, <>}; + <<"int8">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":8/big-signed, "; + <<"V", UseVStr/binary, ":8/big-signed, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "uint8" -> + {true, <>}; + <<"uint8">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":8/big-unsigned, "; + <<"V", UseVStr/binary, ":8/big-unsigned, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "int16" -> + {true, <>}; + <<"int16">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":16/big-signed, "; + <<"V", UseVStr/binary, ":16/big-signed, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "uint16" -> + {true, <>}; + <<"uint16">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":16/big-unsigned, "; + <<"V", UseVStr/binary, ":16/big-unsigned, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "int32" -> + {true, <>}; + <<"int32">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":32/big-signed, "; + <<"V", UseVStr/binary, ":32/big-signed, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "uint32" -> + {true, <>}; + <<"uint32">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":32/big-unsigned, "; + <<"V", UseVStr/binary, ":32/big-unsigned, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "int64" -> + {true, <>}; + <<"int64">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":64/big-signed, "; + <<"V", UseVStr/binary, ":64/big-signed, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "uint64" -> + {true, <>}; + <<"uint64">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":64/big-unsigned, "; + <<"V", UseVStr/binary, ":64/big-unsigned, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "float" -> + {true, <>}; + <<"float">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":32/big-float, "; + <<"V", UseVStr/binary, ":32/big-float, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "double" -> + {true, <>}; + <<"double">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), - "V" ++ UseVStr ++ ":64/big-float, "; + <<"V", UseVStr/binary, ":64/big-float, ">>; _ -> UseVStr = useIndexStr(pd_v), - "\t<> end, - {true, StrAcc ++ TemStr}; - "string" -> + {true, <>}; + <<"string">> -> TemStr = case IsSimple of true -> GetLeftBinStr1 = getIndexStr(pd_leftBin), UseLeftBinStr1 = useIndexStr(pd_leftBin), - "LeftBin" ++ UseLeftBinStr1 ++ "/binary>> = LeftBin" ++ GetLeftBinStr1 ++ ",\n"; + <<"LeftBin", UseLeftBinStr1/binary, "/binary>> = LeftBin", GetLeftBinStr1/binary, ",\n">>; _ -> - "" + <<"">> end, UseLenStr = useIndexStr(pd_len), GetLeftBinStr2 = getIndexStr(pd_leftBin), @@ -433,61 +455,62 @@ genDecodeBin({MsgName, MsgId, FieldList}, SortedSProtoList, IsForBin) -> case isCalcRefSize() of false -> useIndexStr(pd_isCalcRefSize), - "\tRefSize = binary:referenced_byte_size(LeftBin0),\n"; + <<"\tRefSize = binary:referenced_byte_size(LeftBin0),\n">>; _ -> - "" + <<"">> end, - StrStr = "\t<> = LeftBin" ++ GetLeftBinStr2 ++ ",\n", - VStr = "\tcase Len" ++ UseLenStr ++ " < ?BinaryShareSize of\n\t\t" ++ - "true ->\n\t\t\tV" ++ UseVStr ++ " = TemStrV" ++ UseVStr ++ ";\n\t\t" ++ - "_ ->\n\t\t\tcase RefSize / Len" ++ UseLenStr ++ " > ?BinaryCopyRatio of\n\t\t\t\t" ++ - "true ->\n\t\t\t\t\tV" ++ UseVStr ++ " = binary:copy(TemStrV" ++ UseVStr ++ ");\n\t\t\t\t" ++ - "_ ->\n\t\t\t\t\tV" ++ UseVStr ++ " = TemStrV" ++ UseVStr ++ "\n\t\t\tend\n\tend,\n", - {false, StrAcc ++ TemStr ++ RefSizeStr ++ StrStr ++ VStr}; - "integer" -> + StrStr = <<"\t<> = LeftBin", GetLeftBinStr2/binary, ",\n">>, + VStr = <<"\tcase Len", UseLenStr/binary, " < ?BinaryShareSize of\n\t\t", + "true ->\n\t\t\tV", UseVStr/binary, " = TemStrV", UseVStr/binary, ";\n\t\t", + "_ ->\n\t\t\tcase RefSize / Len", UseLenStr/binary, " > ?BinaryCopyRatio of\n\t\t\t\t", + "true ->\n\t\t\t\t\tV", UseVStr/binary, " = binary:copy(TemStrV", UseVStr/binary, ");\n\t\t\t\t", + "_ ->\n\t\t\t\t\tV", UseVStr/binary, " = TemStrV", UseVStr/binary, "\n\t\t\tend\n\tend,\n">>, + {false, <>}; + <<"integer">> -> TemStr = case IsSimple of true -> UseVStr = useIndexStr(pd_v), UseIntBitsStr = useIndexStr(pd_intBits), - "IntBits" ++ UseIntBitsStr ++ ":8, " ++ "V" ++ UseVStr ++ ":IntBits" ++ UseIntBitsStr ++ "/big-signed, "; + <<"IntBits", UseIntBitsStr/binary, ":8, V", UseVStr/binary, ":IntBits", UseIntBitsStr/binary, "/big-signed, ">>; _ -> UseVStr = useIndexStr(pd_v), UseIntBitsStr = useIndexStr(pd_intBits), - "\t<> end, - {true, StrAcc ++ TemStr}; - "number" -> + {true, <>}; + <<"number">> -> TemStr = case IsSimple of true -> GetLeftBinStr1 = getIndexStr(pd_leftBin), UseLeftBinStr1 = useIndexStr(pd_leftBin), - "LeftBin" ++ UseLeftBinStr1 ++ "/binary>> = LeftBin" ++ GetLeftBinStr1 ++ ",\n"; + <<"LeftBin", UseLeftBinStr1/binary, "/binary>> = LeftBin", GetLeftBinStr1/binary, ",\n">>; _ -> - "" + <<"">> end, UseNumBitsStr = useIndexStr(pd_numBits), GetLeftBinStr2 = getIndexStr(pd_leftBin), UseLeftBinStr2 = useIndexStr(pd_leftBin), - NumStr = "\t<> = LeftBin" ++ GetLeftBinStr2 ++ ",\n", + NumStr = <<"\t<> = LeftBin", GetLeftBinStr2/binary, ",\n">>, UseVStr = useIndexStr(pd_v), UseLeftBinStr3 = useIndexStr(pd_leftBin), VStr = - "\tcase NumBits" ++ UseNumBitsStr ++ " of\n\t\t33-> \n\t\t\t<> = LeftBin" ++ UseLeftBinStr2 ++ - ";\n\t\t65 ->\n\t\t\t<> = LeftBin" ++ UseLeftBinStr2 ++ - ";\n\t\t_ ->\n\t\t\t<> = LeftBin" ++ UseLeftBinStr2 ++ "\n\tend,\n", - {false, StrAcc ++ TemStr ++ NumStr ++ VStr}; - "list[" ++ LeftStr -> - [SubTypeStr | _] = re:split(LeftStr, "\\]", [{return, list}]), + <<"\tcase NumBits", UseNumBitsStr/binary, " of\n\t\t33-> \n\t\t\t<> = LeftBin", UseLeftBinStr2/binary, ";\n\t\t65 ->\n\t\t\t<> = LeftBin", UseLeftBinStr2/binary, ";\n\t\t_ ->\n\t\t\t<> = LeftBin", UseLeftBinStr2/binary, "\n\tend,\n">>, + {false, <>}; + <<"list[", LeftStr/binary>> -> + [SubTypeStr | _] = re:split(LeftStr, <<"\\]">>, [{return, binary}]), TemStr = case IsSimple of true -> GetLeftBinStr1 = getIndexStr(pd_leftBin), UseLeftBinStr1 = useIndexStr(pd_leftBin), - "LeftBin" ++ UseLeftBinStr1 ++ "/binary>> = LeftBin" ++ GetLeftBinStr1 ++ ",\n"; + <<"LeftBin", UseLeftBinStr1/binary, "/binary>> = LeftBin", GetLeftBinStr1/binary, ",\n">>; _ -> - "" + <<"">> end, UseLenStr = useIndexStr(pd_len), @@ -497,100 +520,100 @@ genDecodeBin({MsgName, MsgId, FieldList}, SortedSProtoList, IsForBin) -> UseListBinStr = useIndexStr(pd_listBin), GetLeftBinStr3 = getIndexStr(pd_leftBin), UseLeftBinStr3 = useIndexStr(pd_leftBin), - LenStr = "\t<> = LeftBin" ++ GetLeftBinStr2 ++ ",\n", + LenStr = <<"\t<> = LeftBin", GetLeftBinStr2/binary, ",\n">>, DeListStr = case SubTypeStr of - "bool" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV =:= 1 || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "int8" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "uint8" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "int16" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "uint16" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "int32" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "uint32" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "int64" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "uint64" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "integer" -> - "\t{V" ++ UseVStr ++ ", LeftBin" ++ UseLeftBinStr3 ++ "} = deIntegerList(Len" ++ UseLenStr ++ ", LeftBin" ++ GetLeftBinStr3 ++ ", []),\n"; - "number" -> - "\t{V" ++ UseVStr ++ ", LeftBin" ++ UseLeftBinStr3 ++ "} = deNumberList(Len" ++ UseLenStr ++ ", LeftBin" ++ GetLeftBinStr3 ++ ", []),\n"; - "float" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "double" -> - ListBinStr = "\t<> = LeftBin" ++ GetLeftBinStr3 ++ ",\n", - VStr = "\tV" ++ UseVStr ++ " = [TemV || <> <= ListBin" ++ UseListBinStr ++ "],\n", - ListBinStr ++ VStr; - "string" -> + <<"bool">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV =:= 1 || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"int8">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"uint8">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"int16">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"uint16">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"int32">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"uint32">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"int64">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"uint64">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"integer">> -> + <<"\t{V", UseVStr/binary, ", LeftBin", UseLeftBinStr3/binary, "} = deIntegerList(Len", UseLenStr/binary, ", LeftBin", GetLeftBinStr3/binary, ", []),\n">>; + <<"number">> -> + <<"\t{V", UseVStr/binary, ", LeftBin", UseLeftBinStr3/binary, "} = deNumberList(Len", UseLenStr/binary, ", LeftBin", GetLeftBinStr3/binary, ", []),\n">>; + <<"float">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"double">> -> + ListBinStr = <<"\t<> = LeftBin", GetLeftBinStr3/binary, ",\n">>, + VStr = <<"\tV", UseVStr/binary, " = [TemV || <> <= ListBin", UseListBinStr/binary, "],\n">>, + <>; + <<"string">> -> case isCalcRefSize() of true -> - "\t{V" ++ UseVStr ++ ", LeftBin" ++ UseLeftBinStr3 ++ "} = deStringList(Len" ++ UseLenStr ++ ", LeftBin" ++ GetLeftBinStr3 ++ ", RefSize, []),\n"; + <<"\t{V", UseVStr/binary, ", LeftBin", UseLeftBinStr3/binary, "} = deStringList(Len", UseLenStr/binary, ", LeftBin", GetLeftBinStr3/binary, ", RefSize, []),\n">>; _ -> useIndexStr(pd_isCalcRefSize), - RefSizeStr = "\tRefSize = binary:referenced_byte_size(LeftBin0),\n", - VStr = "\t{V" ++ UseVStr ++ ", LeftBin" ++ UseLeftBinStr3 ++ "} = deStringList(Len" ++ UseLenStr ++ ", LeftBin" ++ GetLeftBinStr3 ++ ", RefSize, []),\n", - RefSizeStr ++ VStr + RefSizeStr = <<"\tRefSize = binary:referenced_byte_size(LeftBin0),\n">>, + VStr = <<"\t{V", UseVStr/binary, ", LeftBin", UseLeftBinStr3/binary, "} = deStringList(Len", UseLenStr/binary, ", LeftBin", GetLeftBinStr3/binary, ", RefSize, []),\n">>, + <> end; ListRecord -> case lists:keyfind(ListRecord, 1, SortedSProtoList) of {ListRecord, ListMsgId, _} = RecordInfo -> addSubRec(RecordInfo, IsForBin), - "\t{V" ++ UseVStr ++ ", LeftBin" ++ UseLeftBinStr3 ++ "} = deRecordList(Len" ++ UseLenStr ++ ", " ++ integer_to_list(ListMsgId) ++ ", LeftBin" ++ GetLeftBinStr3 ++ ", []),\n"; + <<"\t{V", UseVStr/binary, ", LeftBin", UseLeftBinStr3/binary, "} = deRecordList(Len", UseLenStr/binary, ", ", (integer_to_binary(ListMsgId))/binary, ", LeftBin", GetLeftBinStr3/binary, ", []),\n">>; _ -> io:format("this an Record undefined :~p~n", [ListRecord]), throw(record_undefined) end end, - {false, StrAcc ++ TemStr ++ LenStr ++ DeListStr}; + {false, <>}; OtherRecord -> TemStr = case IsSimple of true -> GetLeftBinStr1 = getIndexStr(pd_leftBin), UseLeftBinStr1 = useIndexStr(pd_leftBin), - "LeftBin" ++ UseLeftBinStr1 ++ "/binary>> = LeftBin" ++ GetLeftBinStr1 ++ ",\n"; + <<"LeftBin", UseLeftBinStr1/binary, "/binary>> = LeftBin", GetLeftBinStr1/binary, ",\n">>; _ -> - "" + <<"">> end, UseIsUndefStr = useIndexStr(pd_isUndef), GetLeftBinStr2 = getIndexStr(pd_leftBin), UseLeftBinStr2 = useIndexStr(pd_leftBin), - IsStr = "\t<> = LeftBin" ++ GetLeftBinStr2 ++ ",\n", + IsStr = <<"\t<> = LeftBin", GetLeftBinStr2/binary, ",\n">>, UseVStr = useIndexStr(pd_v), UseLeftBinStr3 = useIndexStr(pd_leftBin), case lists:keyfind(OtherRecord, 1, SortedSProtoList) of {OtherRecord, OtherMsgId, _} = RecordInfo -> addSubRec(RecordInfo, IsForBin), - VStr = "\tcase IsUndef" ++ UseIsUndefStr ++ " of\n\t\t0 ->\n\t\t\tV" ++ UseVStr ++ " = undefined,\n\t\t\tLeftBin" ++ UseLeftBinStr3 ++ " = LeftBin" ++ UseLeftBinStr2 ++ - " ;\n\t\t_ ->\n\t\t\t{V" ++ UseVStr ++ ", LeftBin" ++ UseLeftBinStr3 ++ "} = " ++ "decodeRec(" ++ integer_to_list(OtherMsgId) ++ ", LeftBin" ++ UseLeftBinStr2 ++ ")\n\tend,\n", - {false, StrAcc ++ TemStr ++ IsStr ++ VStr}; + VStr = <<"\tcase IsUndef", UseIsUndefStr/binary, " of\n\t\t0 ->\n\t\t\tV", UseVStr/binary, " = undefined,\n\t\t\tLeftBin", UseLeftBinStr3/binary, " = LeftBin", UseLeftBinStr2/binary, + " ;\n\t\t_ ->\n\t\t\t{V", UseVStr/binary, ", LeftBin", UseLeftBinStr3/binary, "} = ", "decodeRec(", (integer_to_binary(OtherMsgId))/binary, ", LeftBin", UseLeftBinStr2/binary, ")\n\tend,\n">>, + {false, <>}; _ -> io:format("this an Record undefined :~p~n", [OtherRecord]), throw(record_undefined) @@ -598,13 +621,13 @@ genDecodeBin({MsgName, MsgId, FieldList}, SortedSProtoList, IsForBin) -> end end, - {LIsSimple, BodyStr} = lists:foldl(FunBody, {false, ""}, FieldList), + {LIsSimple, BodyStr} = lists:foldl(FunBody, {false, <<"">>}, FieldList), LBodyStr = case LIsSimple of true -> LGetLeftBinStr = getIndexStr(pd_leftBin), LUseLeftBinStr = useIndexStr(pd_leftBin), - BodyStr ++ "LeftBin" ++ LUseLeftBinStr ++ "/binary>> = LeftBin" ++ LGetLeftBinStr ++ ",\n"; + <> = LeftBin", LGetLeftBinStr/binary, ",\n">>; _ -> BodyStr end, @@ -615,47 +638,45 @@ genDecodeBin({MsgName, MsgId, FieldList}, SortedSProtoList, IsForBin) -> MsgIndex = MsgId div ?MsgIdSegSize, Handler = erlang:get(pd_handler), {MsgIndex, ModName} = lists:keyfind(MsgIndex, 1, Handler), - HandleName = erlang:binary_to_list(ModName) ++ "Her", + HandleName = <>, case FieldLen > 0 of true -> FunRec = fun(N, Acc) -> - ", V" ++ integer_to_list(N) ++ Acc - + <> end, - RecStr = lists:foldr(FunRec, "", lists:seq(1, FieldLen)), - "\t{" ++ HandleName ++ ", " ++ MsgName ++ ", {" ++ MsgName ++ RecStr ++ "}};\n"; + RecStr = lists:foldl(FunRec, <<"">>, lists:seq(1, FieldLen)), + <<"\t{", HandleName/binary, ", ", MsgName/binary, ", {", MsgName/binary, RecStr/binary, "}};\n">>; _ -> - "\t{" ++ HandleName ++ ", " ++ MsgName ++ ", {" + MsgName ++ "}};\n" + <<"\t{", HandleName/binary, ", ", MsgName/binary, ", {", MsgName/binary, "}};\n">> end; _ -> case FieldLen > 0 of true -> FunRec = fun(N, Acc) -> - ", V" ++ integer_to_list(N) ++ Acc - + <> end, - RecStr = lists:foldr(FunRec, "", lists:seq(1, FieldLen)), - "\tMsgRec = {" ++ MsgName ++ RecStr ++ "},\n" - "\t{MsgRec, LeftBin" ++ getIndexStr(pd_leftBin) ++ "};\n"; + RecStr = lists:foldl(FunRec, <<"">>, lists:seq(1, FieldLen)), + <<"\tMsgRec = {", MsgName/binary, RecStr/binary, "},\n\t{MsgRec, LeftBin", (getIndexStr(pd_leftBin))/binary, "};\n">>; _ -> - "\t{{" + MsgName ++ "}, " ++ "<<>>};\n" + <<"\t{{", MsgName/binary, "}, ", "<<>>};\n">> end end, - HeadStr ++ LBodyStr ++ RetStr. + <>. genErl(SortedSProtoList, SortedErrList, HrlDir, ErlDir) -> initSubRec(), FunSpell = - fun({MsgName, _MsgId, FieldList} = MsgInfo, {MsgHrlAcc, _MsgIdAcc, MsgEncodeAcc, MsgDecodeAcc}) -> + fun({MsgName, MsgId, FieldList} = MsgInfo, {MsgHrlAcc, MsgEncodeAcc, MsgDecodeAcc, MsgIdAcc, MsgNameAcc}) -> %% gen hrl str Len = erlang:length(FieldList), - {_, Len, LastFieldStr} = lists:foldr(fun genMsgHrl/2, {Len, Len, ""}, FieldList), - HrlStr = "-record(" ++ MsgName ++ ", {\n\t" ++ LastFieldStr ++ "}).\n", + LastFieldStr = genMsgHrl(FieldList, Len, Len, <<"">>), + HrlStr = <<"-record(", MsgName/binary, ", {\n\t", LastFieldStr/binary, "}).\n">>, + %% gen getMsgId getMsgType str - %% TypeStr = "getMsgType(" ++ integer_to_list(MsgId) ++ ")-> " ++ MsgName ++ ";\n", - %% IdStr = "getMsgId(" ++ MsgName ++ ")-> " ++ integer_to_list(MsgId) ++ ";\n", + IdStr = <<"getMsgId(", MsgName/binary, ")-> ", (integer_to_binary(MsgId))/binary, ";\n">>, + NameStr = <<"getMsgName(", (integer_to_binary(MsgId))/binary, ")-> ", MsgName/binary, ";\n">>, %% gen encodeRec Str EncodeStr = genEncodeRec(MsgInfo, true), @@ -664,30 +685,28 @@ genErl(SortedSProtoList, SortedErrList, HrlDir, ErlDir) -> resetPd(), DecodeStr = genDecodeBin(MsgInfo, SortedSProtoList, true), - {[HrlStr | MsgHrlAcc], ["Unuse"], [EncodeStr | MsgEncodeAcc], [DecodeStr | MsgDecodeAcc]} + {<>, <>, <>, <>, <>} end, - {MsgHrlStr, _MsgIdStr, MsgEncodeStr, MsgDecodeStr} = lists:foldl(FunSpell, {[], ["getMsgId(_) -> 0.\n\n"], ["encodeIol(_, _) ->\n\t[].\n\n"], ["decodeBin(_, _) ->\n\t{undefinedHer, undefined, {}}.\n\n"]}, SortedSProtoList), + {MsgHrlStr, TMsgEncodeStr, TMsgDecodeStr, _TMsgIdStr, _TMsgNameStr} = lists:foldl(FunSpell, {<<>>, <<>>, <<>>, <<>>, <<>>}, SortedSProtoList), + MsgEncodeStr = <\n\t[].\n\n">>, + MsgDecodeStr = <\n\t{undefinedHer, undefined, {}}.\n\n">>, + _MsgIdStr = <<_TMsgIdStr/binary, "getMsgId(_) -> 0.\n\n">>, + _MsgNameStr = <<_TMsgNameStr/binary, "getMsgName(_) -> undefiend.\n\n">>, - ErrCodeStr = lists:foldl(fun genErrCodeHrl/2, [], SortedErrList) ++ "\n\n", + ErrCodeStr = spellErrCodeHrl(SortedErrList, <<>>), %% gen decodeRec str SubRecList = getSubRec(), - SortedSubRecList = lists:sort(fun({_Name1, MessageId1, _FieldList1}, {_Name2, MessageId2, _FieldList2}) -> - MessageId1 > MessageId2 end, SubRecList), - - FunSubRec = - fun(MsgInfo, {SubEncodeAcc, SubDecodeAcc}) -> - EncodeStr = genEncodeRec(MsgInfo, false), - resetPd(), - DecodeStr = genDecodeBin(MsgInfo, SortedSProtoList, false), - {[EncodeStr | SubEncodeAcc], [DecodeStr | SubDecodeAcc]} - end, - {MsgEncodeRecStr, MsgDecodeRecStr} = lists:foldl(FunSubRec, {["subEncode(_, _) ->\n\t[].\n\n"], ["decodeRec(_, _) ->\n\t{{}, <<>>}.\n\n"]}, SortedSubRecList), + initSubSubRec(), + SortedSubRecList = lists:sort(fun({_Name1, MessageId1, _FieldList1}, {_Name2, MessageId2, _FieldList2}) -> MessageId1 < MessageId2 end, SubRecList), + {MsgEncodeRecStr, MsgDecodeRecStr} = dealSubRec(SortedSubRecList, SortedSProtoList, <<"">>, <<"">>), ErlHeaderStr = protoErlHeader(), - OutputStr = ErlHeaderStr ++ MsgEncodeRecStr ++ MsgEncodeStr ++ MsgDecodeRecStr ++ MsgDecodeStr, - HrlFilename = do_write_hrl(HrlDir, protoMsg, protoHrlHeader() ++ ErrCodeStr ++ MsgHrlStr), - ErlFilename = do_write_erl(ErlDir, protoMsg, OutputStr), + HrlHeaderStr = protoHrlHeader(), + OutputErlStr = <>, + OutputHrlStr = <>, + HrlFilename = do_write_hrl(HrlDir, protoMsg, OutputHrlStr), + ErlFilename = do_write_erl(ErlDir, protoMsg, OutputErlStr), io:format("protoConvert hrl dir : ~s ~n", [HrlDir]), io:format("protoConvert erl dir : ~s ~n", [ErlDir]), @@ -695,14 +714,29 @@ genErl(SortedSProtoList, SortedErrList, HrlDir, ErlDir) -> io:format("protoConvert to erl file ~s succ.~n", [ErlFilename]), ok. -do_write_hrl(OutDir, Mod, Str) when is_list(OutDir) -> +dealSubRec([], SortedSProtoList, SubEncodeAcc, SubDecodeAcc) -> + case getSubSubRec() of + [] -> + {<\n\t[].\n\n">>, <\n\t{{}, <<>>}.\n\n">>}; + NewAddList -> + initSubSubRec(), + SortedSubRecList = lists:sort(fun({_Name1, MessageId1, _FieldList1}, {_Name2, MessageId2, _FieldList2}) -> MessageId1 < MessageId2 end, NewAddList), + dealSubRec(SortedSubRecList, SortedSProtoList, SubEncodeAcc, SubDecodeAcc) + end; +dealSubRec([MsgInfo | SubRecList], SortedSProtoList, SubEncodeAcc, SubDecodeAcc) -> + EncodeStr = genEncodeRec(MsgInfo, false), + resetPd(), + DecodeStr = genDecodeBin(MsgInfo, SortedSProtoList, false), + dealSubRec(SubRecList, SortedSProtoList, <>, <>). + +do_write_hrl(OutDir, Mod, BinStr) -> Filename = filename:join([OutDir, atom_to_list(Mod) ++ ".hrl"]), - ok = file:write_file(Filename, Str), + ok = file:write_file(Filename, BinStr), Filename. -do_write_erl(OutDir, Mod, Str) when is_list(OutDir) -> +do_write_erl(OutDir, Mod, BinStr ) -> Filename = filename:join([OutDir, atom_to_list(Mod) ++ ".erl"]), - case file:write_file(Filename, Str) of + case file:write_file(Filename, BinStr) of ok -> ok; _Ret -> diff --git a/test/protoMsg.erl b/test/protoMsg.erl index 2c2942e..e184942 100644 --- a/test/protoMsg.erl +++ b/test/protoMsg.erl @@ -240,6 +240,8 @@ encodeIol(tlistunion, {_, V1}) -> [<<34:16/big-unsigned>>, ?list_record(V1)]; encodeIol(allType, {_, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, V41, V42, V43, V44, V45, V46, V47, V48, V49, V50, V51, V52, V53, V54, V55}) -> [<<35:16/big-unsigned>>, ?bool(V1), ?int8(V2), ?uint8(V3), ?int16(V4), ?uint16(V5), ?int32(V6), ?uint32(V7), ?int64(V8), ?uint64(V9), ?integer(V10), ?integer(V11), ?integer(V12), ?integer(V13), ?integer(V14), ?integer(V15), ?integer(V16), ?integer(V17), ?number(V18), ?number(V19), ?number(V20), ?number(V21), ?number(V22), ?number(V23), ?number(V24), ?number(V25), ?number(V26), ?number(V27), ?float(V28), ?double(V29), ?string(V30), ?string(V31), ?record(V32), ?list_bool(V33), ?list_int8(V34), ?list_uint8(V35), ?list_int16(V36), ?list_uint16(V37), ?list_int32(V38), ?list_uint32(V39), ?list_int64(V40), ?list_uint64(V41), ?list_integer(V42), ?list_integer(V43), ?list_integer(V44), ?list_integer(V45), ?list_number(V46), ?list_number(V47), ?list_number(V48), ?list_number(V49), ?list_number(V50), ?list_number(V51), ?list_float(V52), ?list_double(V53), ?list_string(V54), ?list_record(V55)]; +encodeIol(testnull, {_}) -> + [<<36:16/big-unsigned>>]; encodeIol(person1, {_, V1, V2, V3, V4}) -> [<<1001:16/big-unsigned>>, ?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)]; encodeIol(_, _) -> @@ -816,6 +818,8 @@ decodeBin(35, LeftBin0) -> <> = LeftBin71, {V55, LeftBin73} = deRecordList(Len25, 5, LeftBin72, []), {testHer, allType, {allType, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, V41, V42, V43, V44, V45, V46, V47, V48, V49, V50, V51, V52, V53, V54, V55}}; +decodeBin(36, LeftBin0) -> + {testHer, testnull, {testnull}}; decodeBin(1001, LeftBin0) -> RefSize = binary:referenced_byte_size(LeftBin0), <> = LeftBin0, diff --git a/test/protoMsg.hrl b/test/protoMsg.hrl index 23f2743..3f6cdab 100644 --- a/test/protoMsg.hrl +++ b/test/protoMsg.hrl @@ -16,8 +16,6 @@ -define(ERR7, 6). %% def -define(ERR8, 7). %% 其他注释辅导费 -define(ERR6, 1001). %% dfff - - -record(test, { aa = "" :: string() }). @@ -218,6 +216,8 @@ , lstring = [] :: [string()] , lunion = [] :: [#union{}] }). +-record(testnull, { + }). -record(person1, { name = "" :: string() , id = 0 :: int32()