ULS4X3VORQZFBSNPXN76UFH2PWS2MVBA64CJQS3IR4YUHIKEF6GQC RUYSGXKQE4F7GWQ6OFI6DABOHVCNOGCYFTUQPK3XTPZ2UPGD4Y2QC WMCS3B3K2DHIXJUAMFK46GO3CVWBQS3ASBOR6WAVIEOX35GPEQYQC YDZ3R5NY7II7WX4Q5O2UQ72TMCABDPPRLEMTTIBH5DGKOLAOPOPAC IBA3VK7OHBGLEYASI7JNTXPYVTNVFT4L4RRWLNF2VGPPCONDAWMQC CZG24QKIB45EL7PK4UA6XVG3VEVKI7OAQXN4YMFUKKI2MXLHRANQC 755UGKECZ3PFYEA2TFFOUZTF27CRQTBZWO7UYFU6WQDJMZDBVPRAC YWCRGWVDIMCPXBQFM23MKCYZCXJJSD733NJEPB6WUU4G4BSREILAC OJ6KWAG7XUCYNQ6T3FRJK2QOP7DBO26PZEWDVH3Q2MJKIBMNWRPQC 55WLMLEEVBRSTAFRZ5RGF7TOGUF5OPVCPA2TMHAQK45OUO7PA3YQC Decoded = posts:decode_post_text(Bin),[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}, {channel, Channel}, {text, Text}
Decoded = posts:decode(Bin),[[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}],[ {channel, Channel}, {text, Text}]
Decoded = posts:decode_post_delete(Bin),[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}, {hashes, Hashes}
Decoded = posts:decode(Bin),[[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}],[ {hashes, Hashes} ]
Decoded = posts:decode_post_info(Bin),[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}, {infos, Infos}
Decoded = posts:decode(Bin),[[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}],[ {infos, Infos} ]
Decoded = posts:decode_post_topic(Bin),[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}, {channel, Channel}, {topic, Topic}
Decoded = posts:decode(Bin),[[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}],[ {channel, Channel}, {topic, Topic}]
Decoded = posts:decode_post_join(Bin),[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}, {channel, Channel}] = Decoded,
Decoded = posts:decode(Bin),[[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}],[ {channel, Channel} ]]= Decoded,
Decoded = posts:decode_post_leave(Bin),[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}, {channel, Channel}
Decoded = posts:decode(Bin),[[ {pubKey, _PubKey}, {links, _Links}, {postType, _PostType}, {timestamp, _TimeStamp}], [ {channel, Channel} ]
assert_post(Post, TestObj) ->?assertEqual(maps:get(<<"postType">>, TestObj), proplists:get_value(postType, Post)),?assertEqual(maps:get(<<"timestamp">>, TestObj), proplists:get_value(timestamp, Post)),?assertEqual(length(maps:get(<<"links">>, TestObj)), length(proplists:get_value(links, Post))),
assert_post([Header, _], TestObj) ->?assertEqual(maps:get(<<"postType">>, TestObj), proplists:get_value(postType, Header)),?assertEqual(maps:get(<<"timestamp">>, TestObj), proplists:get_value(timestamp, Header)),?assertEqual(length(maps:get(<<"links">>, TestObj)), length(proplists:get_value(links, Header))),
-export([decode_post_text/1, decode_post_delete/1, decode_post_info/1, decode_post_topic/1, decode_post_join/1, decode_post_leave/1]).
-export([decode/1]).%-export([decode_post_text/1, decode_post_delete/1, decode_post_info/1, decode_post_topic/1, decode_post_join/1, decode_post_leave/1]).
decode_post_text(Data) ->Header = decode_post_header(Data),Body = proplists:get_value(postBody, Header),
decode(Data) ->[Header, Body] = decode_post_header(Data),Decoded = case proplists:get_value(postType, Header) of0 -> decode_post_text(Body);1 -> decode_post_delete(Body);2 -> decode_post_info(Body);3 -> decode_post_topic(Body);4 -> decode_post_join(Body);5 -> decode_post_leave(Body)end,[Header, Decoded].decode_post_text(Body) ->
<< PubKey:32/binary, Signature:64/binary, SignedData/binary>> = Data,true = enacl:sign_verify_detached(Signature, SignedData, PubKey),{NumLinks, Rest} = wire:decode_varint(SignedData),<<LinkData:(32*NumLinks)/binary, Rest2/binary>> = Rest,Links = [Link || <<Link:32/binary>> <= LinkData],case length(Links) =:= NumLinks offalse ->
<< PubKey:32/binary, Signature:64/binary, SignedData/binary>> = Data,true = enacl:sign_verify_detached(Signature, SignedData, PubKey),{NumLinks, Rest} = wire:decode_varint(SignedData),<<LinkData:(32*NumLinks)/binary, Rest2/binary>> = Rest,Links = [Link || <<Link:32/binary>> <= LinkData],case length(Links) =:= NumLinks offalse ->
[PostType, Timestamp, PostBody] = wire:decode_varints(Rest2, 2),[ {pubKey, PubKey}, {links, Links}, {postType, PostType}, {timestamp, Timestamp}, {postBody, PostBody}]end.
[PostType, Timestamp, PostBody] = wire:decode_varints(Rest2, 2),[[ {pubKey, PubKey}, {links, Links}, {postType, PostType}, {timestamp, Timestamp}],PostBody]end.