Kaynağa Gözat

解码返回对应的handler模块 和 handler函数 以及数据

master
AICells 4 yıl önce
ebeveyn
işleme
8e965947fa
5 değiştirilmiş dosya ile 90 ekleme ve 752 silme
  1. +16
    -6
      src/protoGen.erl
  2. +37
    -37
      test/protoMsg.erl
  3. +31
    -31
      test/test.erl
  4. +0
    -672
      test/test2.erl
  5. +6
    -6
      test/v1/test.erl

+ 16
- 6
src/protoGen.erl Dosyayı Görüntüle

@ -8,6 +8,8 @@
, convertDir/3
]).
-define(MsgIdSegSize, 1000).
protoHrlHeader() ->
"-opaque int8() :: -128..127.
-opaque int16() :: -32768..32767.
@ -615,6 +617,10 @@ genDecodeBin({MsgName, MsgId, FieldList}, SortedSProtoList, IsForBin) ->
RetStr =
case IsForBin of
true ->
MsgIndex = MsgId div ?MsgIdSegSize,
Handler = erlang:get(pd_handler),
{MsgIndex, ModName} = lists:keyfind(MsgIndex, 1, Handler),
HandleName = erlang:binary_to_list(ModName) ++ "Her",
case FieldLen > 0 of
true ->
FunRec =
@ -623,9 +629,9 @@ genDecodeBin({MsgName, MsgId, FieldList}, SortedSProtoList, IsForBin) ->
end,
RecStr = lists:foldr(FunRec, "", lists:seq(1, FieldLen)),
"\t{" ++ MsgName ++ RecStr ++ "};\n";
"\t{" ++ HandleName ++ ", " ++ MsgName ++ ", {" ++ MsgName ++ RecStr ++ "}};\n";
_ ->
"\t{" + MsgName ++ "};\n"
"\t{" ++ HandleName ++ ", " ++ MsgName ++ ", {" + MsgName ++ "}};\n"
end;
_ ->
case FieldLen > 0 of
@ -656,20 +662,24 @@ convertDir(ProtoDir) ->
convertDir(ProtoDir, "./", "./").
convertDir(ProtoDir, HrlDir, ErlDir) ->
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, "_"),
[ModIndex , ModName] = re:split(BaseName, "_"),
Index = binary_to_integer(ModIndex),
erlang:put(pd_messageid, Index * 1000 + 1),
erlang:put(pd_errcodeid, Index * 1000 + 1),
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
@ -703,7 +713,7 @@ convertDir(ProtoDir, HrlDir, ErlDir) ->
{[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{{}, <<>>}.\n\n"]}, SortedSProtoList),
{MsgHrlStr, _MsgIdStr, MsgEncodeStr, MsgDecodeStr} = lists:foldl(FunSpell, {[], ["getMsgId(_) -> 0.\n\n"], ["encodeIol(_, _) ->\n\t[].\n\n"], ["decodeBin(_, _) ->\n\t{undefinedHer, undefined, {}}.\n\n"]}, SortedSProtoList),
SortedErrList = lists:sort(fun({_ErrName1, ErrCodeId1, _Desc1}, {_ErrName2, ErrCodeId2, _Desc2}) ->
ErrCodeId1 > ErrCodeId2 end, ErrCodeList),

+ 37
- 37
test/protoMsg.erl Dosyayı Görüntüle

@ -338,7 +338,7 @@ decodeBin(1, LeftBin0) ->
V1 = TemStrV1
end
end,
{test, V1};
{testHer, test, {test, V1}};
decodeBin(2, LeftBin0) ->
<<IsUndef1:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
case IsUndef1 of
@ -349,7 +349,7 @@ decodeBin(2, LeftBin0) ->
{V1, LeftBin2} = decodeRec(1, LeftBin1)
end,
<<V2:32/big-signed, LeftBin3/binary>> = LeftBin2,
{phoneNumber, V1, V2};
{testHer, phoneNumber, {phoneNumber, V1, V2}};
decodeBin(3, LeftBin0) ->
RefSize = binary:referenced_byte_size(LeftBin0),
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0,
@ -379,13 +379,13 @@ decodeBin(3, LeftBin0) ->
end,
<<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3,
{V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []),
{person, V1, V2, V3, V4};
{testHer, person, {person, V1, V2, V3, V4}};
decodeBin(4, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
{V1, LeftBin2} = deRecordList(Len1, 3, LeftBin1, []),
<<Len2:16/big-unsigned, LeftBin3/binary>> = LeftBin2,
{V2, LeftBin4} = deRecordList(Len2, 3, LeftBin3, []),
{addressBook, V1, V2};
{testHer, addressBook, {addressBook, V1, V2}};
decodeBin(5, LeftBin0) ->
RefSize = binary:referenced_byte_size(LeftBin0),
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0,
@ -401,38 +401,38 @@ decodeBin(5, LeftBin0) ->
end
end,
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1,
{union, V1, V2};
{testHer, union, {union, V1, V2}};
decodeBin(6, LeftBin0) ->
<<Bool1:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
V1 = Bool1 =:= 1,
{tbool, V1};
{testHer, tbool, {tbool, V1}};
decodeBin(7, LeftBin0) ->
<<V1:8/big-signed, V2:8/big-signed, LeftBin1/binary>> = LeftBin0,
{tint8, V1, V2};
{testHer, tint8, {tint8, V1, V2}};
decodeBin(8, LeftBin0) ->
<<V1:8/big-unsigned, V2:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
{tuint8, V1, V2};
{testHer, tuint8, {tuint8, V1, V2}};
decodeBin(9, LeftBin0) ->
<<V1:16/big-signed, V2:16/big-signed, LeftBin1/binary>> = LeftBin0,
{tint16, V1, V2};
{testHer, tint16, {tint16, V1, V2}};
decodeBin(10, LeftBin0) ->
<<V1:16/big-unsigned, V2:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
{tuint16, V1, V2};
{testHer, tuint16, {tuint16, V1, V2}};
decodeBin(11, LeftBin0) ->
<<V1:32/big-signed, V2:32/big-signed, V3:32/big-signed, V4:32/big-signed, V5:32/big-signed, V6:32/big-signed, V7:32/big-signed, V8:32/big-signed, V9:32/big-signed, V10:32/big-signed, LeftBin1/binary>> = LeftBin0,
{tint32, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10};
{testHer, tint32, {tint32, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10}};
decodeBin(12, LeftBin0) ->
<<V1:32/big-unsigned, V2:32/big-unsigned, LeftBin1/binary>> = LeftBin0,
{tuint32, V1, V2};
{testHer, tuint32, {tuint32, V1, V2}};
decodeBin(13, LeftBin0) ->
<<V1:64/big-signed, V2:64/big-signed, LeftBin1/binary>> = LeftBin0,
{tint64, V1, V2};
{testHer, tint64, {tint64, V1, V2}};
decodeBin(14, LeftBin0) ->
<<V1:64/big-unsigned, V2:64/big-unsigned, LeftBin1/binary>> = LeftBin0,
{tuint64, V1, V2};
{testHer, tuint64, {tuint64, V1, V2}};
decodeBin(15, LeftBin0) ->
<<IntBits1:8, V1:IntBits1/big-signed, IntBits2:8, V2:IntBits2/big-signed, IntBits3:8, V3:IntBits3/big-signed, IntBits4:8, V4:IntBits4/big-signed, IntBits5:8, V5:IntBits5/big-signed, IntBits6:8, V6:IntBits6/big-signed, IntBits7:8, V7:IntBits7/big-signed, IntBits8:8, V8:IntBits8/big-signed, LeftBin1/binary>> = LeftBin0,
{tinteger, V1, V2, V3, V4, V5, V6, V7, V8};
{testHer, tinteger, {tinteger, V1, V2, V3, V4, V5, V6, V7, V8}};
decodeBin(16, LeftBin0) ->
<<NumBits1:8, LeftBin1/binary>> = LeftBin0,
case NumBits1 of
@ -524,13 +524,13 @@ decodeBin(16, LeftBin0) ->
_ ->
<<V10:NumBits10/big-signed, LeftBin20/binary>> = LeftBin19
end,
{tnumber, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10};
{testHer, tnumber, {tnumber, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10}};
decodeBin(17, LeftBin0) ->
<<V1:32/big-float, V2:32/big-float, LeftBin1/binary>> = LeftBin0,
{tfloat, V1, V2};
{testHer, tfloat, {tfloat, V1, V2}};
decodeBin(18, LeftBin0) ->
<<V1:64/big-float, V2:64/big-float, LeftBin1/binary>> = LeftBin0,
{tdouble, V1, V2};
{testHer, tdouble, {tdouble, V1, V2}};
decodeBin(19, LeftBin0) ->
RefSize = binary:referenced_byte_size(LeftBin0),
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0,
@ -557,79 +557,79 @@ decodeBin(19, LeftBin0) ->
V2 = TemStrV2
end
end,
{tstring, V1, V2};
{testHer, tstring, {tstring, V1, V2}};
decodeBin(20, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:8, LeftBin2/binary>> = LeftBin1,
V1 = [TemV =:= 1 || <<TemV:8/big-unsigned>> <= ListBin1],
{tlistbool, V1};
{testHer, tlistbool, {tlistbool, V1}};
decodeBin(21, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:8, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:8/big-signed>> <= ListBin1],
{tlistint8, V1};
{testHer, tlistint8, {tlistint8, V1}};
decodeBin(22, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:8, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:8/big-unsigned>> <= ListBin1],
{tlistuint8, V1};
{testHer, tlistuint8, {tlistuint8, V1}};
decodeBin(23, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:16, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:16/big-signed>> <= ListBin1],
{tlistint16, V1};
{testHer, tlistint16, {tlistint16, V1}};
decodeBin(24, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:16, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:16/big-unsigned>> <= ListBin1],
{tlistuint16, V1};
{testHer, tlistuint16, {tlistuint16, V1}};
decodeBin(25, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:32, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:32/big-signed>> <= ListBin1],
{tlistint32, V1};
{testHer, tlistint32, {tlistint32, V1}};
decodeBin(26, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:32, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:32/big-unsigned>> <= ListBin1],
{tlistuint32, V1};
{testHer, tlistuint32, {tlistuint32, V1}};
decodeBin(27, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:64, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:64/big-signed>> <= ListBin1],
{tlistint64, V1};
{testHer, tlistint64, {tlistint64, V1}};
decodeBin(28, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:64, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:64/big-unsigned>> <= ListBin1],
{tlistuint64, V1};
{testHer, tlistuint64, {tlistuint64, V1}};
decodeBin(29, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
{V1, LeftBin2} = deIntegerList(Len1, LeftBin1, []),
{tlistinteger, V1};
{testHer, tlistinteger, {tlistinteger, V1}};
decodeBin(30, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
{V1, LeftBin2} = deNumberList(Len1, LeftBin1, []),
{tlistnumber, V1};
{testHer, tlistnumber, {tlistnumber, V1}};
decodeBin(31, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:32, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:32/big-float>> <= ListBin1],
{tlistfloat, V1};
{testHer, tlistfloat, {tlistfloat, V1}};
decodeBin(32, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
<<ListBin1:Len1/big-binary-unit:64, LeftBin2/binary>> = LeftBin1,
V1 = [TemV || <<TemV:64/big-float>> <= ListBin1],
{tlistdouble, V1};
{testHer, tlistdouble, {tlistdouble, V1}};
decodeBin(33, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
RefSize = binary:referenced_byte_size(LeftBin0),
{V1, LeftBin2} = deStringList(Len1, LeftBin1, RefSize, []),
{tliststring, V1};
{testHer, tliststring, {tliststring, V1}};
decodeBin(34, LeftBin0) ->
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
{V1, LeftBin2} = deRecordList(Len1, 5, LeftBin1, []),
{tlistunion, V1};
{testHer, tlistunion, {tlistunion, V1}};
decodeBin(35, LeftBin0) ->
<<Bool1:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
V1 = Bool1 =:= 1,
@ -815,7 +815,7 @@ decodeBin(35, LeftBin0) ->
{V54, LeftBin71} = deStringList(Len24, LeftBin70, RefSize, []),
<<Len25:16/big-unsigned, LeftBin72/binary>> = LeftBin71,
{V55, LeftBin73} = deRecordList(Len25, 5, LeftBin72, []),
{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};
{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(1001, LeftBin0) ->
RefSize = binary:referenced_byte_size(LeftBin0),
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0,
@ -845,7 +845,7 @@ decodeBin(1001, LeftBin0) ->
end,
<<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3,
{V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []),
{person1, V1, V2, V3, V4};
{errorHer, person1, {person1, V1, V2, V3, V4}};
decodeBin(_, _) ->
{{}, <<>>}.
{undefined, {}}.

+ 31
- 31
test/test.erl Dosyayı Görüntüle

@ -11,20 +11,20 @@ encode_int32(N) ->
tt1(0, TT) ->
ok;
tt1(N, TT) ->
protoMsg:encode(TT),
protoMsg:encodeIol(TT),
tt1(N - 1, TT).
decode_int32(N) ->
TT = #tint32{int1 = 1, int2 = -1, int3 = 128, int4 = -128, int5 = 65536,
int6 = -65536, int7 = 2100000000, int8 = -2100000000, int9 = 678665, int10 = -678665},
Bin = protoMsg:encode(TT),
tt2(N, iolist_to_binary(Bin)).
Bin = protoMsg:encodeIol(TT),
tt2(N, iolist_to_binary(Bin), 0).
tt2(0, Bin) ->
tt2(0, Bin, _A) ->
{protoMsg:decode(Bin), Bin};
tt2(N, Bin) ->
protoMsg:decode(Bin),
tt2(N - 1, Bin).
tt2(N, Bin, _A) ->
A = protoMsg:decode(Bin),
tt2(N - 1, Bin, A).
encode_addressBook(N) ->
Add = #addressBook{
@ -51,7 +51,7 @@ encode_addressBook(N) ->
tt3(0, Add) ->
ok;
tt3(N, Add) ->
protoMsg:encode(Add),
protoMsg:encodeIol(Add),
tt3(N - 1, Add).
@ -75,7 +75,7 @@ decode_addressBook(N) ->
}
]
},
Bin = protoMsg:encode(AddressBook),
Bin = protoMsg:encodeIol(AddressBook),
tt4(N, iolist_to_binary(Bin)).
tt4(0, Bin) ->
Bin;
@ -84,33 +84,33 @@ tt4(N, Bin) ->
tt4(N - 1, Bin).
test1() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tbool{bool = true}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tbool{bool = true}))).
test21() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tint8{int1 = 123, int2 = -22}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tint8{int1 = 123, int2 = -22}))).
test22() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tuint8{int1 = 123, int2 = 182}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tuint8{int1 = 123, int2 = 182}))).
test31() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tint16{int1 = 12343, int2 = -3422}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tint16{int1 = 12343, int2 = -3422}))).
test32() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tuint16{int1 = 43244, int2 = 43243}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tuint16{int1 = 43244, int2 = 43243}))).
test41() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tint32{int1 = 12343434, int2 = -34434322}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tint32{int1 = 12343434, int2 = -34434322}))).
test42() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tuint32{int1 = 432444343, int2 = 432443433}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tuint32{int1 = 432444343, int2 = 432443433}))).
test51() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tint64{int1 = 12344343434, int2 = -344343434322}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tint64{int1 = 12344343434, int2 = -344343434322}))).
test52() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tuint64{int1 = 4343432444343, int2 = 4324434343433}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tuint64{int1 = 4343432444343, int2 = 4324434343433}))).
tt6(N) ->
Bin = iolist_to_binary(protoMsg:encode(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
Bin = iolist_to_binary(protoMsg:encodeIol(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
<<_MsgId:16/big, MsgBin/binary>> = Bin,
test6(N, MsgBin).
@ -121,7 +121,7 @@ test6(N, Bin) ->
test6(N - 1, Bin).
tt66(N) ->
Bin = iolist_to_binary(protoMsg:encode(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
Bin = iolist_to_binary(protoMsg:encodeIol(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
test66(N, Bin).
test66(0, Bin) ->
@ -138,7 +138,7 @@ test66(N, Bin) ->
test66(N - 1, Bin).
tt67(N) ->
Bin = iolist_to_binary(protoMsg:encode(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
Bin = iolist_to_binary(protoMsg:encodeIol(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
test67(N, Bin).
test67(0, Bin) ->
@ -149,15 +149,15 @@ test67(N, Bin) ->
test67(N - 1, Bin).
test7() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tnumber{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434, float1 = -34234343.343, float2 = 43242342342342.434}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tnumber{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434, float1 = -34234343.343, float2 = 43242342342342.434}))).
test81() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tfloat{int1 = -34234343.343, int2 = 42342342.434}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tfloat{int1 = -34234343.343, int2 = 42342342.434}))).
test82() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tdouble{int1 = -342343433333.343, int2 = 423423423333.434}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tdouble{int1 = -342343433333.343, int2 = 423423423333.434}))).
test9() ->
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tstring{int1 = "dfdf143242", int2 = "发地方撒发送"}))).
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tstring{int1 = "dfdf143242", int2 = "发地方撒发送"}))).
allType() ->
AllType = #allType{
@ -216,7 +216,7 @@ allType() ->
, lstring = ["fdsafsdfsfs", "电风扇打法胜多负少的", <<"fdsfasdfsfs">>, <<"大丰收大丰收的方式"/utf8>>]
, lunion = [#union{}, #union{type = 1, test = "aaaaa"}, #union{type = 2, test = "嘿嘿嘿嘿"}]
},
List = protoMsg:encode(AllType),
List = protoMsg:encodeIol(AllType),
iolist_to_binary(List),
%%io:format("~p~n", [List]),
AllType1 = protoMsg:decode(iolist_to_binary(List)).
@ -281,7 +281,7 @@ tall1(N) ->
, lstring = ["fdsafsdfsfs", "电风扇打法胜多负少的", <<"fdsfasdfsfs">>, <<"大丰收大丰收的方式"/utf8>>]
, lunion = [#union{}, #union{type = 1, test = "aaaaa"}, #union{type = 2, test = "嘿嘿嘿嘿"}]
},
%protoMsg:encode(AllType),
%protoMsg:encodeIol(AllType),
term_to_binary(AllType),
tall1(N - 1).
@ -343,7 +343,7 @@ tall(N) ->
, lstring = ["fdsafsdfsfs", "电风扇打法胜多负少的", <<"fdsfasdfsfs">>, <<"大丰收大丰收的方式"/utf8>>]
, lunion = [#union{}, #union{type = 1, test = "aaaaa"}, #union{type = 2, test = "嘿嘿嘿嘿"}]
},
%List = protoMsg:encode(AllType),
%List = protoMsg:encodeIol(AllType),
tall(N, term_to_binary(AllType)).
tall(0, Bin) ->
@ -444,7 +444,7 @@ ttt11(N) ->
ttt11(0, Add) ->
ok;
ttt11(N, Add) ->
protoMsg:encode(Add),
protoMsg:encodeIol(Add),
ttt11(N - 1, Add).
%%tt1(Add) ->
@ -459,7 +459,7 @@ ttt11(N, Add) ->
%]
%AddressBook = #person{name = "1232134", id = 11111,email = "aaa" ,phone = [#phoneNumber{}] },
%AddressBook = #phoneNumber{number =#test{aa = "dffsaf"},type = 12 },
%%protoMsg:encode(Add).
%%protoMsg:encodeIol(Add).
%ok = file:write_file("fff.bin", Bin),
%print_bin(Bin),
%Bin = protoCode:encode(AddressBook),
@ -500,7 +500,7 @@ tt(N) ->
%]
%AddressBook = #person{name = "1232134", id = 11111,email = "aaa" ,phone = [#phoneNumber{}] },
%AddressBook = #phoneNumber{number =#test{aa = "dffsaf"},type = 12 },
Bin = protoMsg:encode(AddressBook),
Bin = protoMsg:encodeIol(AddressBook),
%ok = file:write_file("fff.bin", Bin),
%print_bin(Bin),
tt(N, iolist_to_binary(Bin)).

