-module(pt_603).
-include("common.hrl").
-export([
        read/2,
        write/2
    ]).

read(60300, _) ->
    {ok, []};
read(60301, _) ->
    {ok, []};
read(60304, Bin0) ->
    <<Opty:8, Bin1/binary>> = Bin0, 
    <<Args:8, _Bin2/binary>> = Bin1, 
    {ok, [Opty, Args]};
read(60305, _) ->
    {ok, []};
read(60306, Bin0) ->
    <<Rid:64, _Bin1/binary>> = Bin0, 
    {ok, [Rid]};
read(60307, Bin0) ->
    <<Fact:8, _Bin1/binary>> = Bin0, 
    {ok, [Fact]};
read(60308, _) ->
    {ok, []};
read(60309, Bin0) ->
    <<Aim:64, _Bin1/binary>> = Bin0, 
    {ok, [Aim]};
read(60310, _) ->
    {ok, []};
read(60311, _) ->
    {ok, []};
read(60312, Bin0) ->
    <<Opty:8, _Bin1/binary>> = Bin0, 
    {ok, [Opty]};
read(60313, _) ->
    {ok, []};
read(60314, _) ->
    {ok, []};
read(60315, _) ->
    {ok, []};
read(60316, Bin0) ->
    <<Day:8, _Bin1/binary>> = Bin0, 
    {ok, [Day]};
read(_Cmd, _R) -> {error, no_match}.

write (60300,[
    DirectorRole
] = Src_Data) ->
    BinList_DirectorRole = [
        item_to_bin_0(DirectorRole_Item) || DirectorRole_Item <- DirectorRole
    ], 

    DirectorRole_Len = length(DirectorRole), 
    Bin_DirectorRole = list_to_binary(BinList_DirectorRole),

    Data = <<
        DirectorRole_Len:16, Bin_DirectorRole/binary
    >>,
    {ok, pt:encode(60300, Data, Src_Data)};

write (60301,[
    Process,
    DotList,
    Arms,
    Post,
    RankScore,
    Missions
] = Src_Data) ->
    BinList_DotList = [
        item_to_bin_1(DotList_Item) || DotList_Item <- DotList
    ], 

    DotList_Len = length(DotList), 
    Bin_DotList = list_to_binary(BinList_DotList),

    BinList_Missions = [
        item_to_bin_2(Missions_Item) || Missions_Item <- Missions
    ], 

    Missions_Len = length(Missions), 
    Bin_Missions = list_to_binary(BinList_Missions),

    Data = <<
        Process:32,
        DotList_Len:16, Bin_DotList/binary,
        Arms:32,
        Post:8,
        RankScore:32,
        Missions_Len:16, Bin_Missions/binary
    >>,
    {ok, pt:encode(60301, Data, Src_Data)};

write (60302,[
    Id,
    Bar,
    State
] = Src_Data) ->
    Data = <<
        Id:16,
        Bar:16,
        State:8
    >>,
    {ok, pt:encode(60302, Data, Src_Data)};

write (60303,[
    Updatas
] = Src_Data) ->
    BinList_Updatas = [
        item_to_bin_3(Updatas_Item) || Updatas_Item <- Updatas
    ], 

    Updatas_Len = length(Updatas), 
    Bin_Updatas = list_to_binary(BinList_Updatas),

    Data = <<
        Updatas_Len:16, Bin_Updatas/binary
    >>,
    {ok, pt:encode(60303, Data, Src_Data)};

write (60304,[
    Res,
    Opty,
    Args
] = Src_Data) ->
    Data = <<
        Res:32,
        Opty:8,
        Args:8
    >>,
    {ok, pt:encode(60304, Data, Src_Data)};

write (60305,[
    Res,
    Post
] = Src_Data) ->
    Data = <<
        Res:32,
        Post:8
    >>,
    {ok, pt:encode(60305, Data, Src_Data)};

