|
|
@ -39,45 +39,45 @@ protoErlHeader() -> |
|
|
|
|
|
|
|
-define(int8(V), <<V:8>>). |
|
|
|
-define(uint8(V), <<V:8>>). |
|
|
|
-define(int16(V), <<V:16/little>>). |
|
|
|
-define(uint16(V), <<V:16/little>>). |
|
|
|
-define(int32(V), <<V:32/little>>). |
|
|
|
-define(uint32(V), <<V:32/little>>). |
|
|
|
-define(int64(V), <<V:64/little>>). |
|
|
|
-define(uint64(V), <<V:64/little>>). |
|
|
|
-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/little-float>>). |
|
|
|
-define(double(V), <<V:64/little-float>>). |
|
|
|
-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/little>>, [?bool(V) || V <- List]]). |
|
|
|
-define(list_int8(List), [<<(length(List)):16/little>>, [?int8(V) || V <- List]]). |
|
|
|
-define(list_uint8(List), [<<(length(List)):16/little>>, [?uint8(V) || V <- List]]). |
|
|
|
-define(list_int16(List), [<<(length(List)):16/little>>, [?int16(V) || V <- List]]). |
|
|
|
-define(list_uint16(List), [<<(length(List)):16/little>>, [?uint16(V) || V <- List]]). |
|
|
|
-define(list_int32(List), [<<(length(List)):16/little>>, [?int32(V) || V <- List]]). |
|
|
|
-define(list_uint32(List), [<<(length(List)):16/little>>, [?uint32(V) || V <- List]]). |
|
|
|
-define(list_int64(List), [<<(length(List)):16/little>>, [?int64(V) || V <- List]]). |
|
|
|
-define(list_uint64(List), [<<(length(List)):16/little>>, [?uint64(V) || V <- List]]). |
|
|
|
-define(list_float(List), [<<(length(List)):16/little>>, [?float(V) || V <- List]]). |
|
|
|
-define(list_double(List), [<<(length(List)):16/little>>, [?double(V) || V <- List]]). |
|
|
|
-define(list_integer(List), [<<(length(List)):16/little>>, [integer(V) || V <- List]]). |
|
|
|
-define(list_number(List), [<<(length(List)):16/little>>, [number(V) || V <- List]]). |
|
|
|
-define(list_string(List), [<<(length(List)):16/little>>, [string(V) || V <- List]]). |
|
|
|
-define(list_record(List), [<<(length(List)):16/little>>, [encodeRec(V) || V <- List]]). |
|
|
|
-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]]). |
|
|
|
|
|
|
|
integer(V) -> |
|
|
|
if |
|
|
|
V >= ?min8 andalso V =< ?max8 -> |
|
|
|
<<8:8, <<V:8>>/binary>>; |
|
|
|
V >= ?min16 andalso V =< ?max16 -> |
|
|
|
<<16:8, <<V:16/little>>/binary>>; |
|
|
|
<<16:8, <<V:16/big>>/binary>>; |
|
|
|
V >= ?min32 andalso V =< ?max32 -> |
|
|
|
<<32:8, <<V:32/little>>/binary>>; |
|
|
|
<<32:8, <<V:32/big>>/binary>>; |
|
|
|
V >= ?min64 andalso V =< ?max64 -> |
|
|
|
<<64:8, <<V:64/little>>/binary>>; |
|
|
|
<<64:8, <<V:64/big>>/binary>>; |
|
|
|
true -> |
|
|
|
throw(exceeded_the_integer) |
|
|
|
end. |
|
|
@ -87,11 +87,11 @@ numInteger(V) -> |
|
|
|
V >= ?min8 andalso V =< ?max8 -> |
|
|
|
<<8:8, <<V:8>>/binary>>; |
|
|
|
V >= ?min16 andalso V =< ?max16 -> |
|
|
|
<<16:8, <<V:16/little>>/binary>>; |
|
|
|
<<16:8, <<V:16/big>>/binary>>; |
|
|
|
V >= ?min32 andalso V =< ?max32 -> |
|
|
|
<<32:8, <<V:32/little>>/binary>>; |
|
|
|
<<32:8, <<V:32/big>>/binary>>; |
|
|
|
V >= ?min64 andalso V =< ?max64 -> |
|
|
|
<<64:8, <<V:64/little>>/binary>>; |
|
|
|
<<64:8, <<V:64/big>>/binary>>; |
|
|
|
true -> |
|
|
|
throw(exceeded_the_integer) |
|
|
|
end. |
|
|
@ -99,9 +99,9 @@ numInteger(V) -> |
|
|
|
numFloat(V) -> |
|
|
|
if |
|
|
|
V >= ?minF32 andalso V =< ?maxF32 -> |
|
|
|
<<33:8, <<V:32/little-float>>/binary>>; |
|
|
|
<<33:8, <<V:32/big-float>>/binary>>; |
|
|
|
V >= ?minF64 andalso V =< ?maxF64 -> |
|
|
|
<<65:8, <<V:64/little-float>>/binary>>; |
|
|
|
<<65:8, <<V:64/big-float>>/binary>>; |
|
|
|
true -> |
|
|
|
throw(exceeded_the_float) |
|
|
|
end. |
|
|
@ -117,18 +117,18 @@ number(V) -> |
|
|
|
end. |
|
|
|
|
|
|
|
string(Str) when is_binary(Str) -> |
|
|
|
[<<(byte_size(Str)):16/little>>, Str]; |
|
|
|
[<<(byte_size(Str)):16/big>>, Str]; |
|
|
|
string(Str) -> |
|
|
|
Str2 = unicode:characters_to_binary(Str, utf8), |
|
|
|
[<<(byte_size(Str2)):16/little>>, Str2]. |
|
|
|
[<<(byte_size(Str2)):16/big>>, Str2]. |
|
|
|
|
|
|
|
encode(Record) -> |
|
|
|
MsgBin = encodeRec(Record), |
|
|
|
MsgId = getMsgId(element(1, Record)), |
|
|
|
[<<MsgId:16/little>>, MsgBin]. |
|
|
|
[<<MsgId:16/big>>, MsgBin]. |
|
|
|
|
|
|
|
decode(Bin) -> |
|
|
|
<<MsgId:16/little, MsgBin/binary>> = Bin, |
|
|
|
<<MsgId:16/big, MsgBin/binary>> = Bin, |
|
|
|
SchList = getMsgSchema(MsgId), |
|
|
|
{<<>>, ResultList} = decodeField(SchList, MsgBin, [getMsgType(MsgId)]), |
|
|
|
list_to_tuple(ResultList). |
|
|
@ -143,50 +143,50 @@ decodeField([], LeftBin, Result) -> |
|
|
|
decodeField([Type | SchList], MsgBin, Result) -> |
|
|
|
case Type of |
|
|
|
int32 -> |
|
|
|
<<Int:32/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:32/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
uint32 -> |
|
|
|
<<Int:32/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:32/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
string -> |
|
|
|
<<Len:16/little, StrBin:Len/binary, LeftBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, StrBin:Len/binary, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [StrBin | Result]); |
|
|
|
int16 -> |
|
|
|
<<Int:16/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:16/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
uint16 -> |
|
|
|
<<Int:16/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:16/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
int8 -> |
|
|
|
<<Int:8/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:8/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
uint8 -> |
|
|
|
<<Int:8/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:8/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
int64 -> |
|
|
|
<<Int:64/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:64/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
uint64 -> |
|
|
|
<<Int:64/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:64/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
integer -> |
|
|
|
<<IntBits:8, Int:IntBits/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<IntBits:8, Int:IntBits/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]); |
|
|
|
number -> |
|
|
|
<<NumBits:8, NumBin/binary>> = MsgBin, |
|
|
|
case NumBits of |
|
|
|
33 -> |
|
|
|
<<Float:32/little-float, LeftBin/binary>> = NumBin, |
|
|
|
<<Float:32/big-float, LeftBin/binary>> = NumBin, |
|
|
|
decodeField(SchList, LeftBin, [Float | Result]); |
|
|
|
65 -> |
|
|
|
<<Float:64/little-float, LeftBin/binary>> = NumBin, |
|
|
|
<<Float:64/big-float, LeftBin/binary>> = NumBin, |
|
|
|
decodeField(SchList, LeftBin, [Float | Result]); |
|
|
|
_ -> |
|
|
|
<<Int:NumBits/little-signed, LeftBin/binary>> = NumBin, |
|
|
|
<<Int:NumBits/big-signed, LeftBin/binary>> = NumBin, |
|
|
|
decodeField(SchList, LeftBin, [Int | Result]) |
|
|
|
end; |
|
|
|
bool -> |
|
|
|
<<Bool:8/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Bool:8/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
case Bool =:= 1 of |
|
|
|
true -> |
|
|
|
decodeField(SchList, LeftBin, [true | Result]); |
|
|
@ -194,69 +194,69 @@ decodeField([Type | SchList], MsgBin, Result) -> |
|
|
|
decodeField(SchList, LeftBin, [false | Result]) |
|
|
|
end; |
|
|
|
float -> |
|
|
|
<<Float:32/little-float, LeftBin/binary>> = MsgBin, |
|
|
|
<<Float:32/big-float, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Float | Result]); |
|
|
|
double -> |
|
|
|
<<Float:64/little-float, LeftBin/binary>> = MsgBin, |
|
|
|
<<Float:64/big-float, LeftBin/binary>> = MsgBin, |
|
|
|
decodeField(SchList, LeftBin, [Float | Result]); |
|
|
|
{list, int32} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deInt32List(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, uint32} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deUint32List(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, int16} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deInt16List(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, uint16} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deUint16List(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, int8} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deInt8List(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, uint8} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deUint8List(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, string} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deStringList(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, int64} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deInt64List(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, uint64} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deUint64List(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, integer} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deIntegerList(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, number} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deNumberList(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, bool} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deBoolList(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, float} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deFloatList(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, double} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deDoubleList(Len, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
{list, RecordName} -> |
|
|
|
<<Len:16/little, LeftListBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, LeftListBin/binary>> = MsgBin, |
|
|
|
{LeftBin, RetList} = deRecordList(Len, RecordName, LeftListBin, []), |
|
|
|
decodeField(SchList, LeftBin, [RetList | Result]); |
|
|
|
RecordName -> |
|
|
@ -284,55 +284,55 @@ deBoolList(N, MsgBin, RetList) -> |
|
|
|
deInt8List(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, RetList}; |
|
|
|
deInt8List(N, MsgBin, RetList) -> |
|
|
|
<<Int:8/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:8/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
deInt8List(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deUint8List(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deUint8List(N, MsgBin, RetList) -> |
|
|
|
<<Int:8/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:8/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
deUint8List(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deInt16List(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deInt16List(N, MsgBin, RetList) -> |
|
|
|
<<Int:16/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:16/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
deInt16List(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deUint16List(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deUint16List(N, MsgBin, RetList) -> |
|
|
|
<<Int:16/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:16/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
deUint16List(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deInt32List(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deInt32List(N, MsgBin, RetList) -> |
|
|
|
<<Int:32/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:32/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
deInt32List(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deUint32List(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deUint32List(N, MsgBin, RetList) -> |
|
|
|
<<Int:32/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:32/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
deUint32List(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deInt64List(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deInt64List(N, MsgBin, RetList) -> |
|
|
|
<<Int:64/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:64/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
deInt64List(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deUint64List(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deUint64List(N, MsgBin, RetList) -> |
|
|
|
<<Int:64/little-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
<<Int:64/big-unsigned, LeftBin/binary>> = MsgBin, |
|
|
|
deUint64List(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deIntegerList(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deIntegerList(N, MsgBin, RetList) -> |
|
|
|
<<IntBits:8, Int:IntBits/little-signed, LeftBin/binary>> = MsgBin, |
|
|
|
<<IntBits:8, Int:IntBits/big-signed, LeftBin/binary>> = MsgBin, |
|
|
|
deIntegerList(N - 1, LeftBin, [Int | RetList]). |
|
|
|
|
|
|
|
deNumberList(0, MsgBin, RetList) -> |
|
|
@ -341,32 +341,32 @@ deNumberList(N, MsgBin, RetList) -> |
|
|
|
<<NumBits:8, NumBin/binary>> = MsgBin, |
|
|
|
case NumBits of |
|
|
|
33 -> |
|
|
|
<<Float:32/little-float, LeftBin/binary>> = NumBin, |
|
|
|
<<Float:32/big-float, LeftBin/binary>> = NumBin, |
|
|
|
deNumberList(N - 1, LeftBin, [Float | RetList]); |
|
|
|
65 -> |
|
|
|
<<Float:64/little-float, LeftBin/binary>> = NumBin, |
|
|
|
<<Float:64/big-float, LeftBin/binary>> = NumBin, |
|
|
|
deNumberList(N - 1, LeftBin, [Float | RetList]); |
|
|
|
_ -> |
|
|
|
<<Int:NumBits/little-signed, LeftBin/binary>> = NumBin, |
|
|
|
<<Int:NumBits/big-signed, LeftBin/binary>> = NumBin, |
|
|
|
deNumberList(N - 1, LeftBin, [Int | RetList]) |
|
|
|
end. |
|
|
|
|
|
|
|
deFloatList(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deFloatList(N, MsgBin, RetList) -> |
|
|
|
<<Float:32/little-float, LeftBin/binary>> = MsgBin, |
|
|
|
<<Float:32/big-float, LeftBin/binary>> = MsgBin, |
|
|
|
deFloatList(N - 1, LeftBin, [Float | RetList]). |
|
|
|
|
|
|
|
deDoubleList(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deDoubleList(N, MsgBin, RetList) -> |
|
|
|
<<Float:64/little-float, LeftBin/binary>> = MsgBin, |
|
|
|
<<Float:64/big-float, LeftBin/binary>> = MsgBin, |
|
|
|
deDoubleList(N - 1, LeftBin, [Float | RetList]). |
|
|
|
|
|
|
|
deStringList(0, MsgBin, RetList) -> |
|
|
|
{MsgBin, lists:reverse(RetList)}; |
|
|
|
deStringList(N, MsgBin, RetList) -> |
|
|
|
<<Len:16/little, StrBin:Len/binary-unit:8, LeftBin/binary>> = MsgBin, |
|
|
|
<<Len:16/big, StrBin:Len/binary-unit:8, LeftBin/binary>> = MsgBin, |
|
|
|
deStringList(N - 1, LeftBin, [StrBin | RetList]). |
|
|
|
|
|
|
|
deRecordList(0, _RecordName, MsgBin, RetList) -> |
|
|
@ -390,6 +390,10 @@ genMsgHrl(FieldInfo, {Index, Len, AccList}) -> |
|
|
|
RecStr = TemStr ++ protoField:builtRecStr(FieldInfo) ++ (case Index == Len of true -> ""; _ -> "\t" end), |
|
|
|
{Index - 1, Len, [RecStr | AccList]}. |
|
|
|
|
|
|
|
genErrCodeHrl({ErrName, ErrCodeId, ComDesc}, AccList) -> |
|
|
|
Str = "-define(" ++ ErrName ++ ", " ++ integer_to_list(ErrCodeId) ++ ").\t\t%% " ++ ComDesc ++ "\n", |
|
|
|
[Str | AccList]. |
|
|
|
|
|
|
|
genEncodeRec({MsgName, _MsgId, FieldList}) -> |
|
|
|
FieldLen = length(FieldList), |
|
|
|
FunHead = |
|
|
@ -431,24 +435,28 @@ convertDir(ProtoDir) -> |
|
|
|
convertDir(ProtoDir, "./", "./"). |
|
|
|
convertDir(ProtoDir, HrlDir, ErlDir) -> |
|
|
|
FunRead = |
|
|
|
fun(File, Acc) -> |
|
|
|
case filename:extension(File) == ".msg" of |
|
|
|
fun(File, {ProAcc, ErrCodeAcc} = Acc) -> |
|
|
|
case filename:extension(File) == ".mpdf" of |
|
|
|
true -> |
|
|
|
io:format("Convert proto msg file: ~s ~n", [File]), |
|
|
|
BaseName = filename:basename(File, ".msg"), |
|
|
|
BaseName = filename:basename(File, ".mpdf"), |
|
|
|
[ModIndex | _ModName] = re:split(BaseName, "_"), |
|
|
|
Index = binary_to_integer(ModIndex), |
|
|
|
put(messageid, Index * 1000 + 1), |
|
|
|
erlang:put(pd_messageid, Index * 1000 + 1), |
|
|
|
erlang:put(pd_errcodeid, Index * 1000 + 1), |
|
|
|
erlang:put(pd_errlist, []), |
|
|
|
SProto = protoParse:parseFile(File), |
|
|
|
[SProto | Acc]; |
|
|
|
ErrCode = erlang:get(pd_errlist), |
|
|
|
erlang:erase(), |
|
|
|
{[SProto | ProAcc], [ErrCode | ErrCodeAcc]}; |
|
|
|
_ -> |
|
|
|
Acc |
|
|
|
|
|
|
|
end |
|
|
|
end, |
|
|
|
%% 下面文件帅选并不能准确的帅选出文件名为.msg结尾的文件 在FunRead函数中纠正处理一下 |
|
|
|
SProtoListOfList = filelib:fold_files(ProtoDir, "\\.msg", true, FunRead, []), |
|
|
|
{SProtoListOfList, ErrListOfList} = filelib:fold_files(ProtoDir, "\\.mpdf", true, FunRead, {[], []}), |
|
|
|
SProtoList = lists:append(SProtoListOfList), |
|
|
|
ErrList = lists:append(ErrListOfList), |
|
|
|
SortedSProtoList = lists:sort(fun({_Name1, MessageId1, _FieldList1}, {_Name2, MessageId2, _FieldList2}) -> |
|
|
|
MessageId1 > MessageId2 end, SProtoList), |
|
|
|
FunSpell = |
|
|
@ -465,10 +473,14 @@ convertDir(ProtoDir, HrlDir, ErlDir) -> |
|
|
|
{[HrlStr | MsgHrlAcc], [TypeStr | MsgTypeAcc], [IdStr | MsgIdAcc], [EncodeStr | MsgEndStr], [SchemaStr | MsgSchemaAcc]} |
|
|
|
end, |
|
|
|
{MsgHrlStr, MsgTypeStr, MsgIdStr, MsgEndStr, MsgSchemaStr} = lists:foldl(FunSpell, {[], ["getMsgType(_) -> undefined.\n\n"], ["getMsgId(_) -> 0.\n\n"], ["encodeRec(_) ->\n\t[].\n\n"], ["getMsgSchema(_) ->\n\t[].\n\n"]}, SortedSProtoList), |
|
|
|
|
|
|
|
|
|
|
|
SortedErrList = lists:sort(fun({_ErrName1, ErrCodeId1, _Desc1}, {_ErrName2, ErrCodeId2, _Desc2}) -> |
|
|
|
ErrCodeId1 > ErrCodeId2 end, ErrList), |
|
|
|
ErrCodeStr = lists:foldl(fun genErrCodeHrl/2, [], SortedErrList) ++ "\n\n", |
|
|
|
|
|
|
|
ModStr = protoErlHeader(), |
|
|
|
OutputStr = ModStr ++ MsgTypeStr ++ MsgIdStr ++ MsgEndStr ++ MsgSchemaStr, |
|
|
|
HrlFilename = do_write_hrl(HrlDir, protoMsg, protoHrlHeader() ++ MsgHrlStr), |
|
|
|
HrlFilename = do_write_hrl(HrlDir, protoMsg, protoHrlHeader() ++ ErrCodeStr ++ MsgHrlStr), |
|
|
|
ErlFilename = do_write_erl(ErlDir, protoMsg, OutputStr), |
|
|
|
|
|
|
|
io:format("protoConvert hrl dir : ~s ~n", [HrlDir]), |
|
|
|