+ 0
- 672
test/test2.erl Dosyayı Görüntüle

@ -1,672 +0,0 @@
-module(test2).
-include("protoMsg.hrl").
-compile(export_all).
encode_int32(N) ->
TT = #tint32{int1 = 1, int2 = -1, int3 = 128, int4 = -128, int5 = 65536,
int6 = -65536, int7 = 2100000000, int8 = -2100000000, int9 = 678665, int10 = -678665},
tt1(N, TT).
tt1(0, TT) ->
ok;
tt1(N, TT) ->
protoMsg:encodeIol(TT),
tt1(N - 1, TT).
decode_int32(N) ->
TT = #tint32{int1 = 1, int2 = -1, int3 = 128, int4 = -128, int5 = 65536,
int6 = -65536, int7 = 2100000000, int8 = -2100000000, int9 = 678665, int10 = -678665},
Bin = protoMsg:encodeIol(TT),
tt2(N, iolist_to_binary(Bin)).
tt2(0, Bin) ->
{protoMsg:decode(Bin), Bin};
tt2(N, Bin) ->
protoMsg:decode(Bin),
tt2(N - 1, Bin).
encode_addressBook(N) ->
Add = #addressBook{
person = [
#person{
name = "Alice",
id = 10000,
phone = [
#phoneNumber{number = #test{aa = "123456789"}, type = 1},
#phoneNumber{number = #test{aa = "87654321"}, type = 2}
]
},
#person{
name = "Bob",
id = 20000,
phone = [
#phoneNumber{number = #test{aa = "01234567890"}, type = 3}
]
}
]
},
tt3(N, Add).
tt3(0, Add) ->
ok;
tt3(N, Add) ->
protoMsg:encodeIol(Add),
tt3(N - 1, Add).
decode_addressBook(N) ->
AddressBook = #addressBook{
person = [
#person{
name = "Alice",
id = 10000,
phone = [
#phoneNumber{number = #test{aa = "123456789"}, type = 1},
#phoneNumber{number = #test{aa = "87654321"}, type = 2}
]
},
#person{
name = "Bob",
id = 20000,
phone = [
#phoneNumber{number = #test{aa = "01234567890"}, type = 3}
]
}
]
},
Bin = protoMsg:encodeIol(AddressBook),
tt4(N, iolist_to_binary(Bin)).
tt4(0, Bin) ->
Bin;
tt4(N, Bin) ->
protoMsg:decode(Bin),
tt4(N - 1, Bin).
test1() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tbool{bool = true}))).
test21() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tint8{int1 = 123, int2 = -22}))).
test22() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tuint8{int1 = 123, int2 = 182}))).
test31() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tint16{int1 = 12343, int2 = -3422}))).
test32() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tuint16{int1 = 43244, int2 = 43243}))).
test41() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tint32{int1 = 12343434, int2 = -34434322}))).
test42() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tuint32{int1 = 432444343, int2 = 432443433}))).
test51() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tint64{int1 = 12344343434, int2 = -344343434322}))).
test52() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tuint64{int1 = 4343432444343, int2 = 4324434343433}))).
tt6(N) ->
Bin = iolist_to_binary(protoMsg:encodeIol(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
<<_MsgId:16/big, MsgBin/binary>> = Bin,
test6(N, MsgBin).
test6(0, Bin) ->
io:format("IMY******111 ~p~n", [protoMsg:decode(Bin)]);
test6(N, Bin) ->
protoMsg:decodeBin(15, Bin),
test6(N - 1, Bin).
tt66(N) ->
Bin = iolist_to_binary(protoMsg:encodeIol(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
test66(N, Bin).
test66(0, Bin) ->
<<_MsgId:16/big, MsgBin/binary>> = Bin,
<<IntBits1:8, Int1:IntBits1/big-signed, IntBits2:8, Int2:IntBits2/big-signed, IntBits3:8, Int3:IntBits3/big-signed, IntBits4:8, Int4:IntBits4/big-signed, IntBits5:8, Int5:IntBits5/big-signed, IntBits6:8, Int6:IntBits6/big-signed, IntBits7:8, Int7:IntBits7/big-signed, IntBits8:8, Int8:IntBits8/big-signed, LeftBin/binary>> = MsgBin,
A = {tinteger, Int1, Int2, Int3, Int4, Int5, Int6, Int7, Int8},
io:format("IMY******111 ~p~n", [A]);
test66(N, Bin) ->
<<_MsgId:16/big, MsgBin/binary>> = Bin,
%% <<IntBits1:8, Int1:IntBits1/big-signed, IntBits2:8, Int2:IntBits2/big-signed, IntBits3:8, Int3:IntBits3/big-signed, IntBits4:8, Int4:IntBits4/big-signed, IntBits5:8, Int5:IntBits5/big-signed, IntBits6:8, Int6:IntBits6/big-signed, IntBits7:8, Int7:IntBits7/big-signed, IntBits8:8, Int8:IntBits8/big-signed, LeftBin/binary>> = MsgBin,
%% {tinteger, Int1, Int2, Int3, Int4, Int5, Int6, Int7, Int8},
<<IntBits1:8, V1:IntBits1/big-signed, IntBits2:8, V2:IntBits2/big-signed, IntBits3:8, V3:IntBits3/big-signed, IntBits4:8, V4:IntBits4/big-signed, IntBits5:8, V5:IntBits5/big-signed, IntBits6:8, V6:IntBits6/big-signed, IntBits7:8, V7:IntBits7/big-signed, IntBits8:8, V8:IntBits8/big-signed, LeftBin1/binary>> = MsgBin,
{tinteger, V1, V2, V3, V4, V5, V6, V7, V8},
test66(N - 1, Bin).
tt67(N) ->
Bin = iolist_to_binary(protoMsg:encodeIol(#tinteger{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434})),
test67(N, Bin).
test67(0, Bin) ->
A = protoMsg:decode(Bin),
io:format("IMY******111 ~p~n", [A]);
test67(N, Bin) ->
_A = protoMsg:decode(Bin),
test67(N - 1, Bin).
test7() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tnumber{int1 = -1, int2 = 1, int3 = 128, int4 = -128, int5 = -3244232, int6 = 432423432, int7 = -43434343434434, int8 = 432424242434, float1 = -34234343.343, float2 = 43242342342342.434}))).
test81() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tfloat{int1 = -34234343.343, int2 = 42342342.434}))).
test82() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tdouble{int1 = -342343433333.343, int2 = 423423423333.434}))).
test9() ->
protoMsg:decode(iolist_to_binary(protoMsg:encodeIol(#tstring{int1 = "dfdf143242", int2 = "发地方撒发送"}))).
allType() ->
AllType = #allType{
bool = false
, int8 = -66
, uint8 = 66
, int16 = -666
, uint16 = 666
, int32 = -66666
, uint32 = 66666
, int64 = -5294967296
, uint64 = 5294967296
, inte8 = -88
, uinte8 = 88
, inte16 = -8888
, uinte16 = 8888
, inte32 = -888888
, uinte32 = 888888
, inte64 = -8888888888
, uinte64 = 8888888888
, num8 = -99
, unum8 = 99
, num16 = -9999
, unum16 = 9999
, num32 = -999999
, unum32 = 999999
, num64 = -9999999999
, unum64 = 9999999999
, numfloat = 999999.99999
, numdouble = 9999999999.99999
, float = 123456.789321
, double = 4300000000.789321
, string1 = "this is a test!!!!"
, string2 = "这是一个测试, 等会看结果~!!!"
, lbool = [true, false, true, false]
, lint8 = [123, -123, 66, -66, 88, -88]
, luint8 = [1, 2, 3, 123, 67, 88]
, lint16 = [-12345, 12345, 6666, -6666]
, luint16 = [12345, 12345, 6666, 6666]
, lint32 = [-12345, 12345, 6666, -6666, -4000000000, 66666666]
, luint32 = [12345, 12345, 6666, 6666, 4000000000, 66666666]
, lint64 = [-12345, 12345, -6666, 6666, 400000000000, -66666666666666666]
, luint64 = [12345, 12345, 6666, 6666, 400000000000, 66666666666666666]
, linte8 = [123, 12, -66, 66, 34]
, linte16 = [12334, 12, -6666, 6666, 3412]
, linte32 = [12334, 12, -666666666, 6666, 3412]
, linte64 = [12334, 12, -666666666666, 6666, 3412]
, lnum8 = [123, 12.123, -66.456789, 66, 34]
, lnum16 = [12334, -12, -6666.6666, 6666, 3412]
, lnum32 = [12334, 12.7777, -666666666.666777, 6666, 3412]
, lnum64 = [12334, 12, -666666666666.88888, 6666, 3412.9999]
, lnfloat32 = [-666666.88888, 4434.434, 434.43, 3434]
, lnfloat64 = [-666666666666.88888, 4434.434, 434.43, 11111111111.34343, 5566]
, lfloat = [1.1, 2.2, 3.3, 666666.666]
, ldouble = [111111111.1, 22222222.2, 3.3, 66666622333333.666]
, lstring = ["fdsafsdfsfs", "电风扇打法胜多负少的", <<"fdsfasdfsfs">>, <<"大丰收大丰收的方式"/utf8>>]
, lunion = [#union{}, #union{type = 1, test = "aaaaa"}, #union{type = 2, test = "嘿嘿嘿嘿"}]
},
List = protoMsg:encodeIol(AllType),
iolist_to_binary(List),
%%io:format("~p~n", [List]),
AllType1 = protoMsg:decode(iolist_to_binary(List)).
%%AllType1.
tall1(0) ->
ok;
tall1(N) ->
AllType = #allType{
bool = false
, int8 = -66
, uint8 = 66
, int16 = -666
, uint16 = 666
, int32 = -66666
, uint32 = 66666
, int64 = -5294967296
, uint64 = 5294967296
, inte8 = -88
, uinte8 = 88
, inte16 = -8888
, uinte16 = 8888
, inte32 = -888888
, uinte32 = 888888
, inte64 = -8888888888
, uinte64 = 8888888888
, num8 = -99
, unum8 = 99
, num16 = -9999
, unum16 = 9999
, num32 = -999999
, unum32 = 999999
, num64 = -9999999999
, unum64 = 9999999999
, numfloat = 999999.99999
, numdouble = 9999999999.99999
, float = 123456.789321
, double = 4300000000.789321
, string1 = "this is a test!!!!"
, string2 = "这是一个测试, 等会看结果~!!!"
, lbool = [true, false, true, false]
, lint8 = [123, -123, 66, -66, 88, -88]
, luint8 = [1, 2, 3, 123, 67, 88]
, lint16 = [-12345, 12345, 6666, -6666]
, luint16 = [12345, 12345, 6666, 6666]
, lint32 = [-12345, 12345, 6666, -6666, -4000000000, 66666666]
, luint32 = [12345, 12345, 6666, 6666, 4000000000, 66666666]
, lint64 = [-12345, 12345, -6666, 6666, 400000000000, -66666666666666666]
, luint64 = [12345, 12345, 6666, 6666, 400000000000, 66666666666666666]
, linte8 = [123, 12, -66, 66, 34]
, linte16 = [12334, 12, -6666, 6666, 3412]
, linte32 = [12334, 12, -666666666, 6666, 3412]
, linte64 = [12334, 12, -666666666666, 6666, 3412]
, lnum8 = [123, 12.123, -66.456789, 66, 34]
, lnum16 = [12334, -12, -6666.6666, 6666, 3412]
, lnum32 = [12334, 12.7777, -666666666.666777, 6666, 3412]
, lnum64 = [12334, 12, -666666666666.88888, 6666, 3412.9999]
, lnfloat32 = [-666666.88888, 4434.434, 434.43, 3434]
, lnfloat64 = [-666666666666.88888, 4434.434, 434.43, 11111111111.34343, 5566]
, lfloat = [1.1, 2.2, 3.3, 666666.666]
, ldouble = [111111111.1, 22222222.2, 3.3, 66666622333333.666]
, lstring = ["fdsafsdfsfs", "电风扇打法胜多负少的", <<"fdsfasdfsfs">>, <<"大丰收大丰收的方式"/utf8>>]
, lunion = [#union{}, #union{type = 1, test = "aaaaa"}, #union{type = 2, test = "嘿嘿嘿嘿"}]
},
%protoMsg:encodeIol(AllType),
term_to_binary(AllType),
tall1(N - 1).
tall(N) ->
AllType = #allType{
bool = false
, int8 = -66
, uint8 = 66
, int16 = -666
, uint16 = 666
, int32 = -66666
, uint32 = 66666
, int64 = -5294967296
, uint64 = 5294967296
, inte8 = -88
, uinte8 = 88
, inte16 = -8888
, uinte16 = 8888
, inte32 = -888888
, uinte32 = 888888
, inte64 = -8888888888
, uinte64 = 8888888888
, num8 = -99
, unum8 = 99
, num16 = -9999
, unum16 = 9999
, num32 = -999999
, unum32 = 999999
, num64 = -9999999999
, unum64 = 9999999999
, numfloat = 999999.99999
, numdouble = 9999999999.99999
, float = 123456.789321
, double = 4300000000.789321
, string1 = "this is a test!!!!"
, string2 = "这是一个测试, 等会看结果~!!!"
, lbool = [true, false, true, false]
, lint8 = [123, -123, 66, -66, 88, -88]
, luint8 = [1, 2, 3, 123, 67, 88]
, lint16 = [-12345, 12345, 6666, -6666]
, luint16 = [12345, 12345, 6666, 6666]
, lint32 = [-12345, 12345, 6666, -6666, -4000000000, 66666666]
, luint32 = [12345, 12345, 6666, 6666, 4000000000, 66666666]
, lint64 = [-12345, 12345, -6666, 6666, 400000000000, -66666666666666666]
, luint64 = [12345, 12345, 6666, 6666, 400000000000, 66666666666666666]
, linte8 = [123, 12, -66, 66, 34]
, linte16 = [12334, 12, -6666, 6666, 3412]
, linte32 = [12334, 12, -666666666, 6666, 3412]
, linte64 = [12334, 12, -666666666666, 6666, 3412]
, lnum8 = [123, 12.123, -66.456789, 66, 34]
, lnum16 = [12334, -12, -6666.6666, 6666, 3412]
, lnum32 = [12334, 12.7777, -666666666.666777, 6666, 3412]
, lnum64 = [12334, 12, -666666666666.88888, 6666, 3412.9999]
, lnfloat32 = [-666666.88888, 4434.434, 434.43, 3434]
, lnfloat64 = [-666666666666.88888, 4434.434, 434.43, 11111111111.34343, 5566]
, lfloat = [1.1, 2.2, 3.3, 666666.666]
, ldouble = [111111111.1, 22222222.2, 3.3, 66666622333333.666]
, lstring = ["fdsafsdfsfs", "电风扇打法胜多负少的", <<"fdsfasdfsfs">>, <<"大丰收大丰收的方式"/utf8>>]
, lunion = [#union{}, #union{type = 1, test = "aaaaa"}, #union{type = 2, test = "嘿嘿嘿嘿"}]
},
%List = protoMsg:encodeIol(AllType),
tall(N, term_to_binary(AllType)).
tall(0, Bin) ->
Bin;
tall(N, Bin) ->
%protoMsg:decode(Bin),
binary_to_term(Bin),
tall(N - 1, Bin).
hh1(0) ->
ok;
hh1(N) ->
A = [tt1, tt2, tt3, tt4, {tet, tt1}, {tet, tt2}, {tet, tt3}, yyy],
test(A),
hh1(N - 1).
hh2(0) ->
ok;
hh2(N) ->
A = [tt1, tt2, tt3, tt4, {tet, tt1}, {tet, tt2}, {tet, tt3}, yyy],
tet(A),
hh2(N - 1).
test([]) ->
ok;
test([A | T]) ->
case A of
tt1 ->
ok;
tt2 ->
ok;
tt3 ->
ok;
tt4 ->
ok;
{tet, tt1} ->
ok;
{tet, tt2} ->
ok;
{tet, tt3} ->
ok;
_ ->
ok
end,
test(T).
tet([]) ->
ok;
tet([tt1 | T]) ->
ok,
tet(T);
tet([tt2 | T]) ->
ok,
tet(T);
tet([tt3 | T]) ->
ok,
tet(T);
tet([tt4 | T]) ->
ok,
tet(T);
tet([{tet, tt1} | T]) ->
ok,
tet(T);
tet([{tet, tt2} | T]) ->
ok,
tet(T);
tet([{tet, tt3} | T]) ->
ok,
tet(T);
tet([YY | T]) ->
ok,
tet(T).
ttt11(N) ->
Add = #addressBook{
person = [
#person{
name = "Alice",
id = 10000,
phone = [
#phoneNumber{number = #test{aa = "123456789"}, type = 1},
#phoneNumber{number = #test{aa = "87654321"}, type = 2}
]
},
#person{
name = "Bob",
id = 20000,
phone = [
#phoneNumber{number = #test{aa = "01234567890"}, type = 3}
]
}
]
},
ttt11(N, Add).
ttt11(0, Add) ->
ok;
ttt11(N, Add) ->
protoMsg:encodeIol(Add),
ttt11(N - 1, Add).
%%tt1(Add) ->
%"others" => [
% #{
% "name" => "Carol",
% "id" => 30000,
% "phone" => [
% #{ "number" => #{"aa" => "9876543210"} }
% ]
% }
%]
%AddressBook = #person{name = "1232134", id = 11111,email = "aaa" ,phone = [#phoneNumber{}] },
%AddressBook = #phoneNumber{number =#test{aa = "dffsaf"},type = 12 },
%%protoMsg:encodeIol(Add).
%ok = file:write_file("fff.bin", Bin),
%print_bin(Bin),
%Bin = protoCode:encode(AddressBook),
%ok = file:write_file("fff.bin", Bin),
%print_bin(Bin),
%MsgId = protoMsg:getMsgId(element(1, AddressBook)),
%<<MsgId:16/little, Bin/binary>>.
tt(N) ->
AddressBook = #addressBook{
person = [
#person{
name = "Alice",
id = 10000,
phone = [
#phoneNumber{number = #test{aa = "123456789"}, type = 1},
#phoneNumber{number = #test{aa = "87654321"}, type = 2}
]
},
#person{
name = "Bob",
id = 20000,
phone = [
#phoneNumber{number = #test{aa = "01234567890"}, type = 3}
]
}
]
},
%"others" => [
% #{
% "name" => "Carol",
% "id" => 30000,
% "phone" => [
% #{ "number" => #{"aa" => "9876543210"} }
% ]
% }
%]
%AddressBook = #person{name = "1232134", id = 11111,email = "aaa" ,phone = [#phoneNumber{}] },
%AddressBook = #phoneNumber{number =#test{aa = "dffsaf"},type = 12 },
Bin = protoMsg:encodeIol(AddressBook),
%ok = file:write_file("fff.bin", Bin),
%print_bin(Bin),
tt(N, iolist_to_binary(Bin)).
tt(0, Bin) ->
protoMsg:decode(Bin);
tt(N, Bin) ->
protoMsg:decode(Bin),
tt(N - 1, Bin).
%{Len, List, RestBin} = protoMsg("AddressBook", Bin),
%io:format("Len:~p, RestBin:~p~n", [Len, RestBin]),
%io:format("List:~p~n", [List]),
%{Map, _, _} = sproto:decode2("AddressBook", Bin),
%Map.
ttt1(0) ->
AddressBook = #addressBook{
person = [
#person{
name = "Alice",
id = 10000,
phone = [
#phoneNumber{number = #test{aa = "你好啊 嘿嘿"}, type = 1},
#phoneNumber{number = #test{aa = "87654321"}, type = 2}
]
},
#person{
name = "Bob",
id = 20000,
phone = [
#phoneNumber{number = #test{aa = "范德萨地方范德萨发"}, type = 3}
]
}
]
},
term_to_binary(AddressBook);
ttt1(N) ->
ttt1(),
ttt1(N - 1).
ttt1() ->
AddressBook = #addressBook{
person = [
#person{
name = "Alice",
id = 10000,
phone = [
#phoneNumber{number = #test{aa = "你好啊 嘿嘿"}, type = 1},
#phoneNumber{number = #test{aa = "87654321"}, type = 2}
]
},
#person{
name = "Bob",
id = 20000,
phone = [
#phoneNumber{number = #test{aa = "范德萨地方范德萨发"}, type = 3}
]
}
]
},
%"others" => [
% #{
% "name" => "Carol",
% "id" => 30000,
% "phone" => [
% #{ "number" => #{"aa" => "9876543210"} }
% ]
% }
%]
%AddressBook = #person{name = "1232134", id = 11111,email = "aaa" ,phone = [#phoneNumber{}] },
%AddressBook = #phoneNumber{number =#test{aa = "dffsaf"},type = 12 },
Bin = term_to_binary(AddressBook).
%ok = file:write_file("fff.bin", Bin),
%print_bin(Bin),
%Bin = protoCode:encode(AddressBook),
%ok = file:write_file("fff.bin", Bin),
%print_bin(Bin),
%MsgId = protoMsg:getMsgId(element(1, AddressBook)),
%<<MsgId:16/little, Bin/binary>>.
ttt(N) ->
AddressBook = #addressBook{
person = [
#person{
name = "Alice",
id = 10000,
phone = [
#phoneNumber{number = #test{aa = "123456789"}, type = 1},
#phoneNumber{number = #test{aa = "87654321"}, type = 2}
]
},
#person{
name = "Bob",
id = 20000,
phone = [
#phoneNumber{number = #test{aa = "01234567890"}, type = 3}
]
}
]
},
%"others" => [
% #{
% "name" => "Carol",
% "id" => 30000,
% "phone" => [
% #{ "number" => #{"aa" => "9876543210"} }
% ]
% }
%]
%AddressBook = #person{name = "1232134", id = 11111,email = "aaa" ,phone = [#phoneNumber{}] },
%AddressBook = #phoneNumber{number =#test{aa = "dffsaf"},type = 12 },
%ok = file:write_file("fff.bin", Bin),
%print_bin(Bin),
ttt(N, term_to_binary(AddressBook)).
ttt(0, Bin) ->
binary_to_term(Bin);
ttt(N, Bin) ->
binary_to_term(Bin),
ttt(N - 1, Bin).
print_bin(Bin) ->
ByteList = lists:reverse(bin_to_hex(Bin, [])),
Fun = fun(Byte, Acc) ->
io:format("~2.16.0b ", [Byte]),
case Acc rem 8 =:= 0 of
true -> io:format("~n", []);
false -> ok
end,
Acc + 1
end,
lists:foldl(Fun, 1, ByteList),
io:format("bytes:~p~n", [byte_size(Bin)]).
bin_to_hex(<<>>, Acc) ->
Acc;
bin_to_hex(Bin, Acc) ->
<<A:8, Bin2/binary>> = Bin,
bin_to_hex(Bin2, [A | Acc]).
a1(B) ->
Bin = list_to_binary([X rem 256 || X <- lists:seq(1, 10000)]),
a1(B, Bin).
a1(0, Bin) ->
<<ListBin:6400/big-binary, Left/binary>> = Bin,
[X || <<X:32/big-unsigned>> <= ListBin];
a1(N, Bin) ->
<<ListBin:6400/big-binary, Left/binary>> = Bin,
A = [X || <<X:32/big-unsigned>> <= ListBin],
B = [X || <<X:16/big-unsigned>> <= ListBin],
io:format("IMY********** ~p~n", [A == B]),
a1(N - 1, Bin).
a2(B) ->
Bin = list_to_binary([X rem 256 || X <- lists:seq(1, 10000)]),
a2(B, Bin).
a2(0, Bin) ->
Len = 200,
<<ListBin:Len/big-binary-unit:32, Left/binary>> = Bin,
[X || <<X:32/big-unsigned>> <= ListBin];
a2(N, Bin) ->
Len = 200,
<<ListBin:Len/big-binary-unit:32, Left/binary>> = Bin,
[X || <<X:32/big-unsigned>> <= ListBin],
a2(N - 1, Bin).

test/v1/test1.erl → test/v1/test.erl Dosyayı Görüntüle

@ -1,4 +1,4 @@
-module(test1).
-module(test).
-include("protoMsg.hrl").
-compile(export_all).
@ -18,13 +18,13 @@ decode_int32(N) ->
TT = #tint32{int1 = 1, int2 = -1, int3 = 128, int4 = -128, int5 = 65536,
int6 = -65536, int7 = 2100000000, int8 = -2100000000, int9 = 678665, int10 = -678665},
Bin = protoMsg:encode(TT),
tt2(N, iolist_to_binary(Bin)).
tt2(N, iolist_to_binary(Bin), 0).
tt2(0, Bin) ->
tt2(0, Bin, _A) ->
{protoMsg:decode(Bin), Bin};
tt2(N, Bin) ->
protoMsg:decode(Bin),
tt2(N - 1, Bin).
tt2(N, Bin, _A) ->
A = protoMsg:decode(Bin),
tt2(N - 1, Bin, A).
encode_addressBook(N) ->
Add = #addressBook{

Yükleniyor…
İptal
Kaydet