write (60306,[
    Figure,
    Time
] = Src_Data) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        Bin_Figure/binary,
        Time:32
    >>,
    {ok, pt:encode(60306, Data, Src_Data)};

write (60307,[
    Fact,
    Myrank,
    Myscore,
    Ranks
] = Src_Data) ->
    BinList_Ranks = [
        item_to_bin_4(Ranks_Item) || Ranks_Item <- Ranks
    ], 

    Ranks_Len = length(Ranks), 
    Bin_Ranks = list_to_binary(BinList_Ranks),

    Data = <<
        Fact:8,
        Myrank:16,
        Myscore:32,
        Ranks_Len:16, Bin_Ranks/binary
    >>,
    {ok, pt:encode(60307, Data, Src_Data)};

write (60308,[
    ClickList,
    LastRank,
    DayAward
] = Src_Data) ->
    BinList_ClickList = [
        item_to_bin_5(ClickList_Item) || ClickList_Item <- ClickList
    ], 

    ClickList_Len = length(ClickList), 
    Bin_ClickList = list_to_binary(BinList_ClickList),

    Data = <<
        ClickList_Len:16, Bin_ClickList/binary,
        LastRank:16,
        DayAward:8
    >>,
    {ok, pt:encode(60308, Data, Src_Data)};

write (60309,[
    Res,
    Aim
] = Src_Data) ->
    Data = <<
        Res:32,
        Aim:64
    >>,
    {ok, pt:encode(60309, Data, Src_Data)};

write (60310,[
    Res
] = Src_Data) ->
    Data = <<
        Res:32
    >>,
    {ok, pt:encode(60310, Data, Src_Data)};

write (60311,[
    Ranks
] = Src_Data) ->
    BinList_Ranks = [
        item_to_bin_6(Ranks_Item) || Ranks_Item <- Ranks
    ], 

    Ranks_Len = length(Ranks), 
    Bin_Ranks = list_to_binary(BinList_Ranks),

    Data = <<
        Ranks_Len:16, Bin_Ranks/binary
    >>,
    {ok, pt:encode(60311, Data, Src_Data)};

write (60312,[
    Opty,
    TimeLogs
] = Src_Data) ->
    BinList_TimeLogs = [
        item_to_bin_7(TimeLogs_Item) || TimeLogs_Item <- TimeLogs
    ], 

    TimeLogs_Len = length(TimeLogs), 
    Bin_TimeLogs = list_to_binary(BinList_TimeLogs),

    Data = <<
        Opty:8,
        TimeLogs_Len:16, Bin_TimeLogs/binary
    >>,
    {ok, pt:encode(60312, Data, Src_Data)};

write (60313,[
    Ranks,
    MyRank
] = Src_Data) ->
    BinList_Ranks = [
        item_to_bin_10(Ranks_Item) || Ranks_Item <- Ranks
    ], 

    Ranks_Len = length(Ranks), 
    Bin_Ranks = list_to_binary(BinList_Ranks),

    Data = <<
        Ranks_Len:16, Bin_Ranks/binary,
        MyRank:16
    >>,
    {ok, pt:encode(60313, Data, Src_Data)};

write (60314,[
    Ranks
] = Src_Data) ->
    BinList_Ranks = [
        item_to_bin_11(Ranks_Item) || Ranks_Item <- Ranks
    ], 

    Ranks_Len = length(Ranks), 
    Bin_Ranks = list_to_binary(BinList_Ranks),

    Data = <<
        Ranks_Len:16, Bin_Ranks/binary
    >>,
    {ok, pt:encode(60314, Data, Src_Data)};

write (60315,[
    Lists
] = Src_Data) ->
    BinList_Lists = [
        item_to_bin_12(Lists_Item) || Lists_Item <- Lists
    ], 

    Lists_Len = length(Lists), 
    Bin_Lists = list_to_binary(BinList_Lists),

    Data = <<
        Lists_Len:16, Bin_Lists/binary
    >>,
    {ok, pt:encode(60315, Data, Src_Data)};

