erlang自定义二进制协议
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

724 line
28 KiB

  1. -module(protoMsg).
  2. -compile([nowarn_unused_vars]).
  3. -export([encode/1, decode/1, encodeRec/1, decodeBin/2]).
  4. -define(min8, -128).
  5. -define(max8, 127).
  6. -define(min16, -32768).
  7. -define(max16, 32767).
  8. -define(min32, -2147483648).
  9. -define(max32, 2147483647).
  10. -define(min64, -9223372036854775808).
  11. -define(max64, 9223372036854775807).
  12. -define(minF32, -3.4E+38).
  13. -define(maxF32, 3.4E+38).
  14. -define(minF64, -1.797E-308).
  15. -define(maxF64, 1.797E+308).
  16. -define(int8(V), <<V:8>>).
  17. -define(uint8(V), <<V:8>>).
  18. -define(int16(V), <<V:16/big>>).
  19. -define(uint16(V), <<V:16/big>>).
  20. -define(int32(V), <<V:32/big>>).
  21. -define(uint32(V), <<V:32/big>>).
  22. -define(int64(V), <<V:64/big>>).
  23. -define(uint64(V), <<V:64/big>>).
  24. -define(integer(V), (integer(V))).
  25. -define(number(V), (number(V))).
  26. -define(string(V), (string(V))).
  27. -define(float(V), <<V:32/big-float>>).
  28. -define(double(V), <<V:64/big-float>>).
  29. -define(bool(V), (case V of true -> <<1:8>>; _ -> <<0:8>> end)).
  30. -define(record(V), (case V of undefined -> [<<0:8>>]; V -> [<<1:8>>, encodeRec(V)] end)).
  31. -define(list_bool(List), [<<(length(List)):16/big>>, [?bool(V) || V <- List]]).
  32. -define(list_int8(List), [<<(length(List)):16/big>>, [?int8(V) || V <- List]]).
  33. -define(list_uint8(List), [<<(length(List)):16/big>>, [?uint8(V) || V <- List]]).
  34. -define(list_int16(List), [<<(length(List)):16/big>>, [?int16(V) || V <- List]]).
  35. -define(list_uint16(List), [<<(length(List)):16/big>>, [?uint16(V) || V <- List]]).
  36. -define(list_int32(List), [<<(length(List)):16/big>>, [?int32(V) || V <- List]]).
  37. -define(list_uint32(List), [<<(length(List)):16/big>>, [?uint32(V) || V <- List]]).
  38. -define(list_int64(List), [<<(length(List)):16/big>>, [?int64(V) || V <- List]]).
  39. -define(list_uint64(List), [<<(length(List)):16/big>>, [?uint64(V) || V <- List]]).
  40. -define(list_float(List), [<<(length(List)):16/big>>, [?float(V) || V <- List]]).
  41. -define(list_double(List), [<<(length(List)):16/big>>, [?double(V) || V <- List]]).
  42. -define(list_integer(List), [<<(length(List)):16/big>>, [integer(V) || V <- List]]).
  43. -define(list_number(List), [<<(length(List)):16/big>>, [number(V) || V <- List]]).
  44. -define(list_string(List), [<<(length(List)):16/big>>, [string(V) || V <- List]]).
  45. -define(list_record(List), [<<(length(List)):16/big>>, [encodeRec(V) || V <- List]]).
  46. integer(V) ->
  47. if
  48. V >= ?min8 andalso V =< ?max8 ->
  49. <<8:8, <<V:8>>/binary>>;
  50. V >= ?min16 andalso V =< ?max16 ->
  51. <<16:8, <<V:16/big>>/binary>>;
  52. V >= ?min32 andalso V =< ?max32 ->
  53. <<32:8, <<V:32/big>>/binary>>;
  54. V >= ?min64 andalso V =< ?max64 ->
  55. <<64:8, <<V:64/big>>/binary>>;
  56. true ->
  57. throw(exceeded_the_integer)
  58. end.
  59. number(V) ->
  60. if
  61. erlang:is_integer(V) ->
  62. if
  63. V >= ?min8 andalso V =< ?max8 ->
  64. <<8:8, <<V:8>>/binary>>;
  65. V >= ?min16 andalso V =< ?max16 ->
  66. <<16:8, <<V:16/big>>/binary>>;
  67. V >= ?min32 andalso V =< ?max32 ->
  68. <<32:8, <<V:32/big>>/binary>>;
  69. V >= ?min64 andalso V =< ?max64 ->
  70. <<64:8, <<V:64/big>>/binary>>;
  71. true ->
  72. throw(exceeded_the_integer)
  73. end;
  74. erlang:is_float(V) ->
  75. if
  76. V >= ?minF32 andalso V =< ?maxF32 ->
  77. <<33:8, <<V:32/big-float>>/binary>>;
  78. V >= ?minF64 andalso V =< ?maxF64 ->
  79. <<65:8, <<V:64/big-float>>/binary>>;
  80. true ->
  81. throw(exceeded_the_float)
  82. end;
  83. true ->
  84. throw(is_not_number)
  85. end.
  86. string(Str) when is_binary(Str) ->
  87. [<<(byte_size(Str)):16/big>>, Str];
  88. string(Str) ->
  89. Str2 = unicode:characters_to_binary(Str, utf8),
  90. [<<(byte_size(Str2)):16/big>>, Str2].
  91. decode(Bin) ->
  92. <<MsgId:16/big, MsgBin/binary>> = Bin,
  93. decodeBin(MsgId, MsgBin).
  94. deBoolList(0, MsgBin, RetList) ->
  95. {lists:reverse(RetList), MsgBin};
  96. deBoolList(N, MsgBin, RetList) ->
  97. <<Bool:8, LeftBin/binary>> = MsgBin,
  98. case Bool =:= 1 of
  99. true ->
  100. deBoolList(N - 1, LeftBin, [true | RetList]);
  101. _ ->
  102. deBoolList(N - 1, LeftBin, [false | RetList])
  103. end.
  104. deInt8List(0, MsgBin, RetList) ->
  105. {RetList, MsgBin};
  106. deInt8List(N, MsgBin, RetList) ->
  107. <<Int:8/big-signed, LeftBin/binary>> = MsgBin,
  108. deInt8List(N - 1, LeftBin, [Int | RetList]).
  109. deUint8List(0, MsgBin, RetList) ->
  110. {lists:reverse(RetList), MsgBin};
  111. deUint8List(N, MsgBin, RetList) ->
  112. <<Int:8/big-unsigned, LeftBin/binary>> = MsgBin,
  113. deUint8List(N - 1, LeftBin, [Int | RetList]).
  114. deInt16List(0, MsgBin, RetList) ->
  115. {lists:reverse(RetList), MsgBin};
  116. deInt16List(N, MsgBin, RetList) ->
  117. <<Int:16/big-signed, LeftBin/binary>> = MsgBin,
  118. deInt16List(N - 1, LeftBin, [Int | RetList]).
  119. deUint16List(0, MsgBin, RetList) ->
  120. {lists:reverse(RetList), MsgBin};
  121. deUint16List(N, MsgBin, RetList) ->
  122. <<Int:16/big-unsigned, LeftBin/binary>> = MsgBin,
  123. deUint16List(N - 1, LeftBin, [Int | RetList]).
  124. deInt32List(0, MsgBin, RetList) ->
  125. {lists:reverse(RetList), MsgBin};
  126. deInt32List(N, MsgBin, RetList) ->
  127. <<Int:32/big-signed, LeftBin/binary>> = MsgBin,
  128. deInt32List(N - 1, LeftBin, [Int | RetList]).
  129. deUint32List(0, MsgBin, RetList) ->
  130. {lists:reverse(RetList), MsgBin};
  131. deUint32List(N, MsgBin, RetList) ->
  132. <<Int:32/big-unsigned, LeftBin/binary>> = MsgBin,
  133. deUint32List(N - 1, LeftBin, [Int | RetList]).
  134. deInt64List(0, MsgBin, RetList) ->
  135. {lists:reverse(RetList), MsgBin};
  136. deInt64List(N, MsgBin, RetList) ->
  137. <<Int:64/big-signed, LeftBin/binary>> = MsgBin,
  138. deInt64List(N - 1, LeftBin, [Int | RetList]).
  139. deUint64List(0, MsgBin, RetList) ->
  140. {lists:reverse(RetList), MsgBin};
  141. deUint64List(N, MsgBin, RetList) ->
  142. <<Int:64/big-unsigned, LeftBin/binary>> = MsgBin,
  143. deUint64List(N - 1, LeftBin, [Int | RetList]).
  144. deIntegerList(0, MsgBin, RetList) ->
  145. {lists:reverse(RetList), MsgBin};
  146. deIntegerList(N, MsgBin, RetList) ->
  147. <<IntBits:8, Int:IntBits/big-signed, LeftBin/binary>> = MsgBin,
  148. deIntegerList(N - 1, LeftBin, [Int | RetList]).
  149. deNumberList(0, MsgBin, RetList) ->
  150. {lists:reverse(RetList), MsgBin};
  151. deNumberList(N, MsgBin, RetList) ->
  152. <<NumBits:8, NumBin/binary>> = MsgBin,
  153. case NumBits of
  154. 33 ->
  155. <<Float:32/big-float, LeftBin/binary>> = NumBin,
  156. deNumberList(N - 1, LeftBin, [Float | RetList]);
  157. 65 ->
  158. <<Float:64/big-float, LeftBin/binary>> = NumBin,
  159. deNumberList(N - 1, LeftBin, [Float | RetList]);
  160. _ ->
  161. <<Int:NumBits/big-signed, LeftBin/binary>> = NumBin,
  162. deNumberList(N - 1, LeftBin, [Int | RetList])
  163. end.
  164. deFloatList(0, MsgBin, RetList) ->
  165. {lists:reverse(RetList), MsgBin};
  166. deFloatList(N, MsgBin, RetList) ->
  167. <<Float:32/big-float, LeftBin/binary>> = MsgBin,
  168. deFloatList(N - 1, LeftBin, [Float | RetList]).
  169. deDoubleList(0, MsgBin, RetList) ->
  170. {lists:reverse(RetList), MsgBin};
  171. deDoubleList(N, MsgBin, RetList) ->
  172. <<Float:64/big-float, LeftBin/binary>> = MsgBin,
  173. deDoubleList(N - 1, LeftBin, [Float | RetList]).
  174. deStringList(0, MsgBin, RetList) ->
  175. {lists:reverse(RetList), MsgBin};
  176. deStringList(N, MsgBin, RetList) ->
  177. <<Len:16/big, StrBin:Len/binary-unit:8, LeftBin/binary>> = MsgBin,
  178. deStringList(N - 1, LeftBin, [StrBin | RetList]).
  179. deRecordList(0, _MsgId, MsgBin, RetList) ->
  180. {lists:reverse(RetList), MsgBin};
  181. deRecordList(N, MsgId, MsgBin, RetList) ->
  182. {Tuple, LeftBin} = decodeRec(MsgId, MsgBin),
  183. deRecordList(N - 1, MsgId, LeftBin, [Tuple | RetList]).
  184. encodeRec({test, V1}) ->
  185. [?string(V1)];
  186. encodeRec({phoneNumber, V1, V2}) ->
  187. [?record(V1), ?int32(V2)];
  188. encodeRec({person, V1, V2, V3, V4}) ->
  189. [?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)];
  190. encodeRec({union, V1, V2}) ->
  191. [?string(V1), ?int32(V2)];
  192. encodeRec(_) ->
  193. [].
  194. encode({test, V1}) ->
  195. [<<1:16/big-unsigned>>, ?string(V1)];
  196. encode({phoneNumber, V1, V2}) ->
  197. [<<2:16/big-unsigned>>, ?record(V1), ?int32(V2)];
  198. encode({person, V1, V2, V3, V4}) ->
  199. [<<3:16/big-unsigned>>, ?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)];
  200. encode({addressBook, V1, V2}) ->
  201. [<<4:16/big-unsigned>>, ?list_record(V1), ?list_record(V2)];
  202. encode({union, V1, V2}) ->
  203. [<<5:16/big-unsigned>>, ?string(V1), ?int32(V2)];
  204. encode({tbool, V1}) ->
  205. [<<6:16/big-unsigned>>, ?bool(V1)];
  206. encode({tint8, V1, V2}) ->
  207. [<<7:16/big-unsigned>>, ?int8(V1), ?int8(V2)];
  208. encode({tuint8, V1, V2}) ->
  209. [<<8:16/big-unsigned>>, ?uint8(V1), ?uint8(V2)];
  210. encode({tint16, V1, V2}) ->
  211. [<<9:16/big-unsigned>>, ?int16(V1), ?int16(V2)];
  212. encode({tuint16, V1, V2}) ->
  213. [<<10:16/big-unsigned>>, ?uint16(V1), ?uint16(V2)];
  214. encode({tint32, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10}) ->
  215. [<<11:16/big-unsigned>>, ?int32(V1), ?int32(V2), ?int32(V3), ?int32(V4), ?int32(V5), ?int32(V6), ?int32(V7), ?int32(V8), ?int32(V9), ?int32(V10)];
  216. encode({tuint32, V1, V2}) ->
  217. [<<12:16/big-unsigned>>, ?uint32(V1), ?uint32(V2)];
  218. encode({tint64, V1, V2}) ->
  219. [<<13:16/big-unsigned>>, ?int64(V1), ?int64(V2)];
  220. encode({tuint64, V1, V2}) ->
  221. [<<14:16/big-unsigned>>, ?uint64(V1), ?uint64(V2)];
  222. encode({tinteger, V1, V2, V3, V4, V5, V6, V7, V8}) ->
  223. [<<15:16/big-unsigned>>, ?integer(V1), ?integer(V2), ?integer(V3), ?integer(V4), ?integer(V5), ?integer(V6), ?integer(V7), ?integer(V8)];
  224. encode({tnumber, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10}) ->
  225. [<<16:16/big-unsigned>>, ?number(V1), ?number(V2), ?number(V3), ?number(V4), ?number(V5), ?number(V6), ?number(V7), ?number(V8), ?number(V9), ?number(V10)];
  226. encode({tfloat, V1, V2}) ->
  227. [<<17:16/big-unsigned>>, ?float(V1), ?float(V2)];
  228. encode({tdouble, V1, V2}) ->
  229. [<<18:16/big-unsigned>>, ?double(V1), ?double(V2)];
  230. encode({tstring, V1, V2}) ->
  231. [<<19:16/big-unsigned>>, ?string(V1), ?string(V2)];
  232. encode({tlistbool, V1}) ->
  233. [<<20:16/big-unsigned>>, ?list_bool(V1)];
  234. encode({tlistint8, V1}) ->
  235. [<<21:16/big-unsigned>>, ?list_int8(V1)];
  236. encode({tlistuint8, V1}) ->
  237. [<<22:16/big-unsigned>>, ?list_uint8(V1)];
  238. encode({tlistint16, V1}) ->
  239. [<<23:16/big-unsigned>>, ?list_int16(V1)];
  240. encode({tlistuint16, V1}) ->
  241. [<<24:16/big-unsigned>>, ?list_uint16(V1)];
  242. encode({tlistint32, V1}) ->
  243. [<<25:16/big-unsigned>>, ?list_int32(V1)];
  244. encode({tlistuint32, V1}) ->
  245. [<<26:16/big-unsigned>>, ?list_uint32(V1)];
  246. encode({tlistint64, V1}) ->
  247. [<<27:16/big-unsigned>>, ?list_int64(V1)];
  248. encode({tlistuint64, V1}) ->
  249. [<<28:16/big-unsigned>>, ?list_uint64(V1)];
  250. encode({tlistinteger, V1}) ->
  251. [<<29:16/big-unsigned>>, ?list_integer(V1)];
  252. encode({tlistnumber, V1}) ->
  253. [<<30:16/big-unsigned>>, ?list_number(V1)];
  254. encode({tlistfloat, V1}) ->
  255. [<<31:16/big-unsigned>>, ?list_float(V1)];
  256. encode({tlistdouble, V1}) ->
  257. [<<32:16/big-unsigned>>, ?list_double(V1)];
  258. encode({tliststring, V1}) ->
  259. [<<33:16/big-unsigned>>, ?list_string(V1)];
  260. encode({tlistunion, V1}) ->
  261. [<<34:16/big-unsigned>>, ?list_record(V1)];
  262. 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}) ->
  263. [<<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)];
  264. encode({person1, V1, V2, V3, V4}) ->
  265. [<<1001:16/big-unsigned>>, ?string(V1), ?int32(V2), ?string(V3), ?list_record(V4)];
  266. encode(_) ->
  267. [].
  268. decodeRec(1, LeftBin0) ->
  269. <<Len1:16/big-unsigned, V1:Len1/binary, LeftBin1/binary>> = LeftBin0,
  270. MsgRec = {test, V1},
  271. {MsgRec, LeftBin1};
  272. decodeRec(2, LeftBin0) ->
  273. <<IsUndef1:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
  274. case IsUndef1 of
  275. 0 ->
  276. V1 = undefined,
  277. LeftBin2 = LeftBin1 ;
  278. _ ->
  279. {V1, LeftBin2} = decodeRec(1, LeftBin1)
  280. end,
  281. <<V2:32/big-signed, LeftBin3/binary>> = LeftBin2,
  282. MsgRec = {phoneNumber, V1, V2},
  283. {MsgRec, LeftBin3};
  284. decodeRec(3, LeftBin0) ->
  285. <<Len1:16/big-unsigned, V1:Len1/binary, LeftBin1/binary>> = LeftBin0,
  286. <<V2:32/big-signed, LeftBin2/binary>> = LeftBin1,
  287. <<Len2:16/big-unsigned, V3:Len2/binary, LeftBin3/binary>> = LeftBin2,
  288. <<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3,
  289. {V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []),
  290. MsgRec = {person, V1, V2, V3, V4},
  291. {MsgRec, LeftBin5};
  292. decodeRec(5, LeftBin0) ->
  293. <<Len1:16/big-unsigned, V1:Len1/binary, LeftBin1/binary>> = LeftBin0,
  294. <<V2:32/big-signed, LeftBin2/binary>> = LeftBin1,
  295. MsgRec = {union, V1, V2},
  296. {MsgRec, LeftBin2};
  297. decodeRec(_, _) ->
  298. {{}, <<>>}.
  299. decodeBin(1, LeftBin0) ->
  300. <<Len1:16/big-unsigned, V1:Len1/binary, LeftBin1/binary>> = LeftBin0,
  301. {test, V1};
  302. decodeBin(2, LeftBin0) ->
  303. <<IsUndef1:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
  304. case IsUndef1 of
  305. 0 ->
  306. V1 = undefined,
  307. LeftBin2 = LeftBin1 ;
  308. _ ->
  309. {V1, LeftBin2} = decodeRec(1, LeftBin1)
  310. end,
  311. <<V2:32/big-signed, LeftBin3/binary>> = LeftBin2,
  312. {phoneNumber, V1, V2};
  313. decodeBin(3, LeftBin0) ->
  314. <<Len1:16/big-unsigned, V1:Len1/binary, LeftBin1/binary>> = LeftBin0,
  315. <<V2:32/big-signed, LeftBin2/binary>> = LeftBin1,
  316. <<Len2:16/big-unsigned, V3:Len2/binary, LeftBin3/binary>> = LeftBin2,
  317. <<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3,
  318. {V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []),
  319. {person, V1, V2, V3, V4};
  320. decodeBin(4, LeftBin0) ->
  321. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  322. {V1, LeftBin2} = deRecordList(Len1, 3, LeftBin1, []),
  323. <<Len2:16/big-unsigned, LeftBin3/binary>> = LeftBin2,
  324. {V2, LeftBin4} = deRecordList(Len2, 3, LeftBin3, []),
  325. {addressBook, V1, V2};
  326. decodeBin(5, LeftBin0) ->
  327. <<Len1:16/big-unsigned, V1:Len1/binary, LeftBin1/binary>> = LeftBin0,
  328. <<V2:32/big-signed, LeftBin2/binary>> = LeftBin1,
  329. {union, V1, V2};
  330. decodeBin(6, LeftBin0) ->
  331. <<Bool1:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
  332. case Bool1 =:= 1 of
  333. true ->
  334. V1 = true;
  335. _ ->
  336. V1 = false
  337. end,
  338. {tbool, V1};
  339. decodeBin(7, LeftBin0) ->
  340. <<V1:8/big-signed, V2:8/big-signed, LeftBin1/binary>> = LeftBin0,
  341. {tint8, V1, V2};
  342. decodeBin(8, LeftBin0) ->
  343. <<V1:8/big-unsigned, V2:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
  344. {tuint8, V1, V2};
  345. decodeBin(9, LeftBin0) ->
  346. <<V1:16/big-signed, V2:16/big-signed, LeftBin1/binary>> = LeftBin0,
  347. {tint16, V1, V2};
  348. decodeBin(10, LeftBin0) ->
  349. <<V1:16/big-unsigned, V2:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  350. {tuint16, V1, V2};
  351. decodeBin(11, LeftBin0) ->
  352. <<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,
  353. {tint32, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10};
  354. decodeBin(12, LeftBin0) ->
  355. <<V1:32/big-unsigned, V2:32/big-unsigned, LeftBin1/binary>> = LeftBin0,
  356. {tuint32, V1, V2};
  357. decodeBin(13, LeftBin0) ->
  358. <<V1:64/big-signed, V2:64/big-signed, LeftBin1/binary>> = LeftBin0,
  359. {tint64, V1, V2};
  360. decodeBin(14, LeftBin0) ->
  361. <<V1:64/big-unsigned, V2:64/big-unsigned, LeftBin1/binary>> = LeftBin0,
  362. {tuint64, V1, V2};
  363. decodeBin(15, LeftBin0) ->
  364. <<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,
  365. {tinteger, V1, V2, V3, V4, V5, V6, V7, V8};
  366. decodeBin(16, LeftBin0) ->
  367. <<NumBits1:8, LeftBin1/binary>> = LeftBin0,
  368. case NumBits1 of
  369. 33->
  370. <<V1:32/big-float, LeftBin2/binary>> = LeftBin1;
  371. 65 ->
  372. <<V1:64/big-float, LeftBin2/binary>> = LeftBin1;
  373. _ ->
  374. <<V1:NumBits1/big-signed, LeftBin2/binary>> = LeftBin1
  375. end,
  376. <<NumBits2:8, LeftBin3/binary>> = LeftBin2,
  377. case NumBits2 of
  378. 33->
  379. <<V2:32/big-float, LeftBin4/binary>> = LeftBin3;
  380. 65 ->
  381. <<V2:64/big-float, LeftBin4/binary>> = LeftBin3;
  382. _ ->
  383. <<V2:NumBits2/big-signed, LeftBin4/binary>> = LeftBin3
  384. end,
  385. <<NumBits3:8, LeftBin5/binary>> = LeftBin4,
  386. case NumBits3 of
  387. 33->
  388. <<V3:32/big-float, LeftBin6/binary>> = LeftBin5;
  389. 65 ->
  390. <<V3:64/big-float, LeftBin6/binary>> = LeftBin5;
  391. _ ->
  392. <<V3:NumBits3/big-signed, LeftBin6/binary>> = LeftBin5
  393. end,
  394. <<NumBits4:8, LeftBin7/binary>> = LeftBin6,
  395. case NumBits4 of
  396. 33->
  397. <<V4:32/big-float, LeftBin8/binary>> = LeftBin7;
  398. 65 ->
  399. <<V4:64/big-float, LeftBin8/binary>> = LeftBin7;
  400. _ ->
  401. <<V4:NumBits4/big-signed, LeftBin8/binary>> = LeftBin7
  402. end,
  403. <<NumBits5:8, LeftBin9/binary>> = LeftBin8,
  404. case NumBits5 of
  405. 33->
  406. <<V5:32/big-float, LeftBin10/binary>> = LeftBin9;
  407. 65 ->
  408. <<V5:64/big-float, LeftBin10/binary>> = LeftBin9;
  409. _ ->
  410. <<V5:NumBits5/big-signed, LeftBin10/binary>> = LeftBin9
  411. end,
  412. <<NumBits6:8, LeftBin11/binary>> = LeftBin10,
  413. case NumBits6 of
  414. 33->
  415. <<V6:32/big-float, LeftBin12/binary>> = LeftBin11;
  416. 65 ->
  417. <<V6:64/big-float, LeftBin12/binary>> = LeftBin11;
  418. _ ->
  419. <<V6:NumBits6/big-signed, LeftBin12/binary>> = LeftBin11
  420. end,
  421. <<NumBits7:8, LeftBin13/binary>> = LeftBin12,
  422. case NumBits7 of
  423. 33->
  424. <<V7:32/big-float, LeftBin14/binary>> = LeftBin13;
  425. 65 ->
  426. <<V7:64/big-float, LeftBin14/binary>> = LeftBin13;
  427. _ ->
  428. <<V7:NumBits7/big-signed, LeftBin14/binary>> = LeftBin13
  429. end,
  430. <<NumBits8:8, LeftBin15/binary>> = LeftBin14,
  431. case NumBits8 of
  432. 33->
  433. <<V8:32/big-float, LeftBin16/binary>> = LeftBin15;
  434. 65 ->
  435. <<V8:64/big-float, LeftBin16/binary>> = LeftBin15;
  436. _ ->
  437. <<V8:NumBits8/big-signed, LeftBin16/binary>> = LeftBin15
  438. end,
  439. <<NumBits9:8, LeftBin17/binary>> = LeftBin16,
  440. case NumBits9 of
  441. 33->
  442. <<V9:32/big-float, LeftBin18/binary>> = LeftBin17;
  443. 65 ->
  444. <<V9:64/big-float, LeftBin18/binary>> = LeftBin17;
  445. _ ->
  446. <<V9:NumBits9/big-signed, LeftBin18/binary>> = LeftBin17
  447. end,
  448. <<NumBits10:8, LeftBin19/binary>> = LeftBin18,
  449. case NumBits10 of
  450. 33->
  451. <<V10:32/big-float, LeftBin20/binary>> = LeftBin19;
  452. 65 ->
  453. <<V10:64/big-float, LeftBin20/binary>> = LeftBin19;
  454. _ ->
  455. <<V10:NumBits10/big-signed, LeftBin20/binary>> = LeftBin19
  456. end,
  457. {tnumber, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10};
  458. decodeBin(17, LeftBin0) ->
  459. <<V1:32/big-float, V2:32/big-float, LeftBin1/binary>> = LeftBin0,
  460. {tfloat, V1, V2};
  461. decodeBin(18, LeftBin0) ->
  462. <<V1:64/big-float, V2:64/big-float, LeftBin1/binary>> = LeftBin0,
  463. {tdouble, V1, V2};
  464. decodeBin(19, LeftBin0) ->
  465. <<Len1:16/big-unsigned, V1:Len1/binary, LeftBin1/binary>> = LeftBin0,
  466. <<Len2:16/big-unsigned, V2:Len2/binary, LeftBin2/binary>> = LeftBin1,
  467. {tstring, V1, V2};
  468. decodeBin(20, LeftBin0) ->
  469. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  470. {V1, LeftBin2} = deBoolList(Len1, LeftBin1, []),
  471. {tlistbool, V1};
  472. decodeBin(21, LeftBin0) ->
  473. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  474. {V1, LeftBin2} = deInt8List(Len1, LeftBin1, []),
  475. {tlistint8, V1};
  476. decodeBin(22, LeftBin0) ->
  477. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  478. {V1, LeftBin2} = deUint8List(Len1, LeftBin1, []),
  479. {tlistuint8, V1};
  480. decodeBin(23, LeftBin0) ->
  481. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  482. {V1, LeftBin2} = deInt16List(Len1, LeftBin1, []),
  483. {tlistint16, V1};
  484. decodeBin(24, LeftBin0) ->
  485. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  486. {V1, LeftBin2} = deUint16List(Len1, LeftBin1, []),
  487. {tlistuint16, V1};
  488. decodeBin(25, LeftBin0) ->
  489. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  490. {V1, LeftBin2} = deInt32List(Len1, LeftBin1, []),
  491. {tlistint32, V1};
  492. decodeBin(26, LeftBin0) ->
  493. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  494. {V1, LeftBin2} = deUint32List(Len1, LeftBin1, []),
  495. {tlistuint32, V1};
  496. decodeBin(27, LeftBin0) ->
  497. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  498. {V1, LeftBin2} = deInt64List(Len1, LeftBin1, []),
  499. {tlistint64, V1};
  500. decodeBin(28, LeftBin0) ->
  501. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  502. {V1, LeftBin2} = deUint64List(Len1, LeftBin1, []),
  503. {tlistuint64, V1};
  504. decodeBin(29, LeftBin0) ->
  505. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  506. {V1, LeftBin2} = deIntegerList(Len1, LeftBin1, []),
  507. {tlistinteger, V1};
  508. decodeBin(30, LeftBin0) ->
  509. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  510. {V1, LeftBin2} = deNumberList(Len1, LeftBin1, []),
  511. {tlistnumber, V1};
  512. decodeBin(31, LeftBin0) ->
  513. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  514. {V1, LeftBin2} = deFloatList(Len1, LeftBin1, []),
  515. {tlistfloat, V1};
  516. decodeBin(32, LeftBin0) ->
  517. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  518. {V1, LeftBin2} = deDoubleList(Len1, LeftBin1, []),
  519. {tlistdouble, V1};
  520. decodeBin(33, LeftBin0) ->
  521. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  522. {V1, LeftBin2} = deStringList(Len1, LeftBin1, []),
  523. {tliststring, V1};
  524. decodeBin(34, LeftBin0) ->
  525. <<Len1:16/big-unsigned, LeftBin1/binary>> = LeftBin0,
  526. {V1, LeftBin2} = deRecordList(Len1, 5, LeftBin1, []),
  527. {tlistunion, V1};
  528. decodeBin(35, LeftBin0) ->
  529. <<Bool1:8/big-unsigned, LeftBin1/binary>> = LeftBin0,
  530. case Bool1 =:= 1 of
  531. true ->
  532. V1 = true;
  533. _ ->
  534. V1 = false
  535. end,
  536. <<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,
  537. <<NumBits1:8, LeftBin3/binary>> = LeftBin2,
  538. case NumBits1 of
  539. 33->
  540. <<V18:32/big-float, LeftBin4/binary>> = LeftBin3;
  541. 65 ->
  542. <<V18:64/big-float, LeftBin4/binary>> = LeftBin3;
  543. _ ->
  544. <<V18:NumBits1/big-signed, LeftBin4/binary>> = LeftBin3
  545. end,
  546. <<NumBits2:8, LeftBin5/binary>> = LeftBin4,
  547. case NumBits2 of
  548. 33->
  549. <<V19:32/big-float, LeftBin6/binary>> = LeftBin5;
  550. 65 ->
  551. <<V19:64/big-float, LeftBin6/binary>> = LeftBin5;
  552. _ ->
  553. <<V19:NumBits2/big-signed, LeftBin6/binary>> = LeftBin5
  554. end,
  555. <<NumBits3:8, LeftBin7/binary>> = LeftBin6,
  556. case NumBits3 of
  557. 33->
  558. <<V20:32/big-float, LeftBin8/binary>> = LeftBin7;
  559. 65 ->
  560. <<V20:64/big-float, LeftBin8/binary>> = LeftBin7;
  561. _ ->
  562. <<V20:NumBits3/big-signed, LeftBin8/binary>> = LeftBin7
  563. end,
  564. <<NumBits4:8, LeftBin9/binary>> = LeftBin8,
  565. case NumBits4 of
  566. 33->
  567. <<V21:32/big-float, LeftBin10/binary>> = LeftBin9;
  568. 65 ->
  569. <<V21:64/big-float, LeftBin10/binary>> = LeftBin9;
  570. _ ->
  571. <<V21:NumBits4/big-signed, LeftBin10/binary>> = LeftBin9
  572. end,
  573. <<NumBits5:8, LeftBin11/binary>> = LeftBin10,
  574. case NumBits5 of
  575. 33->
  576. <<V22:32/big-float, LeftBin12/binary>> = LeftBin11;
  577. 65 ->
  578. <<V22:64/big-float, LeftBin12/binary>> = LeftBin11;
  579. _ ->
  580. <<V22:NumBits5/big-signed, LeftBin12/binary>> = LeftBin11
  581. end,
  582. <<NumBits6:8, LeftBin13/binary>> = LeftBin12,
  583. case NumBits6 of
  584. 33->
  585. <<V23:32/big-float, LeftBin14/binary>> = LeftBin13;
  586. 65 ->
  587. <<V23:64/big-float, LeftBin14/binary>> = LeftBin13;
  588. _ ->
  589. <<V23:NumBits6/big-signed, LeftBin14/binary>> = LeftBin13
  590. end,
  591. <<NumBits7:8, LeftBin15/binary>> = LeftBin14,
  592. case NumBits7 of
  593. 33->
  594. <<V24:32/big-float, LeftBin16/binary>> = LeftBin15;
  595. 65 ->
  596. <<V24:64/big-float, LeftBin16/binary>> = LeftBin15;
  597. _ ->
  598. <<V24:NumBits7/big-signed, LeftBin16/binary>> = LeftBin15
  599. end,
  600. <<NumBits8:8, LeftBin17/binary>> = LeftBin16,
  601. case NumBits8 of
  602. 33->
  603. <<V25:32/big-float, LeftBin18/binary>> = LeftBin17;
  604. 65 ->
  605. <<V25:64/big-float, LeftBin18/binary>> = LeftBin17;
  606. _ ->
  607. <<V25:NumBits8/big-signed, LeftBin18/binary>> = LeftBin17
  608. end,
  609. <<NumBits9:8, LeftBin19/binary>> = LeftBin18,
  610. case NumBits9 of
  611. 33->
  612. <<V26:32/big-float, LeftBin20/binary>> = LeftBin19;
  613. 65 ->
  614. <<V26:64/big-float, LeftBin20/binary>> = LeftBin19;
  615. _ ->
  616. <<V26:NumBits9/big-signed, LeftBin20/binary>> = LeftBin19
  617. end,
  618. <<NumBits10:8, LeftBin21/binary>> = LeftBin20,
  619. case NumBits10 of
  620. 33->
  621. <<V27:32/big-float, LeftBin22/binary>> = LeftBin21;
  622. 65 ->
  623. <<V27:64/big-float, LeftBin22/binary>> = LeftBin21;
  624. _ ->
  625. <<V27:NumBits10/big-signed, LeftBin22/binary>> = LeftBin21
  626. end,
  627. <<V28:32/big-float, V29:64/big-float, LeftBin23/binary>> = LeftBin22,
  628. <<Len1:16/big-unsigned, V30:Len1/binary, LeftBin24/binary>> = LeftBin23,
  629. <<Len2:16/big-unsigned, V31:Len2/binary, LeftBin25/binary>> = LeftBin24,
  630. <<IsUndef1:8/big-unsigned, LeftBin26/binary>> = LeftBin25,
  631. case IsUndef1 of
  632. 0 ->
  633. V32 = undefined,
  634. LeftBin27 = LeftBin26 ;
  635. _ ->
  636. {V32, LeftBin27} = decodeRec(5, LeftBin26)
  637. end,
  638. <<Len3:16/big-unsigned, LeftBin28/binary>> = LeftBin27,
  639. {V33, LeftBin29} = deBoolList(Len3, LeftBin28, []),
  640. <<Len4:16/big-unsigned, LeftBin30/binary>> = LeftBin29,
  641. {V34, LeftBin31} = deInt8List(Len4, LeftBin30, []),
  642. <<Len5:16/big-unsigned, LeftBin32/binary>> = LeftBin31,
  643. {V35, LeftBin33} = deUint8List(Len5, LeftBin32, []),
  644. <<Len6:16/big-unsigned, LeftBin34/binary>> = LeftBin33,
  645. {V36, LeftBin35} = deInt16List(Len6, LeftBin34, []),
  646. <<Len7:16/big-unsigned, LeftBin36/binary>> = LeftBin35,
  647. {V37, LeftBin37} = deUint16List(Len7, LeftBin36, []),
  648. <<Len8:16/big-unsigned, LeftBin38/binary>> = LeftBin37,
  649. {V38, LeftBin39} = deInt32List(Len8, LeftBin38, []),
  650. <<Len9:16/big-unsigned, LeftBin40/binary>> = LeftBin39,
  651. {V39, LeftBin41} = deUint32List(Len9, LeftBin40, []),
  652. <<Len10:16/big-unsigned, LeftBin42/binary>> = LeftBin41,
  653. {V40, LeftBin43} = deInt64List(Len10, LeftBin42, []),
  654. <<Len11:16/big-unsigned, LeftBin44/binary>> = LeftBin43,
  655. {V41, LeftBin45} = deUint64List(Len11, LeftBin44, []),
  656. <<Len12:16/big-unsigned, LeftBin46/binary>> = LeftBin45,
  657. {V42, LeftBin47} = deIntegerList(Len12, LeftBin46, []),
  658. <<Len13:16/big-unsigned, LeftBin48/binary>> = LeftBin47,
  659. {V43, LeftBin49} = deIntegerList(Len13, LeftBin48, []),
  660. <<Len14:16/big-unsigned, LeftBin50/binary>> = LeftBin49,
  661. {V44, LeftBin51} = deIntegerList(Len14, LeftBin50, []),
  662. <<Len15:16/big-unsigned, LeftBin52/binary>> = LeftBin51,
  663. {V45, LeftBin53} = deIntegerList(Len15, LeftBin52, []),
  664. <<Len16:16/big-unsigned, LeftBin54/binary>> = LeftBin53,
  665. {V46, LeftBin55} = deNumberList(Len16, LeftBin54, []),
  666. <<Len17:16/big-unsigned, LeftBin56/binary>> = LeftBin55,
  667. {V47, LeftBin57} = deNumberList(Len17, LeftBin56, []),
  668. <<Len18:16/big-unsigned, LeftBin58/binary>> = LeftBin57,
  669. {V48, LeftBin59} = deNumberList(Len18, LeftBin58, []),
  670. <<Len19:16/big-unsigned, LeftBin60/binary>> = LeftBin59,
  671. {V49, LeftBin61} = deNumberList(Len19, LeftBin60, []),
  672. <<Len20:16/big-unsigned, LeftBin62/binary>> = LeftBin61,
  673. {V50, LeftBin63} = deNumberList(Len20, LeftBin62, []),
  674. <<Len21:16/big-unsigned, LeftBin64/binary>> = LeftBin63,
  675. {V51, LeftBin65} = deNumberList(Len21, LeftBin64, []),
  676. <<Len22:16/big-unsigned, LeftBin66/binary>> = LeftBin65,
  677. {V52, LeftBin67} = deFloatList(Len22, LeftBin66, []),
  678. <<Len23:16/big-unsigned, LeftBin68/binary>> = LeftBin67,
  679. {V53, LeftBin69} = deDoubleList(Len23, LeftBin68, []),
  680. <<Len24:16/big-unsigned, LeftBin70/binary>> = LeftBin69,
  681. {V54, LeftBin71} = deStringList(Len24, LeftBin70, []),
  682. <<Len25:16/big-unsigned, LeftBin72/binary>> = LeftBin71,
  683. {V55, LeftBin73} = deRecordList(Len25, 5, LeftBin72, []),
  684. {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};
  685. decodeBin(1001, LeftBin0) ->
  686. <<Len1:16/big-unsigned, V1:Len1/binary, LeftBin1/binary>> = LeftBin0,
  687. <<V2:32/big-signed, LeftBin2/binary>> = LeftBin1,
  688. <<Len2:16/big-unsigned, V3:Len2/binary, LeftBin3/binary>> = LeftBin2,
  689. <<Len3:16/big-unsigned, LeftBin4/binary>> = LeftBin3,
  690. {V4, LeftBin5} = deRecordList(Len3, 2, LeftBin4, []),
  691. {person1, V1, V2, V3, V4};
  692. decodeBin(_, _) ->
  693. {{}, <<>>}.