@ -0,0 +1,851 @@ | |||
-module(protoMsg). | |||
-compile([nowarn_unused_vars]). | |||
-export([encodeIol/1, encodeBin/1, encodeIol/2, subEncode/1, subEncode/2, decode/1, decodeBin/2]). | |||
-define(min8, -128). | |||
-define(max8, 127). | |||
-define(min16, -32768). | |||
-define(max16, 32767). | |||
-define(min32, -2147483648). | |||
-define(max32, 2147483647). | |||
-define(min64, -9223372036854775808). | |||
-define(max64, 9223372036854775807). | |||
-define(minF32, -3.4E+38). | |||
-define(maxF32, 3.4E+38). | |||
-define(minF64, -1.797E-308). | |||
-define(maxF64, 1.797E+308). | |||
-define(int8(V), <<V:8>>). | |||
-define(uint8(V), <<V:8>>). | |||
-define(int16(V), <<V:16/big>>). | |||
-define(uint16(V), <<V:16/big>>). | |||
-define(int32(V), <<V:32/big>>). | |||
-define(uint32(V), <<V:32/big>>). | |||
-define(int64(V), <<V:64/big>>). | |||
-define(uint64(V), <<V:64/big>>). | |||
-define(integer(V), (integer(V))). | |||
-define(number(V), (number(V))). | |||
-define(string(V), (string(V))). | |||
-define(float(V), <<V:32/big-float>>). | |||
-define(double(V), <<V:64/big-float>>). | |||
-define(bool(V), (case V of true -> <<1:8>>; _ -> <<0:8>> end)). | |||
-define(record(V), (case V of undefined -> [<<0:8>>]; V -> [<<1:8>>, subEncode(V)] end)). | |||
-define(list_bool(List), [<<(length(List)):16/big>>, [?bool(V) || V <- List]]). | |||
-define(list_int8(List), [<<(length(List)):16/big>>, [?int8(V) || V <- List]]). | |||
-define(list_uint8(List), [<<(length(List)):16/big>>, [?uint8(V) || V <- List]]). | |||
-define(list_int16(List), [<<(length(List)):16/big>>, [?int16(V) || V <- List]]). | |||
-define(list_uint16(List), [<<(length(List)):16/big>>, [?uint16(V) || V <- List]]). | |||
-define(list_int32(List), [<<(length(List)):16/big>>, [?int32(V) || V <- List]]). | |||
-define(list_uint32(List), [<<(length(List)):16/big>>, [?uint32(V) || V <- List]]). | |||
-define(list_int64(List), [<<(length(List)):16/big>>, [?int64(V) || V <- List]]). | |||
-define(list_uint64(List), [<<(length(List)):16/big>>, [?uint64(V) || V <- List]]). | |||
-define(list_float(List), [<<(length(List)):16/big>>, [?float(V) || V <- List]]). | |||
-define(list_double(List), [<<(length(List)):16/big>>, [?double(V) || V <- List]]). | |||
-define(list_integer(List), [<<(length(List)):16/big>>, [integer(V) || V <- List]]). | |||
-define(list_number(List), [<<(length(List)):16/big>>, [number(V) || V <- List]]). | |||
-define(list_string(List), [<<(length(List)):16/big>>, [string(V) || V <- List]]). | |||
-define(list_record(List), [<<(length(List)):16/big>>, [subEncode(V) || V <- List]]). | |||
-define(BinaryShareSize, 65). | |||
-define(BinaryCopyRatio, 1.2). | |||
integer(V) -> | |||
if | |||
V >= ?min8 andalso V =< ?max8 -> | |||
<<8:8, <<V:8>>/binary>>; | |||
V >= ?min16 andalso V =< ?max16 -> | |||
<<16:8, <<V:16/big>>/binary>>; | |||
V >= ?min32 andalso V =< ?max32 -> | |||
<<32:8, <<V:32/big>>/binary>>; | |||
V >= ?min64 andalso V =< ?max64 -> | |||
<<64:8, <<V:64/big>>/binary>>; | |||
true -> | |||
throw(exceeded_the_integer) | |||
end. | |||
number(V) -> | |||
if | |||
erlang:is_integer(V) -> | |||
if | |||
V >= ?min8 andalso V =< ?max8 -> | |||
<<8:8, <<V:8>>/binary>>; | |||
V >= ?min16 andalso V =< ?max16 -> | |||
<<16:8, <<V:16/big>>/binary>>; | |||
V >= ?min32 andalso V =< ?max32 -> | |||
<<32:8, <<V:32/big>>/binary>>; | |||
V >= ?min64 andalso V =< ?max64 -> | |||
<<64:8, <<V:64/big>>/binary>>; | |||
true -> | |||
throw(exceeded_the_integer) | |||
end; | |||
erlang:is_float(V) -> | |||
if | |||
V >= ?minF32 andalso V =< ?maxF32 -> | |||
<<33:8, <<V:32/big-float>>/binary>>; | |||
V >= ?minF64 andalso V =< ?maxF64 -> | |||
<<65:8, <<V:64/big-float>>/binary>>; | |||
true -> | |||
throw(exceeded_the_float) | |||
end; | |||
true -> | |||
throw(is_not_number) | |||
end. | |||
string(Str) when is_binary(Str) -> | |||
[<<(byte_size(Str)):16/big>>, Str]; | |||
string(Str) -> | |||
Str2 = unicode:characters_to_binary(Str, utf8), | |||
[<<(byte_size(Str2)):16/big>>, Str2]. | |||
decode(Bin) -> | |||
<<MsgId:16/big, MsgBin/binary>> = Bin, | |||
decodeBin(MsgId, MsgBin). | |||
deIntegerList(0, MsgBin, RetList) -> | |||
{lists:reverse(RetList), MsgBin}; | |||
deIntegerList(N, MsgBin, RetList) -> | |||
<<IntBits:8, Int:IntBits/big-signed, LeftBin/binary>> = MsgBin, | |||
deIntegerList(N - 1, LeftBin, [Int | RetList]). | |||
deNumberList(0, MsgBin, RetList) -> | |||
{lists:reverse(RetList), MsgBin}; | |||
deNumberList(N, MsgBin, RetList) -> | |||
<<NumBits:8, NumBin/binary>> = MsgBin, | |||
case NumBits of | |||
33 -> | |||
<<Float:32/big-float, LeftBin/binary>> = NumBin, | |||
deNumberList(N - 1, LeftBin, [Float | RetList]); | |||
65 -> | |||
<<Float:64/big-float, LeftBin/binary>> = NumBin, | |||
deNumberList(N - 1, LeftBin, [Float | RetList]); | |||
_ -> | |||
<<Int:NumBits/big-signed, LeftBin/binary>> = NumBin, | |||
deNumberList(N - 1, LeftBin, [Int | RetList]) | |||
end. | |||
deStringList(0, MsgBin, _RefSize, RetList) -> | |||
{lists:reverse(RetList), MsgBin}; | |||
deStringList(N, MsgBin, RefSize, RetList) -> | |||
<<Len:16/big, StrBin:Len/binary-unit:8, LeftBin/binary>> = MsgBin, | |||
case Len < ?BinaryShareSize of | |||
true -> | |||
deStringList(N - 1, LeftBin, RefSize, [StrBin | RetList]); | |||
_ -> | |||
case RefSize / Len > ?BinaryCopyRatio of | |||
true -> | |||
StrBinCopy = binary:copy(StrBin), | |||
deStringList(N - 1, LeftBin, RefSize, [StrBinCopy | RetList]); | |||
_ -> | |||
deStringList(N - 1, LeftBin, RefSize, [StrBin | RetList]) | |||
end | |||
end. | |||
deRecordList(0, _MsgId, MsgBin, RetList) -> | |||
{lists:reverse(RetList), MsgBin}; | |||
deRecordList(N, MsgId, MsgBin, RetList) -> | |||
{Tuple, LeftBin} = decodeRec(MsgId, MsgBin), | |||
deRecordList(N - 1, MsgId, LeftBin, [Tuple | RetList]). | |||
encodeIol(RecMsg) -> | |||
encodeIol(erlang:element(1, RecMsg), RecMsg). | |||
encodeBin(RecMsg) -> | |||
erlang:iolist_to_binary(encodeIol(RecMsg)). | |||
subEncode(RecMsg) -> | |||
subEncode(erlang:element(1, RecMsg), RecMsg). | |||
subEncode(test, {_, V1}) -> | |||
[?string(V1)]; | |||
subEncode(phoneNumber, {_, V1, V2}) -> | |||
[?record(V1), ?int32(V2)]; | |||
subEncode(person, {_, V1, V2, V3, V4}) -> | |||
[?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)]; | |||
subEncode(union, {_, V1, V2}) -> | |||
[?string(V1), ?int32(V2)]; | |||
subEncode(_, _) -> | |||
[]. | |||
encodeIol(test, {_, V1}) -> | |||
[<<1:16/big-unsigned>>, ?string(V1)]; | |||
encodeIol(phoneNumber, {_, V1, V2}) -> | |||
[<<2:16/big-unsigned>>, ?record(V1), ?int32(V2)]; | |||
encodeIol(person, {_, V1, V2, V3, V4}) -> | |||
[<<3:16/big-unsigned>>, ?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)]; | |||
encodeIol(addressBook, {_, V1, V2}) -> | |||
[<<4:16/big-unsigned>>, ?list_record(V1), ?list_record(V2)]; | |||
encodeIol(union, {_, V1, V2}) -> | |||
[<<5:16/big-unsigned>>, ?string(V1), ?int32(V2)]; | |||
encodeIol(tbool, {_, V1}) -> | |||
[<<6:16/big-unsigned>>, ?bool(V1)]; | |||
encodeIol(tint8, {_, V1, V2}) -> | |||
[<<7:16/big-unsigned>>, ?int8(V1), ?int8(V2)]; | |||
encodeIol(tuint8, {_, V1, V2}) -> | |||
[<<8:16/big-unsigned>>, ?uint8(V1), ?uint8(V2)]; | |||
encodeIol(tint16, {_, V1, V2}) -> | |||
[<<9:16/big-unsigned>>, ?int16(V1), ?int16(V2)]; | |||
encodeIol(tuint16, {_, V1, V2}) -> | |||
[<<10:16/big-unsigned>>, ?uint16(V1), ?uint16(V2)]; | |||
encodeIol(tint32, {_, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10}) -> | |||
[<<11:16/big-unsigned>>, ?int32(V1), ?int32(V2), ?int32(V3), ?int32(V4), ?int32(V5), ?int32(V6), ?int32(V7), ?int32(V8), ?int32(V9), ?int32(V10)]; | |||
encodeIol(tuint32, {_, V1, V2}) -> | |||
[<<12:16/big-unsigned>>, ?uint32(V1), ?uint32(V2)]; | |||
encodeIol(tint64, {_, V1, V2}) -> | |||
[<<13:16/big-unsigned>>, ?int64(V1), ?int64(V2)]; | |||
encodeIol(tuint64, {_, V1, V2}) -> | |||
[<<14:16/big-unsigned>>, ?uint64(V1), ?uint64(V2)]; | |||
encodeIol(tinteger, {_, V1, V2, V3, V4, V5, V6, V7, V8}) -> | |||
[<<15:16/big-unsigned>>, ?integer(V1), ?integer(V2), ?integer(V3), ?integer(V4), ?integer(V5), ?integer(V6), ?integer(V7), ?integer(V8)]; | |||
encodeIol(tnumber, {_, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10}) -> | |||
[<<16:16/big-unsigned>>, ?number(V1), ?number(V2), ?number(V3), ?number(V4), ?number(V5), ?number(V6), ?number(V7), ?number(V8), ?number(V9), ?number(V10)]; | |||
encodeIol(tfloat, {_, V1, V2}) -> | |||
[<<17:16/big-unsigned>>, ?float(V1), ?float(V2)]; | |||
encodeIol(tdouble, {_, V1, V2}) -> | |||
[<<18:16/big-unsigned>>, ?double(V1), ?double(V2)]; | |||
encodeIol(tstring, {_, V1, V2}) -> | |||
[<<19:16/big-unsigned>>, ?string(V1), ?string(V2)]; | |||
encodeIol(tlistbool, {_, V1}) -> | |||
[<<20:16/big-unsigned>>, ?list_bool(V1)]; | |||
encodeIol(tlistint8, {_, V1}) -> | |||
[<<21:16/big-unsigned>>, ?list_int8(V1)]; | |||
encodeIol(tlistuint8, {_, V1}) -> | |||
[<<22:16/big-unsigned>>, ?list_uint8(V1)]; | |||
encodeIol(tlistint16, {_, V1}) -> | |||
[<<23:16/big-unsigned>>, ?list_int16(V1)]; | |||
encodeIol(tlistuint16, {_, V1}) -> | |||
[<<24:16/big-unsigned>>, ?list_uint16(V1)]; | |||
encodeIol(tlistint32, {_, V1}) -> | |||
[<<25:16/big-unsigned>>, ?list_int32(V1)]; | |||
encodeIol(tlistuint32, {_, V1}) -> | |||
[<<26:16/big-unsigned>>, ?list_uint32(V1)]; | |||
encodeIol(tlistint64, {_, V1}) -> | |||
[<<27:16/big-unsigned>>, ?list_int64(V1)]; | |||
encodeIol(tlistuint64, {_, V1}) -> | |||
[<<28:16/big-unsigned>>, ?list_uint64(V1)]; | |||
encodeIol(tlistinteger, {_, V1}) -> | |||
[<<29:16/big-unsigned>>, ?list_integer(V1)]; | |||
encodeIol(tlistnumber, {_, V1}) -> | |||
[<<30:16/big-unsigned>>, ?list_number(V1)]; | |||
encodeIol(tlistfloat, {_, V1}) -> | |||
[<<31:16/big-unsigned>>, ?list_float(V1)]; | |||
encodeIol(tlistdouble, {_, V1}) -> | |||
[<<32:16/big-unsigned>>, ?list_double(V1)]; | |||
encodeIol(tliststring, {_, V1}) -> | |||
[<<33:16/big-unsigned>>, ?list_string(V1)]; | |||
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(person1, {_, V1, V2, V3, V4}) -> | |||
[<<1001:16/big-unsigned>>, ?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)]; | |||
encodeIol(_, _) -> | |||
[]. | |||
decodeRec(1, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
MsgRec = {test, V1}, | |||
{MsgRec, LeftBin1}; | |||
decodeRec(2, LeftBin0) -> | |||
<<IsUndef1:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
case IsUndef1 of | |||
0 -> | |||
V1 = undefined, | |||
LeftBin2 = LeftBin1 ; | |||
_ -> | |||
{V1, LeftBin2} = decodeRec(1, LeftBin1) | |||
end, | |||
<<V2:32/big-signed, LeftBin3/binary>> = LeftBin2, | |||
MsgRec = {phoneNumber, V1, V2}, | |||
{MsgRec, LeftBin3}; | |||
decodeRec(3, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
<<Len2:16/big-unsigned, TemStrV3:Len2/binary, LeftBin3/binary>> = LeftBin2, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V3 = TemStrV3; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V3 = binary:copy(TemStrV3); | |||
_ -> | |||
V3 = TemStrV3 | |||
end | |||
end, | |||
<<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3, | |||
{V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []), | |||
MsgRec = {person, V1, V2, V3, V4}, | |||
{MsgRec, LeftBin5}; | |||
decodeRec(5, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
MsgRec = {union, V1, V2}, | |||
{MsgRec, LeftBin2}; | |||
decodeRec(_, _) -> | |||
{{}, <<>>}. | |||
decodeBin(1, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
{test, V1}; | |||
decodeBin(2, LeftBin0) -> | |||
<<IsUndef1:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
case IsUndef1 of | |||
0 -> | |||
V1 = undefined, | |||
LeftBin2 = LeftBin1 ; | |||
_ -> | |||
{V1, LeftBin2} = decodeRec(1, LeftBin1) | |||
end, | |||
<<V2:32/big-signed, LeftBin3/binary>> = LeftBin2, | |||
{phoneNumber, V1, V2}; | |||
decodeBin(3, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
<<Len2:16/big-unsigned, TemStrV3:Len2/binary, LeftBin3/binary>> = LeftBin2, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V3 = TemStrV3; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V3 = binary:copy(TemStrV3); | |||
_ -> | |||
V3 = TemStrV3 | |||
end | |||
end, | |||
<<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3, | |||
{V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []), | |||
{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}; | |||
decodeBin(5, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
{union, V1, V2}; | |||
decodeBin(6, LeftBin0) -> | |||
<<Bool1:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
V1 = Bool1 =:= 1, | |||
{tbool, V1}; | |||
decodeBin(7, LeftBin0) -> | |||
<<V1:8/big-signed, V2:8/big-signed, LeftBin1/binary>> = LeftBin0, | |||
{tint8, V1, V2}; | |||
decodeBin(8, LeftBin0) -> | |||
<<V1:8/big-unsigned, V2:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{tuint8, V1, V2}; | |||
decodeBin(9, LeftBin0) -> | |||
<<V1:16/big-signed, V2:16/big-signed, LeftBin1/binary>> = LeftBin0, | |||
{tint16, V1, V2}; | |||
decodeBin(10, LeftBin0) -> | |||
<<V1:16/big-unsigned, V2:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{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}; | |||
decodeBin(12, LeftBin0) -> | |||
<<V1:32/big-unsigned, V2:32/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{tuint32, V1, V2}; | |||
decodeBin(13, LeftBin0) -> | |||
<<V1:64/big-signed, V2:64/big-signed, LeftBin1/binary>> = LeftBin0, | |||
{tint64, V1, V2}; | |||
decodeBin(14, LeftBin0) -> | |||
<<V1:64/big-unsigned, V2:64/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{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}; | |||
decodeBin(16, LeftBin0) -> | |||
<<NumBits1:8, LeftBin1/binary>> = LeftBin0, | |||
case NumBits1 of | |||
33-> | |||
<<V1:32/big-float, LeftBin2/binary>> = LeftBin1; | |||
65 -> | |||
<<V1:64/big-float, LeftBin2/binary>> = LeftBin1; | |||
_ -> | |||
<<V1:NumBits1/big-signed, LeftBin2/binary>> = LeftBin1 | |||
end, | |||
<<NumBits2:8, LeftBin3/binary>> = LeftBin2, | |||
case NumBits2 of | |||
33-> | |||
<<V2:32/big-float, LeftBin4/binary>> = LeftBin3; | |||
65 -> | |||
<<V2:64/big-float, LeftBin4/binary>> = LeftBin3; | |||
_ -> | |||
<<V2:NumBits2/big-signed, LeftBin4/binary>> = LeftBin3 | |||
end, | |||
<<NumBits3:8, LeftBin5/binary>> = LeftBin4, | |||
case NumBits3 of | |||
33-> | |||
<<V3:32/big-float, LeftBin6/binary>> = LeftBin5; | |||
65 -> | |||
<<V3:64/big-float, LeftBin6/binary>> = LeftBin5; | |||
_ -> | |||
<<V3:NumBits3/big-signed, LeftBin6/binary>> = LeftBin5 | |||
end, | |||
<<NumBits4:8, LeftBin7/binary>> = LeftBin6, | |||
case NumBits4 of | |||
33-> | |||
<<V4:32/big-float, LeftBin8/binary>> = LeftBin7; | |||
65 -> | |||
<<V4:64/big-float, LeftBin8/binary>> = LeftBin7; | |||
_ -> | |||
<<V4:NumBits4/big-signed, LeftBin8/binary>> = LeftBin7 | |||
end, | |||
<<NumBits5:8, LeftBin9/binary>> = LeftBin8, | |||
case NumBits5 of | |||
33-> | |||
<<V5:32/big-float, LeftBin10/binary>> = LeftBin9; | |||
65 -> | |||
<<V5:64/big-float, LeftBin10/binary>> = LeftBin9; | |||
_ -> | |||
<<V5:NumBits5/big-signed, LeftBin10/binary>> = LeftBin9 | |||
end, | |||
<<NumBits6:8, LeftBin11/binary>> = LeftBin10, | |||
case NumBits6 of | |||
33-> | |||
<<V6:32/big-float, LeftBin12/binary>> = LeftBin11; | |||
65 -> | |||
<<V6:64/big-float, LeftBin12/binary>> = LeftBin11; | |||
_ -> | |||
<<V6:NumBits6/big-signed, LeftBin12/binary>> = LeftBin11 | |||
end, | |||
<<NumBits7:8, LeftBin13/binary>> = LeftBin12, | |||
case NumBits7 of | |||
33-> | |||
<<V7:32/big-float, LeftBin14/binary>> = LeftBin13; | |||
65 -> | |||
<<V7:64/big-float, LeftBin14/binary>> = LeftBin13; | |||
_ -> | |||
<<V7:NumBits7/big-signed, LeftBin14/binary>> = LeftBin13 | |||
end, | |||
<<NumBits8:8, LeftBin15/binary>> = LeftBin14, | |||
case NumBits8 of | |||
33-> | |||
<<V8:32/big-float, LeftBin16/binary>> = LeftBin15; | |||
65 -> | |||
<<V8:64/big-float, LeftBin16/binary>> = LeftBin15; | |||
_ -> | |||
<<V8:NumBits8/big-signed, LeftBin16/binary>> = LeftBin15 | |||
end, | |||
<<NumBits9:8, LeftBin17/binary>> = LeftBin16, | |||
case NumBits9 of | |||
33-> | |||
<<V9:32/big-float, LeftBin18/binary>> = LeftBin17; | |||
65 -> | |||
<<V9:64/big-float, LeftBin18/binary>> = LeftBin17; | |||
_ -> | |||
<<V9:NumBits9/big-signed, LeftBin18/binary>> = LeftBin17 | |||
end, | |||
<<NumBits10:8, LeftBin19/binary>> = LeftBin18, | |||
case NumBits10 of | |||
33-> | |||
<<V10:32/big-float, LeftBin20/binary>> = LeftBin19; | |||
65 -> | |||
<<V10:64/big-float, LeftBin20/binary>> = LeftBin19; | |||
_ -> | |||
<<V10:NumBits10/big-signed, LeftBin20/binary>> = LeftBin19 | |||
end, | |||
{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}; | |||
decodeBin(18, LeftBin0) -> | |||
<<V1:64/big-float, V2:64/big-float, LeftBin1/binary>> = LeftBin0, | |||
{tdouble, V1, V2}; | |||
decodeBin(19, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<Len2:16/big-unsigned, TemStrV2:Len2/binary, LeftBin2/binary>> = LeftBin1, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V2 = TemStrV2; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V2 = binary:copy(TemStrV2); | |||
_ -> | |||
V2 = TemStrV2 | |||
end | |||
end, | |||
{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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
decodeBin(29, LeftBin0) -> | |||
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{V1, LeftBin2} = deIntegerList(Len1, LeftBin1, []), | |||
{tlistinteger, V1}; | |||
decodeBin(30, LeftBin0) -> | |||
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{V1, LeftBin2} = deNumberList(Len1, LeftBin1, []), | |||
{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}; | |||
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}; | |||
decodeBin(33, LeftBin0) -> | |||
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
{V1, LeftBin2} = deStringList(Len1, LeftBin1, RefSize, []), | |||
{tliststring, V1}; | |||
decodeBin(34, LeftBin0) -> | |||
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{V1, LeftBin2} = deRecordList(Len1, 5, LeftBin1, []), | |||
{tlistunion, V1}; | |||
decodeBin(35, LeftBin0) -> | |||
<<Bool1:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
V1 = Bool1 =:= 1, | |||
<<V2:8/big-signed, V3:8/big-unsigned, V4:16/big-signed, V5:16/big-unsigned, V6:32/big-signed, V7:32/big-unsigned, V8:64/big-signed, V9:64/big-unsigned, IntBits1:8, V10:IntBits1/big-signed, IntBits2:8, V11:IntBits2/big-signed, IntBits3:8, V12:IntBits3/big-signed, IntBits4:8, V13:IntBits4/big-signed, IntBits5:8, V14:IntBits5/big-signed, IntBits6:8, V15:IntBits6/big-signed, IntBits7:8, V16:IntBits7/big-signed, IntBits8:8, V17:IntBits8/big-signed, LeftBin2/binary>> = LeftBin1, | |||
<<NumBits1:8, LeftBin3/binary>> = LeftBin2, | |||
case NumBits1 of | |||
33-> | |||
<<V18:32/big-float, LeftBin4/binary>> = LeftBin3; | |||
65 -> | |||
<<V18:64/big-float, LeftBin4/binary>> = LeftBin3; | |||
_ -> | |||
<<V18:NumBits1/big-signed, LeftBin4/binary>> = LeftBin3 | |||
end, | |||
<<NumBits2:8, LeftBin5/binary>> = LeftBin4, | |||
case NumBits2 of | |||
33-> | |||
<<V19:32/big-float, LeftBin6/binary>> = LeftBin5; | |||
65 -> | |||
<<V19:64/big-float, LeftBin6/binary>> = LeftBin5; | |||
_ -> | |||
<<V19:NumBits2/big-signed, LeftBin6/binary>> = LeftBin5 | |||
end, | |||
<<NumBits3:8, LeftBin7/binary>> = LeftBin6, | |||
case NumBits3 of | |||
33-> | |||
<<V20:32/big-float, LeftBin8/binary>> = LeftBin7; | |||
65 -> | |||
<<V20:64/big-float, LeftBin8/binary>> = LeftBin7; | |||
_ -> | |||
<<V20:NumBits3/big-signed, LeftBin8/binary>> = LeftBin7 | |||
end, | |||
<<NumBits4:8, LeftBin9/binary>> = LeftBin8, | |||
case NumBits4 of | |||
33-> | |||
<<V21:32/big-float, LeftBin10/binary>> = LeftBin9; | |||
65 -> | |||
<<V21:64/big-float, LeftBin10/binary>> = LeftBin9; | |||
_ -> | |||
<<V21:NumBits4/big-signed, LeftBin10/binary>> = LeftBin9 | |||
end, | |||
<<NumBits5:8, LeftBin11/binary>> = LeftBin10, | |||
case NumBits5 of | |||
33-> | |||
<<V22:32/big-float, LeftBin12/binary>> = LeftBin11; | |||
65 -> | |||
<<V22:64/big-float, LeftBin12/binary>> = LeftBin11; | |||
_ -> | |||
<<V22:NumBits5/big-signed, LeftBin12/binary>> = LeftBin11 | |||
end, | |||
<<NumBits6:8, LeftBin13/binary>> = LeftBin12, | |||
case NumBits6 of | |||
33-> | |||
<<V23:32/big-float, LeftBin14/binary>> = LeftBin13; | |||
65 -> | |||
<<V23:64/big-float, LeftBin14/binary>> = LeftBin13; | |||
_ -> | |||
<<V23:NumBits6/big-signed, LeftBin14/binary>> = LeftBin13 | |||
end, | |||
<<NumBits7:8, LeftBin15/binary>> = LeftBin14, | |||
case NumBits7 of | |||
33-> | |||
<<V24:32/big-float, LeftBin16/binary>> = LeftBin15; | |||
65 -> | |||
<<V24:64/big-float, LeftBin16/binary>> = LeftBin15; | |||
_ -> | |||
<<V24:NumBits7/big-signed, LeftBin16/binary>> = LeftBin15 | |||
end, | |||
<<NumBits8:8, LeftBin17/binary>> = LeftBin16, | |||
case NumBits8 of | |||
33-> | |||
<<V25:32/big-float, LeftBin18/binary>> = LeftBin17; | |||
65 -> | |||
<<V25:64/big-float, LeftBin18/binary>> = LeftBin17; | |||
_ -> | |||
<<V25:NumBits8/big-signed, LeftBin18/binary>> = LeftBin17 | |||
end, | |||
<<NumBits9:8, LeftBin19/binary>> = LeftBin18, | |||
case NumBits9 of | |||
33-> | |||
<<V26:32/big-float, LeftBin20/binary>> = LeftBin19; | |||
65 -> | |||
<<V26:64/big-float, LeftBin20/binary>> = LeftBin19; | |||
_ -> | |||
<<V26:NumBits9/big-signed, LeftBin20/binary>> = LeftBin19 | |||
end, | |||
<<NumBits10:8, LeftBin21/binary>> = LeftBin20, | |||
case NumBits10 of | |||
33-> | |||
<<V27:32/big-float, LeftBin22/binary>> = LeftBin21; | |||
65 -> | |||
<<V27:64/big-float, LeftBin22/binary>> = LeftBin21; | |||
_ -> | |||
<<V27:NumBits10/big-signed, LeftBin22/binary>> = LeftBin21 | |||
end, | |||
<<V28:32/big-float, V29:64/big-float, LeftBin23/binary>> = LeftBin22, | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV30:Len1/binary, LeftBin24/binary>> = LeftBin23, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V30 = TemStrV30; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V30 = binary:copy(TemStrV30); | |||
_ -> | |||
V30 = TemStrV30 | |||
end | |||
end, | |||
<<Len2:16/big-unsigned, TemStrV31:Len2/binary, LeftBin25/binary>> = LeftBin24, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V31 = TemStrV31; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V31 = binary:copy(TemStrV31); | |||
_ -> | |||
V31 = TemStrV31 | |||
end | |||
end, | |||
<<IsUndef1:8/big-unsigned, LeftBin26/binary>> = LeftBin25, | |||
case IsUndef1 of | |||
0 -> | |||
V32 = undefined, | |||
LeftBin27 = LeftBin26 ; | |||
_ -> | |||
{V32, LeftBin27} = decodeRec(5, LeftBin26) | |||
end, | |||
<<Len3:16/big-unsigned, LeftBin28/binary>> = LeftBin27, | |||
<<ListBin1:Len3/big-binary-unit:8, LeftBin29/binary>> = LeftBin28, | |||
V33 = [TemV =:= 1 || <<TemV:8/big-unsigned>> <= ListBin1], | |||
<<Len4:16/big-unsigned, LeftBin30/binary>> = LeftBin29, | |||
<<ListBin2:Len4/big-binary-unit:8, LeftBin31/binary>> = LeftBin30, | |||
V34 = [TemV || <<TemV:8/big-signed>> <= ListBin2], | |||
<<Len5:16/big-unsigned, LeftBin32/binary>> = LeftBin31, | |||
<<ListBin3:Len5/big-binary-unit:8, LeftBin33/binary>> = LeftBin32, | |||
V35 = [TemV || <<TemV:8/big-unsigned>> <= ListBin3], | |||
<<Len6:16/big-unsigned, LeftBin34/binary>> = LeftBin33, | |||
<<ListBin4:Len6/big-binary-unit:16, LeftBin35/binary>> = LeftBin34, | |||
V36 = [TemV || <<TemV:16/big-signed>> <= ListBin4], | |||
<<Len7:16/big-unsigned, LeftBin36/binary>> = LeftBin35, | |||
<<ListBin5:Len7/big-binary-unit:16, LeftBin37/binary>> = LeftBin36, | |||
V37 = [TemV || <<TemV:16/big-unsigned>> <= ListBin5], | |||
<<Len8:16/big-unsigned, LeftBin38/binary>> = LeftBin37, | |||
<<ListBin6:Len8/big-binary-unit:32, LeftBin39/binary>> = LeftBin38, | |||
V38 = [TemV || <<TemV:32/big-signed>> <= ListBin6], | |||
<<Len9:16/big-unsigned, LeftBin40/binary>> = LeftBin39, | |||
<<ListBin7:Len9/big-binary-unit:32, LeftBin41/binary>> = LeftBin40, | |||
V39 = [TemV || <<TemV:32/big-unsigned>> <= ListBin7], | |||
<<Len10:16/big-unsigned, LeftBin42/binary>> = LeftBin41, | |||
<<ListBin8:Len10/big-binary-unit:64, LeftBin43/binary>> = LeftBin42, | |||
V40 = [TemV || <<TemV:64/big-signed>> <= ListBin8], | |||
<<Len11:16/big-unsigned, LeftBin44/binary>> = LeftBin43, | |||
<<ListBin9:Len11/big-binary-unit:64, LeftBin45/binary>> = LeftBin44, | |||
V41 = [TemV || <<TemV:64/big-unsigned>> <= ListBin9], | |||
<<Len12:16/big-unsigned, LeftBin46/binary>> = LeftBin45, | |||
{V42, LeftBin47} = deIntegerList(Len12, LeftBin46, []), | |||
<<Len13:16/big-unsigned, LeftBin48/binary>> = LeftBin47, | |||
{V43, LeftBin49} = deIntegerList(Len13, LeftBin48, []), | |||
<<Len14:16/big-unsigned, LeftBin50/binary>> = LeftBin49, | |||
{V44, LeftBin51} = deIntegerList(Len14, LeftBin50, []), | |||
<<Len15:16/big-unsigned, LeftBin52/binary>> = LeftBin51, | |||
{V45, LeftBin53} = deIntegerList(Len15, LeftBin52, []), | |||
<<Len16:16/big-unsigned, LeftBin54/binary>> = LeftBin53, | |||
{V46, LeftBin55} = deNumberList(Len16, LeftBin54, []), | |||
<<Len17:16/big-unsigned, LeftBin56/binary>> = LeftBin55, | |||
{V47, LeftBin57} = deNumberList(Len17, LeftBin56, []), | |||
<<Len18:16/big-unsigned, LeftBin58/binary>> = LeftBin57, | |||
{V48, LeftBin59} = deNumberList(Len18, LeftBin58, []), | |||
<<Len19:16/big-unsigned, LeftBin60/binary>> = LeftBin59, | |||
{V49, LeftBin61} = deNumberList(Len19, LeftBin60, []), | |||
<<Len20:16/big-unsigned, LeftBin62/binary>> = LeftBin61, | |||
{V50, LeftBin63} = deNumberList(Len20, LeftBin62, []), | |||
<<Len21:16/big-unsigned, LeftBin64/binary>> = LeftBin63, | |||
{V51, LeftBin65} = deNumberList(Len21, LeftBin64, []), | |||
<<Len22:16/big-unsigned, LeftBin66/binary>> = LeftBin65, | |||
<<ListBin20:Len22/big-binary-unit:32, LeftBin67/binary>> = LeftBin66, | |||
V52 = [TemV || <<TemV:32/big-float>> <= ListBin20], | |||
<<Len23:16/big-unsigned, LeftBin68/binary>> = LeftBin67, | |||
<<ListBin21:Len23/big-binary-unit:64, LeftBin69/binary>> = LeftBin68, | |||
V53 = [TemV || <<TemV:64/big-float>> <= ListBin21], | |||
<<Len24:16/big-unsigned, LeftBin70/binary>> = LeftBin69, | |||
{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}; | |||
decodeBin(1001, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
<<Len2:16/big-unsigned, TemStrV3:Len2/binary, LeftBin3/binary>> = LeftBin2, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V3 = TemStrV3; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V3 = binary:copy(TemStrV3); | |||
_ -> | |||
V3 = TemStrV3 | |||
end | |||
end, | |||
<<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3, | |||
{V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []), | |||
{person1, V1, V2, V3, V4}; | |||
decodeBin(_, _) -> | |||
{{}, <<>>}. | |||
@ -0,0 +1,226 @@ | |||
-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(). | |||
-define(ERR1, 1). %% 辅导费 | |||
-define(ERR2, 2). %% 444 | |||
-define(ERR3, 3). %% 辅导费 | |||
-define(ERR4, 4). %% dfsf | |||
-define(ERR5, 5). %% 其他注释辅导费 err6:dfff | |||
-define(ERR7, 6). %% def | |||
-define(ERR8, 7). %% 其他注释辅导费 | |||
-define(ERR6, 1001). %% dfff | |||
-record(test, { | |||
aa = "" :: string() | |||
}). | |||
-record(phoneNumber, { | |||
number = undefined :: #test{} | |||
, type = 0 :: int32() | |||
}). | |||
-record(person, { | |||
name = "" :: string() | |||
, id = 0 :: int32() | |||
, email = "" :: string() | |||
, phone = [] :: [#phoneNumber{}] | |||
}). | |||
-record(addressBook, { | |||
person = [] :: [#person{}] | |||
, other = [] :: [#person{}] | |||
}). | |||
-record(union, { | |||
test = "" :: string() | |||
, type = 0 :: int32() | |||
}). | |||
-record(tbool, { | |||
bool = false :: boolean() | |||
}). | |||
-record(tint8, { | |||
int1 = 0 :: int8() | |||
, int2 = 0 :: int8() | |||
}). | |||
-record(tuint8, { | |||
int1 = 0 :: uint8() | |||
, int2 = 0 :: uint8() | |||
}). | |||
-record(tint16, { | |||
int1 = 0 :: int16() | |||
, int2 = 0 :: int16() | |||
}). | |||
-record(tuint16, { | |||
int1 = 0 :: uint16() | |||
, int2 = 0 :: uint16() | |||
}). | |||
-record(tint32, { | |||
int1 = 0 :: int32() | |||
, int2 = 0 :: int32() | |||
, int3 = 0 :: int32() | |||
, int4 = 0 :: int32() | |||
, int5 = 0 :: int32() | |||
, int6 = 0 :: int32() | |||
, int7 = 0 :: int32() | |||
, int8 = 0 :: int32() | |||
, int9 = 0 :: int32() | |||
, int10 = 0 :: int32() | |||
}). | |||
-record(tuint32, { | |||
int1 = 0 :: uint32() | |||
, int2 = 0 :: uint32() | |||
}). | |||
-record(tint64, { | |||
int1 = 0 :: int64() | |||
, int2 = 0 :: int64() | |||
}). | |||
-record(tuint64, { | |||
int1 = 0 :: uint64() | |||
, int2 = 0 :: uint64() | |||
}). | |||
-record(tinteger, { | |||
int1 = 0 :: integer() | |||
, int2 = 0 :: integer() | |||
, int3 = 0 :: integer() | |||
, int4 = 0 :: integer() | |||
, int5 = 0 :: integer() | |||
, int6 = 0 :: integer() | |||
, int7 = 0 :: integer() | |||
, int8 = 0 :: integer() | |||
}). | |||
-record(tnumber, { | |||
int1 = 0 :: number() | |||
, int2 = 0 :: number() | |||
, int3 = 0 :: number() | |||
, int4 = 0 :: number() | |||
, int5 = 0 :: number() | |||
, int6 = 0 :: number() | |||
, int7 = 0 :: number() | |||
, int8 = 0 :: number() | |||
, float1 = 0 :: number() | |||
, float2 = 0 :: number() | |||
}). | |||
-record(tfloat, { | |||
int1 = 0.0 :: float() | |||
, int2 = 0.0 :: float() | |||
}). | |||
-record(tdouble, { | |||
int1 = 0.0 :: double() | |||
, int2 = 0.0 :: double() | |||
}). | |||
-record(tstring, { | |||
int1 = "" :: string() | |||
, int2 = "" :: string() | |||
}). | |||
-record(tlistbool, { | |||
int1 = [] :: [boolean()] | |||
}). | |||
-record(tlistint8, { | |||
int1 = [] :: [int8()] | |||
}). | |||
-record(tlistuint8, { | |||
int1 = [] :: [uint8()] | |||
}). | |||
-record(tlistint16, { | |||
int1 = [] :: [int16()] | |||
}). | |||
-record(tlistuint16, { | |||
int1 = [] :: [uint16()] | |||
}). | |||
-record(tlistint32, { | |||
int1 = [] :: [int32()] | |||
}). | |||
-record(tlistuint32, { | |||
int1 = [] :: [uint32()] | |||
}). | |||
-record(tlistint64, { | |||
int1 = [] :: [int64()] | |||
}). | |||
-record(tlistuint64, { | |||
int1 = [] :: [uint64()] | |||
}). | |||
-record(tlistinteger, { | |||
int1 = [] :: [integer()] | |||
}). | |||
-record(tlistnumber, { | |||
int1 = [] :: [number()] | |||
}). | |||
-record(tlistfloat, { | |||
int1 = [] :: [float()] | |||
}). | |||
-record(tlistdouble, { | |||
int1 = [] :: [double()] | |||
}). | |||
-record(tliststring, { | |||
int1 = [] :: [string()] | |||
}). | |||
-record(tlistunion, { | |||
int1 = [] :: [#union{}] | |||
}). | |||
-record(allType, { | |||
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() | |||
, inte8 = 0 :: integer() | |||
, uinte8 = 0 :: integer() | |||
, inte16 = 0 :: integer() | |||
, uinte16 = 0 :: integer() | |||
, inte32 = 0 :: integer() | |||
, uinte32 = 0 :: integer() | |||
, inte64 = 0 :: integer() | |||
, uinte64 = 0 :: integer() | |||
, num8 = 0 :: number() | |||
, unum8 = 0 :: number() | |||
, num16 = 0 :: number() | |||
, unum16 = 0 :: number() | |||
, num32 = 0 :: number() | |||
, unum32 = 0 :: number() | |||
, num64 = 0 :: number() | |||
, unum64 = 0 :: number() | |||
, numfloat = 0 :: number() | |||
, numdouble = 0 :: number() | |||
, float = 0.0 :: float() | |||
, double = 0.0 :: double() | |||
, string1 = "" :: string() | |||
, string2 = "" :: string() | |||
, union = undefined :: #union{} | |||
, lbool = [] :: [boolean()] | |||
, lint8 = [] :: [int8()] | |||
, luint8 = [] :: [uint8()] | |||
, lint16 = [] :: [int16()] | |||
, luint16 = [] :: [uint16()] | |||
, lint32 = [] :: [int32()] | |||
, luint32 = [] :: [uint32()] | |||
, lint64 = [] :: [int64()] | |||
, luint64 = [] :: [uint64()] | |||
, linte8 = [] :: [integer()] | |||
, linte16 = [] :: [integer()] | |||
, linte32 = [] :: [integer()] | |||
, linte64 = [] :: [integer()] | |||
, lnum8 = [] :: [number()] | |||
, lnum16 = [] :: [number()] | |||
, lnum32 = [] :: [number()] | |||
, lnum64 = [] :: [number()] | |||
, lnfloat32 = [] :: [number()] | |||
, lnfloat64 = [] :: [number()] | |||
, lfloat = [] :: [float()] | |||
, ldouble = [] :: [double()] | |||
, lstring = [] :: [string()] | |||
, lunion = [] :: [#union{}] | |||
}). | |||
-record(person1, { | |||
name = "" :: string() | |||
, id = 0 :: int32() | |||
, email = "" :: string() | |||
, phone = [] :: [#phoneNumber{}] | |||
}). |
@ -0,0 +1,672 @@ | |||
-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). |
@ -0,0 +1,672 @@ | |||
-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). |
@ -0,0 +1,842 @@ | |||
-module(protoMsg). | |||
-compile([nowarn_unused_vars]). | |||
-export([encode/1, decode/1, encodeRec/1, decodeBin/2]). | |||
-define(min8, -128). | |||
-define(max8, 127). | |||
-define(min16, -32768). | |||
-define(max16, 32767). | |||
-define(min32, -2147483648). | |||
-define(max32, 2147483647). | |||
-define(min64, -9223372036854775808). | |||
-define(max64, 9223372036854775807). | |||
-define(minF32, -3.4E+38). | |||
-define(maxF32, 3.4E+38). | |||
-define(minF64, -1.797E-308). | |||
-define(maxF64, 1.797E+308). | |||
-define(int8(V), <<V:8>>). | |||
-define(uint8(V), <<V:8>>). | |||
-define(int16(V), <<V:16/big>>). | |||
-define(uint16(V), <<V:16/big>>). | |||
-define(int32(V), <<V:32/big>>). | |||
-define(uint32(V), <<V:32/big>>). | |||
-define(int64(V), <<V:64/big>>). | |||
-define(uint64(V), <<V:64/big>>). | |||
-define(integer(V), (integer(V))). | |||
-define(number(V), (number(V))). | |||
-define(string(V), (string(V))). | |||
-define(float(V), <<V:32/big-float>>). | |||
-define(double(V), <<V:64/big-float>>). | |||
-define(bool(V), (case V of true -> <<1:8>>; _ -> <<0:8>> end)). | |||
-define(record(V), (case V of undefined -> [<<0:8>>]; V -> [<<1:8>>, encodeRec(V)] end)). | |||
-define(list_bool(List), [<<(length(List)):16/big>>, [?bool(V) || V <- List]]). | |||
-define(list_int8(List), [<<(length(List)):16/big>>, [?int8(V) || V <- List]]). | |||
-define(list_uint8(List), [<<(length(List)):16/big>>, [?uint8(V) || V <- List]]). | |||
-define(list_int16(List), [<<(length(List)):16/big>>, [?int16(V) || V <- List]]). | |||
-define(list_uint16(List), [<<(length(List)):16/big>>, [?uint16(V) || V <- List]]). | |||
-define(list_int32(List), [<<(length(List)):16/big>>, [?int32(V) || V <- List]]). | |||
-define(list_uint32(List), [<<(length(List)):16/big>>, [?uint32(V) || V <- List]]). | |||
-define(list_int64(List), [<<(length(List)):16/big>>, [?int64(V) || V <- List]]). | |||
-define(list_uint64(List), [<<(length(List)):16/big>>, [?uint64(V) || V <- List]]). | |||
-define(list_float(List), [<<(length(List)):16/big>>, [?float(V) || V <- List]]). | |||
-define(list_double(List), [<<(length(List)):16/big>>, [?double(V) || V <- List]]). | |||
-define(list_integer(List), [<<(length(List)):16/big>>, [integer(V) || V <- List]]). | |||
-define(list_number(List), [<<(length(List)):16/big>>, [number(V) || V <- List]]). | |||
-define(list_string(List), [<<(length(List)):16/big>>, [string(V) || V <- List]]). | |||
-define(list_record(List), [<<(length(List)):16/big>>, [encodeRec(V) || V <- List]]). | |||
-define(BinaryShareSize, 65). | |||
-define(BinaryCopyRatio, 1.2). | |||
integer(V) -> | |||
if | |||
V >= ?min8 andalso V =< ?max8 -> | |||
<<8:8, <<V:8>>/binary>>; | |||
V >= ?min16 andalso V =< ?max16 -> | |||
<<16:8, <<V:16/big>>/binary>>; | |||
V >= ?min32 andalso V =< ?max32 -> | |||
<<32:8, <<V:32/big>>/binary>>; | |||
V >= ?min64 andalso V =< ?max64 -> | |||
<<64:8, <<V:64/big>>/binary>>; | |||
true -> | |||
throw(exceeded_the_integer) | |||
end. | |||
number(V) -> | |||
if | |||
erlang:is_integer(V) -> | |||
if | |||
V >= ?min8 andalso V =< ?max8 -> | |||
<<8:8, <<V:8>>/binary>>; | |||
V >= ?min16 andalso V =< ?max16 -> | |||
<<16:8, <<V:16/big>>/binary>>; | |||
V >= ?min32 andalso V =< ?max32 -> | |||
<<32:8, <<V:32/big>>/binary>>; | |||
V >= ?min64 andalso V =< ?max64 -> | |||
<<64:8, <<V:64/big>>/binary>>; | |||
true -> | |||
throw(exceeded_the_integer) | |||
end; | |||
erlang:is_float(V) -> | |||
if | |||
V >= ?minF32 andalso V =< ?maxF32 -> | |||
<<33:8, <<V:32/big-float>>/binary>>; | |||
V >= ?minF64 andalso V =< ?maxF64 -> | |||
<<65:8, <<V:64/big-float>>/binary>>; | |||
true -> | |||
throw(exceeded_the_float) | |||
end; | |||
true -> | |||
throw(is_not_number) | |||
end. | |||
string(Str) when is_binary(Str) -> | |||
[<<(byte_size(Str)):16/big>>, Str]; | |||
string(Str) -> | |||
Str2 = unicode:characters_to_binary(Str, utf8), | |||
[<<(byte_size(Str2)):16/big>>, Str2]. | |||
decode(Bin) -> | |||
<<MsgId:16/big, MsgBin/binary>> = Bin, | |||
decodeBin(MsgId, MsgBin). | |||
deIntegerList(0, MsgBin, RetList) -> | |||
{lists:reverse(RetList), MsgBin}; | |||
deIntegerList(N, MsgBin, RetList) -> | |||
<<IntBits:8, Int:IntBits/big-signed, LeftBin/binary>> = MsgBin, | |||
deIntegerList(N - 1, LeftBin, [Int | RetList]). | |||
deNumberList(0, MsgBin, RetList) -> | |||
{lists:reverse(RetList), MsgBin}; | |||
deNumberList(N, MsgBin, RetList) -> | |||
<<NumBits:8, NumBin/binary>> = MsgBin, | |||
case NumBits of | |||
33 -> | |||
<<Float:32/big-float, LeftBin/binary>> = NumBin, | |||
deNumberList(N - 1, LeftBin, [Float | RetList]); | |||
65 -> | |||
<<Float:64/big-float, LeftBin/binary>> = NumBin, | |||
deNumberList(N - 1, LeftBin, [Float | RetList]); | |||
_ -> | |||
<<Int:NumBits/big-signed, LeftBin/binary>> = NumBin, | |||
deNumberList(N - 1, LeftBin, [Int | RetList]) | |||
end. | |||
deStringList(0, MsgBin, _RefSize, RetList) -> | |||
{lists:reverse(RetList), MsgBin}; | |||
deStringList(N, MsgBin, RefSize, RetList) -> | |||
<<Len:16/big, StrBin:Len/binary-unit:8, LeftBin/binary>> = MsgBin, | |||
case Len < ?BinaryShareSize of | |||
true -> | |||
deStringList(N - 1, LeftBin, RefSize, [StrBin | RetList]); | |||
_ -> | |||
case RefSize / Len > ?BinaryCopyRatio of | |||
true -> | |||
StrBinCopy = binary:copy(StrBin), | |||
deStringList(N - 1, LeftBin, RefSize, [StrBinCopy | RetList]); | |||
_ -> | |||
deStringList(N - 1, LeftBin, RefSize, [StrBin | RetList]) | |||
end | |||
end. | |||
deRecordList(0, _MsgId, MsgBin, RetList) -> | |||
{lists:reverse(RetList), MsgBin}; | |||
deRecordList(N, MsgId, MsgBin, RetList) -> | |||
{Tuple, LeftBin} = decodeRec(MsgId, MsgBin), | |||
deRecordList(N - 1, MsgId, LeftBin, [Tuple | RetList]). | |||
encodeRec({test, V1}) -> | |||
[?string(V1)]; | |||
encodeRec({phoneNumber, V1, V2}) -> | |||
[?record(V1), ?int32(V2)]; | |||
encodeRec({person, V1, V2, V3, V4}) -> | |||
[?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)]; | |||
encodeRec({union, V1, V2}) -> | |||
[?string(V1), ?int32(V2)]; | |||
encodeRec(_) -> | |||
[]. | |||
encode({test, V1}) -> | |||
[<<1:16/big-unsigned>>, ?string(V1)]; | |||
encode({phoneNumber, V1, V2}) -> | |||
[<<2:16/big-unsigned>>, ?record(V1), ?int32(V2)]; | |||
encode({person, V1, V2, V3, V4}) -> | |||
[<<3:16/big-unsigned>>, ?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)]; | |||
encode({addressBook, V1, V2}) -> | |||
[<<4:16/big-unsigned>>, ?list_record(V1), ?list_record(V2)]; | |||
encode({union, V1, V2}) -> | |||
[<<5:16/big-unsigned>>, ?string(V1), ?int32(V2)]; | |||
encode({tbool, V1}) -> | |||
[<<6:16/big-unsigned>>, ?bool(V1)]; | |||
encode({tint8, V1, V2}) -> | |||
[<<7:16/big-unsigned>>, ?int8(V1), ?int8(V2)]; | |||
encode({tuint8, V1, V2}) -> | |||
[<<8:16/big-unsigned>>, ?uint8(V1), ?uint8(V2)]; | |||
encode({tint16, V1, V2}) -> | |||
[<<9:16/big-unsigned>>, ?int16(V1), ?int16(V2)]; | |||
encode({tuint16, V1, V2}) -> | |||
[<<10:16/big-unsigned>>, ?uint16(V1), ?uint16(V2)]; | |||
encode({tint32, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10}) -> | |||
[<<11:16/big-unsigned>>, ?int32(V1), ?int32(V2), ?int32(V3), ?int32(V4), ?int32(V5), ?int32(V6), ?int32(V7), ?int32(V8), ?int32(V9), ?int32(V10)]; | |||
encode({tuint32, V1, V2}) -> | |||
[<<12:16/big-unsigned>>, ?uint32(V1), ?uint32(V2)]; | |||
encode({tint64, V1, V2}) -> | |||
[<<13:16/big-unsigned>>, ?int64(V1), ?int64(V2)]; | |||
encode({tuint64, V1, V2}) -> | |||
[<<14:16/big-unsigned>>, ?uint64(V1), ?uint64(V2)]; | |||
encode({tinteger, V1, V2, V3, V4, V5, V6, V7, V8}) -> | |||
[<<15:16/big-unsigned>>, ?integer(V1), ?integer(V2), ?integer(V3), ?integer(V4), ?integer(V5), ?integer(V6), ?integer(V7), ?integer(V8)]; | |||
encode({tnumber, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10}) -> | |||
[<<16:16/big-unsigned>>, ?number(V1), ?number(V2), ?number(V3), ?number(V4), ?number(V5), ?number(V6), ?number(V7), ?number(V8), ?number(V9), ?number(V10)]; | |||
encode({tfloat, V1, V2}) -> | |||
[<<17:16/big-unsigned>>, ?float(V1), ?float(V2)]; | |||
encode({tdouble, V1, V2}) -> | |||
[<<18:16/big-unsigned>>, ?double(V1), ?double(V2)]; | |||
encode({tstring, V1, V2}) -> | |||
[<<19:16/big-unsigned>>, ?string(V1), ?string(V2)]; | |||
encode({tlistbool, V1}) -> | |||
[<<20:16/big-unsigned>>, ?list_bool(V1)]; | |||
encode({tlistint8, V1}) -> | |||
[<<21:16/big-unsigned>>, ?list_int8(V1)]; | |||
encode({tlistuint8, V1}) -> | |||
[<<22:16/big-unsigned>>, ?list_uint8(V1)]; | |||
encode({tlistint16, V1}) -> | |||
[<<23:16/big-unsigned>>, ?list_int16(V1)]; | |||
encode({tlistuint16, V1}) -> | |||
[<<24:16/big-unsigned>>, ?list_uint16(V1)]; | |||
encode({tlistint32, V1}) -> | |||
[<<25:16/big-unsigned>>, ?list_int32(V1)]; | |||
encode({tlistuint32, V1}) -> | |||
[<<26:16/big-unsigned>>, ?list_uint32(V1)]; | |||
encode({tlistint64, V1}) -> | |||
[<<27:16/big-unsigned>>, ?list_int64(V1)]; | |||
encode({tlistuint64, V1}) -> | |||
[<<28:16/big-unsigned>>, ?list_uint64(V1)]; | |||
encode({tlistinteger, V1}) -> | |||
[<<29:16/big-unsigned>>, ?list_integer(V1)]; | |||
encode({tlistnumber, V1}) -> | |||
[<<30:16/big-unsigned>>, ?list_number(V1)]; | |||
encode({tlistfloat, V1}) -> | |||
[<<31:16/big-unsigned>>, ?list_float(V1)]; | |||
encode({tlistdouble, V1}) -> | |||
[<<32:16/big-unsigned>>, ?list_double(V1)]; | |||
encode({tliststring, V1}) -> | |||
[<<33:16/big-unsigned>>, ?list_string(V1)]; | |||
encode({tlistunion, V1}) -> | |||
[<<34:16/big-unsigned>>, ?list_record(V1)]; | |||
encode({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)]; | |||
encode({person1, V1, V2, V3, V4}) -> | |||
[<<1001:16/big-unsigned>>, ?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)]; | |||
encode(_) -> | |||
[]. | |||
decodeRec(1, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
MsgRec = {test, V1}, | |||
{MsgRec, LeftBin1}; | |||
decodeRec(2, LeftBin0) -> | |||
<<IsUndef1:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
case IsUndef1 of | |||
0 -> | |||
V1 = undefined, | |||
LeftBin2 = LeftBin1 ; | |||
_ -> | |||
{V1, LeftBin2} = decodeRec(1, LeftBin1) | |||
end, | |||
<<V2:32/big-signed, LeftBin3/binary>> = LeftBin2, | |||
MsgRec = {phoneNumber, V1, V2}, | |||
{MsgRec, LeftBin3}; | |||
decodeRec(3, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
<<Len2:16/big-unsigned, TemStrV3:Len2/binary, LeftBin3/binary>> = LeftBin2, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V3 = TemStrV3; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V3 = binary:copy(TemStrV3); | |||
_ -> | |||
V3 = TemStrV3 | |||
end | |||
end, | |||
<<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3, | |||
{V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []), | |||
MsgRec = {person, V1, V2, V3, V4}, | |||
{MsgRec, LeftBin5}; | |||
decodeRec(5, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
MsgRec = {union, V1, V2}, | |||
{MsgRec, LeftBin2}; | |||
decodeRec(_, _) -> | |||
{{}, <<>>}. | |||
decodeBin(1, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
{test, V1}; | |||
decodeBin(2, LeftBin0) -> | |||
<<IsUndef1:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
case IsUndef1 of | |||
0 -> | |||
V1 = undefined, | |||
LeftBin2 = LeftBin1 ; | |||
_ -> | |||
{V1, LeftBin2} = decodeRec(1, LeftBin1) | |||
end, | |||
<<V2:32/big-signed, LeftBin3/binary>> = LeftBin2, | |||
{phoneNumber, V1, V2}; | |||
decodeBin(3, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
<<Len2:16/big-unsigned, TemStrV3:Len2/binary, LeftBin3/binary>> = LeftBin2, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V3 = TemStrV3; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V3 = binary:copy(TemStrV3); | |||
_ -> | |||
V3 = TemStrV3 | |||
end | |||
end, | |||
<<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3, | |||
{V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []), | |||
{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}; | |||
decodeBin(5, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
{union, V1, V2}; | |||
decodeBin(6, LeftBin0) -> | |||
<<Bool1:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
V1 = Bool1 =:= 1, | |||
{tbool, V1}; | |||
decodeBin(7, LeftBin0) -> | |||
<<V1:8/big-signed, V2:8/big-signed, LeftBin1/binary>> = LeftBin0, | |||
{tint8, V1, V2}; | |||
decodeBin(8, LeftBin0) -> | |||
<<V1:8/big-unsigned, V2:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{tuint8, V1, V2}; | |||
decodeBin(9, LeftBin0) -> | |||
<<V1:16/big-signed, V2:16/big-signed, LeftBin1/binary>> = LeftBin0, | |||
{tint16, V1, V2}; | |||
decodeBin(10, LeftBin0) -> | |||
<<V1:16/big-unsigned, V2:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{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}; | |||
decodeBin(12, LeftBin0) -> | |||
<<V1:32/big-unsigned, V2:32/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{tuint32, V1, V2}; | |||
decodeBin(13, LeftBin0) -> | |||
<<V1:64/big-signed, V2:64/big-signed, LeftBin1/binary>> = LeftBin0, | |||
{tint64, V1, V2}; | |||
decodeBin(14, LeftBin0) -> | |||
<<V1:64/big-unsigned, V2:64/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{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}; | |||
decodeBin(16, LeftBin0) -> | |||
<<NumBits1:8, LeftBin1/binary>> = LeftBin0, | |||
case NumBits1 of | |||
33-> | |||
<<V1:32/big-float, LeftBin2/binary>> = LeftBin1; | |||
65 -> | |||
<<V1:64/big-float, LeftBin2/binary>> = LeftBin1; | |||
_ -> | |||
<<V1:NumBits1/big-signed, LeftBin2/binary>> = LeftBin1 | |||
end, | |||
<<NumBits2:8, LeftBin3/binary>> = LeftBin2, | |||
case NumBits2 of | |||
33-> | |||
<<V2:32/big-float, LeftBin4/binary>> = LeftBin3; | |||
65 -> | |||
<<V2:64/big-float, LeftBin4/binary>> = LeftBin3; | |||
_ -> | |||
<<V2:NumBits2/big-signed, LeftBin4/binary>> = LeftBin3 | |||
end, | |||
<<NumBits3:8, LeftBin5/binary>> = LeftBin4, | |||
case NumBits3 of | |||
33-> | |||
<<V3:32/big-float, LeftBin6/binary>> = LeftBin5; | |||
65 -> | |||
<<V3:64/big-float, LeftBin6/binary>> = LeftBin5; | |||
_ -> | |||
<<V3:NumBits3/big-signed, LeftBin6/binary>> = LeftBin5 | |||
end, | |||
<<NumBits4:8, LeftBin7/binary>> = LeftBin6, | |||
case NumBits4 of | |||
33-> | |||
<<V4:32/big-float, LeftBin8/binary>> = LeftBin7; | |||
65 -> | |||
<<V4:64/big-float, LeftBin8/binary>> = LeftBin7; | |||
_ -> | |||
<<V4:NumBits4/big-signed, LeftBin8/binary>> = LeftBin7 | |||
end, | |||
<<NumBits5:8, LeftBin9/binary>> = LeftBin8, | |||
case NumBits5 of | |||
33-> | |||
<<V5:32/big-float, LeftBin10/binary>> = LeftBin9; | |||
65 -> | |||
<<V5:64/big-float, LeftBin10/binary>> = LeftBin9; | |||
_ -> | |||
<<V5:NumBits5/big-signed, LeftBin10/binary>> = LeftBin9 | |||
end, | |||
<<NumBits6:8, LeftBin11/binary>> = LeftBin10, | |||
case NumBits6 of | |||
33-> | |||
<<V6:32/big-float, LeftBin12/binary>> = LeftBin11; | |||
65 -> | |||
<<V6:64/big-float, LeftBin12/binary>> = LeftBin11; | |||
_ -> | |||
<<V6:NumBits6/big-signed, LeftBin12/binary>> = LeftBin11 | |||
end, | |||
<<NumBits7:8, LeftBin13/binary>> = LeftBin12, | |||
case NumBits7 of | |||
33-> | |||
<<V7:32/big-float, LeftBin14/binary>> = LeftBin13; | |||
65 -> | |||
<<V7:64/big-float, LeftBin14/binary>> = LeftBin13; | |||
_ -> | |||
<<V7:NumBits7/big-signed, LeftBin14/binary>> = LeftBin13 | |||
end, | |||
<<NumBits8:8, LeftBin15/binary>> = LeftBin14, | |||
case NumBits8 of | |||
33-> | |||
<<V8:32/big-float, LeftBin16/binary>> = LeftBin15; | |||
65 -> | |||
<<V8:64/big-float, LeftBin16/binary>> = LeftBin15; | |||
_ -> | |||
<<V8:NumBits8/big-signed, LeftBin16/binary>> = LeftBin15 | |||
end, | |||
<<NumBits9:8, LeftBin17/binary>> = LeftBin16, | |||
case NumBits9 of | |||
33-> | |||
<<V9:32/big-float, LeftBin18/binary>> = LeftBin17; | |||
65 -> | |||
<<V9:64/big-float, LeftBin18/binary>> = LeftBin17; | |||
_ -> | |||
<<V9:NumBits9/big-signed, LeftBin18/binary>> = LeftBin17 | |||
end, | |||
<<NumBits10:8, LeftBin19/binary>> = LeftBin18, | |||
case NumBits10 of | |||
33-> | |||
<<V10:32/big-float, LeftBin20/binary>> = LeftBin19; | |||
65 -> | |||
<<V10:64/big-float, LeftBin20/binary>> = LeftBin19; | |||
_ -> | |||
<<V10:NumBits10/big-signed, LeftBin20/binary>> = LeftBin19 | |||
end, | |||
{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}; | |||
decodeBin(18, LeftBin0) -> | |||
<<V1:64/big-float, V2:64/big-float, LeftBin1/binary>> = LeftBin0, | |||
{tdouble, V1, V2}; | |||
decodeBin(19, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<Len2:16/big-unsigned, TemStrV2:Len2/binary, LeftBin2/binary>> = LeftBin1, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V2 = TemStrV2; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V2 = binary:copy(TemStrV2); | |||
_ -> | |||
V2 = TemStrV2 | |||
end | |||
end, | |||
{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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
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}; | |||
decodeBin(29, LeftBin0) -> | |||
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{V1, LeftBin2} = deIntegerList(Len1, LeftBin1, []), | |||
{tlistinteger, V1}; | |||
decodeBin(30, LeftBin0) -> | |||
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{V1, LeftBin2} = deNumberList(Len1, LeftBin1, []), | |||
{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}; | |||
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}; | |||
decodeBin(33, LeftBin0) -> | |||
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
{V1, LeftBin2} = deStringList(Len1, LeftBin1, RefSize, []), | |||
{tliststring, V1}; | |||
decodeBin(34, LeftBin0) -> | |||
<<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
{V1, LeftBin2} = deRecordList(Len1, 5, LeftBin1, []), | |||
{tlistunion, V1}; | |||
decodeBin(35, LeftBin0) -> | |||
<<Bool1:8/big-unsigned, LeftBin1/binary>> = LeftBin0, | |||
V1 = Bool1 =:= 1, | |||
<<V2:8/big-signed, V3:8/big-unsigned, V4:16/big-signed, V5:16/big-unsigned, V6:32/big-signed, V7:32/big-unsigned, V8:64/big-signed, V9:64/big-unsigned, IntBits1:8, V10:IntBits1/big-signed, IntBits2:8, V11:IntBits2/big-signed, IntBits3:8, V12:IntBits3/big-signed, IntBits4:8, V13:IntBits4/big-signed, IntBits5:8, V14:IntBits5/big-signed, IntBits6:8, V15:IntBits6/big-signed, IntBits7:8, V16:IntBits7/big-signed, IntBits8:8, V17:IntBits8/big-signed, LeftBin2/binary>> = LeftBin1, | |||
<<NumBits1:8, LeftBin3/binary>> = LeftBin2, | |||
case NumBits1 of | |||
33-> | |||
<<V18:32/big-float, LeftBin4/binary>> = LeftBin3; | |||
65 -> | |||
<<V18:64/big-float, LeftBin4/binary>> = LeftBin3; | |||
_ -> | |||
<<V18:NumBits1/big-signed, LeftBin4/binary>> = LeftBin3 | |||
end, | |||
<<NumBits2:8, LeftBin5/binary>> = LeftBin4, | |||
case NumBits2 of | |||
33-> | |||
<<V19:32/big-float, LeftBin6/binary>> = LeftBin5; | |||
65 -> | |||
<<V19:64/big-float, LeftBin6/binary>> = LeftBin5; | |||
_ -> | |||
<<V19:NumBits2/big-signed, LeftBin6/binary>> = LeftBin5 | |||
end, | |||
<<NumBits3:8, LeftBin7/binary>> = LeftBin6, | |||
case NumBits3 of | |||
33-> | |||
<<V20:32/big-float, LeftBin8/binary>> = LeftBin7; | |||
65 -> | |||
<<V20:64/big-float, LeftBin8/binary>> = LeftBin7; | |||
_ -> | |||
<<V20:NumBits3/big-signed, LeftBin8/binary>> = LeftBin7 | |||
end, | |||
<<NumBits4:8, LeftBin9/binary>> = LeftBin8, | |||
case NumBits4 of | |||
33-> | |||
<<V21:32/big-float, LeftBin10/binary>> = LeftBin9; | |||
65 -> | |||
<<V21:64/big-float, LeftBin10/binary>> = LeftBin9; | |||
_ -> | |||
<<V21:NumBits4/big-signed, LeftBin10/binary>> = LeftBin9 | |||
end, | |||
<<NumBits5:8, LeftBin11/binary>> = LeftBin10, | |||
case NumBits5 of | |||
33-> | |||
<<V22:32/big-float, LeftBin12/binary>> = LeftBin11; | |||
65 -> | |||
<<V22:64/big-float, LeftBin12/binary>> = LeftBin11; | |||
_ -> | |||
<<V22:NumBits5/big-signed, LeftBin12/binary>> = LeftBin11 | |||
end, | |||
<<NumBits6:8, LeftBin13/binary>> = LeftBin12, | |||
case NumBits6 of | |||
33-> | |||
<<V23:32/big-float, LeftBin14/binary>> = LeftBin13; | |||
65 -> | |||
<<V23:64/big-float, LeftBin14/binary>> = LeftBin13; | |||
_ -> | |||
<<V23:NumBits6/big-signed, LeftBin14/binary>> = LeftBin13 | |||
end, | |||
<<NumBits7:8, LeftBin15/binary>> = LeftBin14, | |||
case NumBits7 of | |||
33-> | |||
<<V24:32/big-float, LeftBin16/binary>> = LeftBin15; | |||
65 -> | |||
<<V24:64/big-float, LeftBin16/binary>> = LeftBin15; | |||
_ -> | |||
<<V24:NumBits7/big-signed, LeftBin16/binary>> = LeftBin15 | |||
end, | |||
<<NumBits8:8, LeftBin17/binary>> = LeftBin16, | |||
case NumBits8 of | |||
33-> | |||
<<V25:32/big-float, LeftBin18/binary>> = LeftBin17; | |||
65 -> | |||
<<V25:64/big-float, LeftBin18/binary>> = LeftBin17; | |||
_ -> | |||
<<V25:NumBits8/big-signed, LeftBin18/binary>> = LeftBin17 | |||
end, | |||
<<NumBits9:8, LeftBin19/binary>> = LeftBin18, | |||
case NumBits9 of | |||
33-> | |||
<<V26:32/big-float, LeftBin20/binary>> = LeftBin19; | |||
65 -> | |||
<<V26:64/big-float, LeftBin20/binary>> = LeftBin19; | |||
_ -> | |||
<<V26:NumBits9/big-signed, LeftBin20/binary>> = LeftBin19 | |||
end, | |||
<<NumBits10:8, LeftBin21/binary>> = LeftBin20, | |||
case NumBits10 of | |||
33-> | |||
<<V27:32/big-float, LeftBin22/binary>> = LeftBin21; | |||
65 -> | |||
<<V27:64/big-float, LeftBin22/binary>> = LeftBin21; | |||
_ -> | |||
<<V27:NumBits10/big-signed, LeftBin22/binary>> = LeftBin21 | |||
end, | |||
<<V28:32/big-float, V29:64/big-float, LeftBin23/binary>> = LeftBin22, | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV30:Len1/binary, LeftBin24/binary>> = LeftBin23, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V30 = TemStrV30; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V30 = binary:copy(TemStrV30); | |||
_ -> | |||
V30 = TemStrV30 | |||
end | |||
end, | |||
<<Len2:16/big-unsigned, TemStrV31:Len2/binary, LeftBin25/binary>> = LeftBin24, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V31 = TemStrV31; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V31 = binary:copy(TemStrV31); | |||
_ -> | |||
V31 = TemStrV31 | |||
end | |||
end, | |||
<<IsUndef1:8/big-unsigned, LeftBin26/binary>> = LeftBin25, | |||
case IsUndef1 of | |||
0 -> | |||
V32 = undefined, | |||
LeftBin27 = LeftBin26 ; | |||
_ -> | |||
{V32, LeftBin27} = decodeRec(5, LeftBin26) | |||
end, | |||
<<Len3:16/big-unsigned, LeftBin28/binary>> = LeftBin27, | |||
<<ListBin1:Len3/big-binary-unit:8, LeftBin29/binary>> = LeftBin28, | |||
V33 = [TemV =:= 1 || <<TemV:8/big-unsigned>> <= ListBin1], | |||
<<Len4:16/big-unsigned, LeftBin30/binary>> = LeftBin29, | |||
<<ListBin2:Len4/big-binary-unit:8, LeftBin31/binary>> = LeftBin30, | |||
V34 = [TemV || <<TemV:8/big-signed>> <= ListBin2], | |||
<<Len5:16/big-unsigned, LeftBin32/binary>> = LeftBin31, | |||
<<ListBin3:Len5/big-binary-unit:8, LeftBin33/binary>> = LeftBin32, | |||
V35 = [TemV || <<TemV:8/big-unsigned>> <= ListBin3], | |||
<<Len6:16/big-unsigned, LeftBin34/binary>> = LeftBin33, | |||
<<ListBin4:Len6/big-binary-unit:16, LeftBin35/binary>> = LeftBin34, | |||
V36 = [TemV || <<TemV:16/big-signed>> <= ListBin4], | |||
<<Len7:16/big-unsigned, LeftBin36/binary>> = LeftBin35, | |||
<<ListBin5:Len7/big-binary-unit:16, LeftBin37/binary>> = LeftBin36, | |||
V37 = [TemV || <<TemV:16/big-unsigned>> <= ListBin5], | |||
<<Len8:16/big-unsigned, LeftBin38/binary>> = LeftBin37, | |||
<<ListBin6:Len8/big-binary-unit:32, LeftBin39/binary>> = LeftBin38, | |||
V38 = [TemV || <<TemV:32/big-signed>> <= ListBin6], | |||
<<Len9:16/big-unsigned, LeftBin40/binary>> = LeftBin39, | |||
<<ListBin7:Len9/big-binary-unit:32, LeftBin41/binary>> = LeftBin40, | |||
V39 = [TemV || <<TemV:32/big-unsigned>> <= ListBin7], | |||
<<Len10:16/big-unsigned, LeftBin42/binary>> = LeftBin41, | |||
<<ListBin8:Len10/big-binary-unit:64, LeftBin43/binary>> = LeftBin42, | |||
V40 = [TemV || <<TemV:64/big-signed>> <= ListBin8], | |||
<<Len11:16/big-unsigned, LeftBin44/binary>> = LeftBin43, | |||
<<ListBin9:Len11/big-binary-unit:64, LeftBin45/binary>> = LeftBin44, | |||
V41 = [TemV || <<TemV:64/big-unsigned>> <= ListBin9], | |||
<<Len12:16/big-unsigned, LeftBin46/binary>> = LeftBin45, | |||
{V42, LeftBin47} = deIntegerList(Len12, LeftBin46, []), | |||
<<Len13:16/big-unsigned, LeftBin48/binary>> = LeftBin47, | |||
{V43, LeftBin49} = deIntegerList(Len13, LeftBin48, []), | |||
<<Len14:16/big-unsigned, LeftBin50/binary>> = LeftBin49, | |||
{V44, LeftBin51} = deIntegerList(Len14, LeftBin50, []), | |||
<<Len15:16/big-unsigned, LeftBin52/binary>> = LeftBin51, | |||
{V45, LeftBin53} = deIntegerList(Len15, LeftBin52, []), | |||
<<Len16:16/big-unsigned, LeftBin54/binary>> = LeftBin53, | |||
{V46, LeftBin55} = deNumberList(Len16, LeftBin54, []), | |||
<<Len17:16/big-unsigned, LeftBin56/binary>> = LeftBin55, | |||
{V47, LeftBin57} = deNumberList(Len17, LeftBin56, []), | |||
<<Len18:16/big-unsigned, LeftBin58/binary>> = LeftBin57, | |||
{V48, LeftBin59} = deNumberList(Len18, LeftBin58, []), | |||
<<Len19:16/big-unsigned, LeftBin60/binary>> = LeftBin59, | |||
{V49, LeftBin61} = deNumberList(Len19, LeftBin60, []), | |||
<<Len20:16/big-unsigned, LeftBin62/binary>> = LeftBin61, | |||
{V50, LeftBin63} = deNumberList(Len20, LeftBin62, []), | |||
<<Len21:16/big-unsigned, LeftBin64/binary>> = LeftBin63, | |||
{V51, LeftBin65} = deNumberList(Len21, LeftBin64, []), | |||
<<Len22:16/big-unsigned, LeftBin66/binary>> = LeftBin65, | |||
<<ListBin20:Len22/big-binary-unit:32, LeftBin67/binary>> = LeftBin66, | |||
V52 = [TemV || <<TemV:32/big-float>> <= ListBin20], | |||
<<Len23:16/big-unsigned, LeftBin68/binary>> = LeftBin67, | |||
<<ListBin21:Len23/big-binary-unit:64, LeftBin69/binary>> = LeftBin68, | |||
V53 = [TemV || <<TemV:64/big-float>> <= ListBin21], | |||
<<Len24:16/big-unsigned, LeftBin70/binary>> = LeftBin69, | |||
{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}; | |||
decodeBin(1001, LeftBin0) -> | |||
RefSize = binary:referenced_byte_size(LeftBin0), | |||
<<Len1:16/big-unsigned, TemStrV1:Len1/binary, LeftBin1/binary>> = LeftBin0, | |||
case Len1 < ?BinaryShareSize of | |||
true -> | |||
V1 = TemStrV1; | |||
_ -> | |||
case RefSize / Len1 > ?BinaryCopyRatio of | |||
true -> | |||
V1 = binary:copy(TemStrV1); | |||
_ -> | |||
V1 = TemStrV1 | |||
end | |||
end, | |||
<<V2:32/big-signed, LeftBin2/binary>> = LeftBin1, | |||
<<Len2:16/big-unsigned, TemStrV3:Len2/binary, LeftBin3/binary>> = LeftBin2, | |||
case Len2 < ?BinaryShareSize of | |||
true -> | |||
V3 = TemStrV3; | |||
_ -> | |||
case RefSize / Len2 > ?BinaryCopyRatio of | |||
true -> | |||
V3 = binary:copy(TemStrV3); | |||
_ -> | |||
V3 = TemStrV3 | |||
end | |||
end, | |||
<<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3, | |||
{V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []), | |||
{person1, V1, V2, V3, V4}; | |||
decodeBin(_, _) -> | |||
{{}, <<>>}. | |||
@ -0,0 +1,226 @@ | |||
-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(). | |||
-define(ERR1, 1). %% 辅导费 | |||
-define(ERR2, 2). %% 444 | |||
-define(ERR3, 3). %% 辅导费 | |||
-define(ERR4, 4). %% dfsf | |||
-define(ERR5, 5). %% 其他注释辅导费 err6:dfff | |||
-define(ERR7, 6). %% def | |||
-define(ERR8, 7). %% 其他注释辅导费 | |||
-define(ERR6, 1001). %% dfff | |||
-record(test, { | |||
aa = "" :: string() | |||
}). | |||
-record(phoneNumber, { | |||
number = undefined :: #test{} | |||
, type = 0 :: int32() | |||
}). | |||
-record(person, { | |||
name = "" :: string() | |||
, id = 0 :: int32() | |||
, email = "" :: string() | |||
, phone = [] :: [#phoneNumber{}] | |||
}). | |||
-record(addressBook, { | |||
person = [] :: [#person{}] | |||
, other = [] :: [#person{}] | |||
}). | |||
-record(union, { | |||
test = "" :: string() | |||
, type = 0 :: int32() | |||
}). | |||
-record(tbool, { | |||
bool = false :: boolean() | |||
}). | |||
-record(tint8, { | |||
int1 = 0 :: int8() | |||
, int2 = 0 :: int8() | |||
}). | |||
-record(tuint8, { | |||
int1 = 0 :: uint8() | |||
, int2 = 0 :: uint8() | |||
}). | |||
-record(tint16, { | |||
int1 = 0 :: int16() | |||
, int2 = 0 :: int16() | |||
}). | |||
-record(tuint16, { | |||
int1 = 0 :: uint16() | |||
, int2 = 0 :: uint16() | |||
}). | |||
-record(tint32, { | |||
int1 = 0 :: int32() | |||
, int2 = 0 :: int32() | |||
, int3 = 0 :: int32() | |||
, int4 = 0 :: int32() | |||
, int5 = 0 :: int32() | |||
, int6 = 0 :: int32() | |||
, int7 = 0 :: int32() | |||
, int8 = 0 :: int32() | |||
, int9 = 0 :: int32() | |||
, int10 = 0 :: int32() | |||
}). | |||
-record(tuint32, { | |||
int1 = 0 :: uint32() | |||
, int2 = 0 :: uint32() | |||
}). | |||
-record(tint64, { | |||
int1 = 0 :: int64() | |||
, int2 = 0 :: int64() | |||
}). | |||
-record(tuint64, { | |||
int1 = 0 :: uint64() | |||
, int2 = 0 :: uint64() | |||
}). | |||
-record(tinteger, { | |||
int1 = 0 :: integer() | |||
, int2 = 0 :: integer() | |||
, int3 = 0 :: integer() | |||
, int4 = 0 :: integer() | |||
, int5 = 0 :: integer() | |||
, int6 = 0 :: integer() | |||
, int7 = 0 :: integer() | |||
, int8 = 0 :: integer() | |||
}). | |||
-record(tnumber, { | |||
int1 = 0 :: number() | |||
, int2 = 0 :: number() | |||
, int3 = 0 :: number() | |||
, int4 = 0 :: number() | |||
, int5 = 0 :: number() | |||
, int6 = 0 :: number() | |||
, int7 = 0 :: number() | |||
, int8 = 0 :: number() | |||
, float1 = 0 :: number() | |||
, float2 = 0 :: number() | |||
}). | |||
-record(tfloat, { | |||
int1 = 0.0 :: float() | |||
, int2 = 0.0 :: float() | |||
}). | |||
-record(tdouble, { | |||
int1 = 0.0 :: double() | |||
, int2 = 0.0 :: double() | |||
}). | |||
-record(tstring, { | |||
int1 = "" :: string() | |||
, int2 = "" :: string() | |||
}). | |||
-record(tlistbool, { | |||
int1 = [] :: [boolean()] | |||
}). | |||
-record(tlistint8, { | |||
int1 = [] :: [int8()] | |||
}). | |||
-record(tlistuint8, { | |||
int1 = [] :: [uint8()] | |||
}). | |||
-record(tlistint16, { | |||
int1 = [] :: [int16()] | |||
}). | |||
-record(tlistuint16, { | |||
int1 = [] :: [uint16()] | |||
}). | |||
-record(tlistint32, { | |||
int1 = [] :: [int32()] | |||
}). | |||
-record(tlistuint32, { | |||
int1 = [] :: [uint32()] | |||
}). | |||
-record(tlistint64, { | |||
int1 = [] :: [int64()] | |||
}). | |||
-record(tlistuint64, { | |||
int1 = [] :: [uint64()] | |||
}). | |||
-record(tlistinteger, { | |||
int1 = [] :: [integer()] | |||
}). | |||
-record(tlistnumber, { | |||
int1 = [] :: [number()] | |||
}). | |||
-record(tlistfloat, { | |||
int1 = [] :: [float()] | |||
}). | |||
-record(tlistdouble, { | |||
int1 = [] :: [double()] | |||
}). | |||
-record(tliststring, { | |||
int1 = [] :: [string()] | |||
}). | |||
-record(tlistunion, { | |||
int1 = [] :: [#union{}] | |||
}). | |||
-record(allType, { | |||
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() | |||
, inte8 = 0 :: integer() | |||
, uinte8 = 0 :: integer() | |||
, inte16 = 0 :: integer() | |||
, uinte16 = 0 :: integer() | |||
, inte32 = 0 :: integer() | |||
, uinte32 = 0 :: integer() | |||
, inte64 = 0 :: integer() | |||
, uinte64 = 0 :: integer() | |||
, num8 = 0 :: number() | |||
, unum8 = 0 :: number() | |||
, num16 = 0 :: number() | |||
, unum16 = 0 :: number() | |||
, num32 = 0 :: number() | |||
, unum32 = 0 :: number() | |||
, num64 = 0 :: number() | |||
, unum64 = 0 :: number() | |||
, numfloat = 0 :: number() | |||
, numdouble = 0 :: number() | |||
, float = 0.0 :: float() | |||
, double = 0.0 :: double() | |||
, string1 = "" :: string() | |||
, string2 = "" :: string() | |||
, union = undefined :: #union{} | |||
, lbool = [] :: [boolean()] | |||
, lint8 = [] :: [int8()] | |||
, luint8 = [] :: [uint8()] | |||
, lint16 = [] :: [int16()] | |||
, luint16 = [] :: [uint16()] | |||
, lint32 = [] :: [int32()] | |||
, luint32 = [] :: [uint32()] | |||
, lint64 = [] :: [int64()] | |||
, luint64 = [] :: [uint64()] | |||
, linte8 = [] :: [integer()] | |||
, linte16 = [] :: [integer()] | |||
, linte32 = [] :: [integer()] | |||
, linte64 = [] :: [integer()] | |||
, lnum8 = [] :: [number()] | |||
, lnum16 = [] :: [number()] | |||
, lnum32 = [] :: [number()] | |||
, lnum64 = [] :: [number()] | |||
, lnfloat32 = [] :: [number()] | |||
, lnfloat64 = [] :: [number()] | |||
, lfloat = [] :: [float()] | |||
, ldouble = [] :: [double()] | |||
, lstring = [] :: [string()] | |||
, lunion = [] :: [#union{}] | |||
}). | |||
-record(person1, { | |||
name = "" :: string() | |||
, id = 0 :: int32() | |||
, email = "" :: string() | |||
, phone = [] :: [#phoneNumber{}] | |||
}). |
@ -0,0 +1 @@ | |||
start werl.exe |
@ -0,0 +1,672 @@ | |||
-module(test1). | |||
-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:encode(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)). | |||
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:encode(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:encode(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:encode(#tbool{bool = true}))). | |||
test21() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tint8{int1 = 123, int2 = -22}))). | |||
test22() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tuint8{int1 = 123, int2 = 182}))). | |||
test31() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tint16{int1 = 12343, int2 = -3422}))). | |||
test32() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tuint16{int1 = 43244, int2 = 43243}))). | |||
test41() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tint32{int1 = 12343434, int2 = -34434322}))). | |||
test42() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tuint32{int1 = 432444343, int2 = 432443433}))). | |||
test51() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tint64{int1 = 12344343434, int2 = -344343434322}))). | |||
test52() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#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})), | |||
<<_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:encode(#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:encode(#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:encode(#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}))). | |||
test82() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#tdouble{int1 = -342343433333.343, int2 = 423423423333.434}))). | |||
test9() -> | |||
protoMsg:decode(iolist_to_binary(protoMsg:encode(#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:encode(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:encode(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:encode(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:encode(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:encode(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:encode(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). |