write (60316,[
    Res,
    Day
] = Src_Data) ->
    Data = <<
        Res:16,
        Day:8
    >>,
    {ok, pt:encode(60316, Data, Src_Data)};

write (60317,[
] = Src_Data) ->
    Data = <<
    >>,
    {ok, pt:encode(60317, Data, Src_Data)};

write(_Cmd, _R) -> ?DEBUG("no_match:~p,~p~n", [_Cmd, _R]), {ok, pt:pack(0, <<>>)}.


item_to_bin_0 ({
    Pos,
    Rid,
    Figure,
    Time
}) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        Pos:8,
        Rid:64,
        Bin_Figure/binary,
        Time:32
    >>,
    Data.
item_to_bin_1 (
    Hot
) ->
    Data = <<
        Hot:8
    >>,
    Data.
item_to_bin_2 ({
    Id,
    Bar,
    State
}) ->
    Data = <<
        Id:16,
        Bar:16,
        State:8
    >>,
    Data.
item_to_bin_3 ({
    Kdata,
    Vdata
}) ->
    Data = <<
        Kdata:8,
        Vdata:32
    >>,
    Data.
item_to_bin_4 ({
    Rank,
    Rid,
    SerNum,
    Figure,
    Gname,
    Post,
    Score
}) ->
    Bin_Figure = pt:write_picture(Figure), 

    Bin_Gname = pt:write_string(Gname), 

    Data = <<
        Rank:16,
        Rid:64,
        SerNum:16,
        Bin_Figure/binary,
        Bin_Gname/binary,
        Post:8,
        Score:32
    >>,
    Data.
item_to_bin_5 (
    ClickRole
) ->
    Data = <<
        ClickRole:64
    >>,
    Data.
item_to_bin_6 ({
    Rank,
    Rid,
    Vip,
    Svip,
    SerNum,
    Name,
    Score
}) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        Rank:16,
        Rid:64,
        Vip:8,
        Svip:8,
        SerNum:16,
        Bin_Name/binary,
        Score:32
    >>,
    Data.
item_to_bin_7 ({
    Issue,
    Servers
}) ->
    BinList_Servers = [
        item_to_bin_8(Servers_Item) || Servers_Item <- Servers
    ], 

    Servers_Len = length(Servers), 
    Bin_Servers = list_to_binary(BinList_Servers),

    Data = <<
        Issue:32,
        Servers_Len:16, Bin_Servers/binary
    >>,
    Data.
item_to_bin_8 ({
    SerNum,
    Directors
}) ->
    BinList_Directors = [
        item_to_bin_9(Directors_Item) || Directors_Item <- Directors
    ], 

    Directors_Len = length(Directors), 
    Bin_Directors = list_to_binary(BinList_Directors),

    Data = <<
        SerNum:16,
        Directors_Len:16, Bin_Directors/binary
    >>,
    Data.
item_to_bin_9 ({
    Rid,
    Pos,
    Time,
    Figure
}) ->
    Bin_Figure = pt:write_picture(Figure), 

    Data = <<
        Rid:64,
        Pos:8,
        Time:32,
        Bin_Figure/binary
    >>,
    Data.
item_to_bin_10 ({
    Rank,
    Rid,
    Vip,
    Svip,
    SerNum,
    Name,
    Sex,
    Faction,
    Pos
}) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        Rank:16,
        Rid:64,
        Vip:8,
        Svip:8,
        SerNum:16,
        Bin_Name/binary,
        Sex:8,
        Faction:8,
        Pos:8
    >>,
    Data.
item_to_bin_11 ({
    Rank,
    ServerNum,
    GuildName,
    Score
}) ->
    Bin_GuildName = pt:write_string(GuildName), 

    Data = <<
        Rank:16,
        ServerNum:16,
        Bin_GuildName/binary,
        Score:64
    >>,
    Data.
item_to_bin_12 (
    Day
) ->
    Data = <<
        Day:8
    >>,
    Data.
