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

read(16501, _) ->
    {ok, []};
read(16502, Bin0) ->
    <<ChildSex:8, Bin1/binary>> = Bin0, 
    {ChildName, _Bin2} = pt:read_string(Bin1), 
    {ok, [ChildSex, ChildName]};
read(16503, Bin0) ->
    {ChildName, _Bin1} = pt:read_string(Bin0), 
    {ok, [ChildName]};
read(16504, Bin0) ->
    <<IsAuto:8, Bin1/binary>> = Bin0, 
    <<GoodsId:32, Bin2/binary>> = Bin1, 
    <<GoodsNum:8, _Bin3/binary>> = Bin2, 
    {ok, [IsAuto, GoodsId, GoodsNum]};
read(16505, _) ->
    {ok, []};
read(16506, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<Id:32, Bin2/binary>> = Bin1, 
    <<Num:8, _Bin3/binary>> = Bin2, 
    {ok, [Type, Id, Num]};
read(16507, _) ->
    {ok, []};
read(16508, _) ->
    {ok, []};
read(16509, Bin0) ->
    <<Channel:8, _Bin1/binary>> = Bin0, 
    {ok, [Channel]};
read(16510, Bin0) ->
    <<BeVoteRoleId:64, _Bin1/binary>> = Bin0, 
    {ok, [BeVoteRoleId]};
read(16511, Bin0) ->
    <<RoleId:64, _Bin1/binary>> = Bin0, 
    {ok, [RoleId]};
read(16512, _) ->
    {ok, []};
read(16513, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<SkillId:32, _Bin2/binary>> = Bin1, 
    {ok, [Type, SkillId]};
read(16514, _) ->
    {ok, []};
read(16515, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<VehicleId:32, _Bin2/binary>> = Bin1, 
    {ok, [Type, VehicleId]};
read(16516, _) ->
    {ok, []};
read(16517, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<VehicleId:32, _Bin2/binary>> = Bin1, 
    {ok, [Type, VehicleId]};
read(16518, _) ->
    {ok, []};
read(16519, _) ->
    {ok, []};
read(16520, _) ->
    {ok, []};
read(16521, Bin0) ->
    <<GoodsId:64, _Bin1/binary>> = Bin0, 
    {ok, [GoodsId]};
read(16522, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<SlotId:8, Bin2/binary>> = Bin1, 
    <<GoodsId:64, _Bin3/binary>> = Bin2, 
    {ok, [Type, SlotId, GoodsId]};
read(16523, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<GoodsId:64, Bin2/binary>> = Bin1, 
    <<AimLv:16, _Bin3/binary>> = Bin2, 
    {ok, [Type, GoodsId, AimLv]};
read(16524, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<GoodsId:64, _Args01/binary>> = RestBin0, 
        {GoodsId,_Args01}
        end,
    {GoodsList, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [GoodsList]};
read(16525, _) ->
    {ok, []};
read(16526, Bin0) ->
    <<SlotId:8, _Bin1/binary>> = Bin0, 
    {ok, [SlotId]};
read(16527, Bin0) ->
    <<SlotId:8, _Bin1/binary>> = Bin0, 
    {ok, [SlotId]};
read(16528, Bin0) ->
    <<SlotId:8, _Bin1/binary>> = Bin0, 
    {ok, [SlotId]};
read(16529, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(16530, Bin0) ->
    <<Option:8, Bin1/binary>> = Bin0, 
    <<Type:8, Bin2/binary>> = Bin1, 
    <<FashionId:32, _Bin3/binary>> = Bin2, 
    {ok, [Option, Type, FashionId]};
read(16531, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<FashionId:32, Bin2/binary>> = Bin1, 
    <<IsAuto:8, _Bin3/binary>> = Bin2, 
    {ok, [Type, FashionId, IsAuto]};
read(16532, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<SlotId:32, _Bin2/binary>> = Bin1, 
    {ok, [Type, SlotId]};
read(16533, _) ->
    {ok, []};
read(16534, _) ->
    {ok, []};
read(16535, Bin0) ->
    <<SuitType:8, _Bin1/binary>> = Bin0, 
    {ok, [SuitType]};
read(16536, Bin0) ->
    <<SuitType:8, Bin1/binary>> = Bin0, 
    <<ToyId:32, _Bin2/binary>> = Bin1, 
    {ok, [SuitType, ToyId]};
read(16537, _) ->
    {ok, []};
read(16538, _) ->
    {ok, []};
read(16539, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<RewardId:8, _Bin2/binary>> = Bin1, 
    {ok, [Type, RewardId]};
read(16540, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(_Cmd, _R) -> {error, no_match}.

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

write (16501,[
    ChildName,
    ChildSex,
    ChildAgeYear,
    ChildAgeMonth,
    ChildAgeExp,
    HeartLinkExp,
    HeartReward,
    ChildPower,
    IsFollow,
    CanCarry,
    AdoptTime,
    ShareReward,
    YestRank,
    YestReward
] = Src_Data) ->
    Bin_ChildName = pt:write_string(ChildName), 

    BinList_HeartReward = [
        item_to_bin_0(HeartReward_Item) || HeartReward_Item <- HeartReward
    ], 

    HeartReward_Len = length(HeartReward), 
    Bin_HeartReward = list_to_binary(BinList_HeartReward),

    Data = <<
        Bin_ChildName/binary,
        ChildSex:8,
        ChildAgeYear:8,
        ChildAgeMonth:8,
        ChildAgeExp:32,
        HeartLinkExp:32,
        HeartReward_Len:16, Bin_HeartReward/binary,
        ChildPower:64,
        IsFollow:8,
        CanCarry:16,
        AdoptTime:32,
        ShareReward:8,
        YestRank:16,
        YestReward:8
    >>,
    {ok, pt:encode(16501, Data, Src_Data)};

write (16502,[
    ChildName,
    ChildSex,
    ChildAgeYear,
    ChildAgeMonth,
    ChildAgeExp,
    ChildPower
] = Src_Data) ->
    Bin_ChildName = pt:write_string(ChildName), 

    Data = <<
        Bin_ChildName/binary,
        ChildSex:8,
        ChildAgeYear:8,
        ChildAgeMonth:8,
        ChildAgeExp:32,
        ChildPower:64
    >>,
    {ok, pt:encode(16502, Data, Src_Data)};

write (16503,[
    ChildName
] = Src_Data) ->
    Bin_ChildName = pt:write_string(ChildName), 

    Data = <<
        Bin_ChildName/binary
    >>,
    {ok, pt:encode(16503, Data, Src_Data)};

write (16504,[
    ChildAgeYear,
    ChildAgeMonth,
    ChildAgeExp
] = Src_Data) ->
    Data = <<
        ChildAgeYear:8,
        ChildAgeMonth:8,
        ChildAgeExp:32
    >>,
    {ok, pt:encode(16504, Data, Src_Data)};

write (16505,[
    TaskList
] = Src_Data) ->
    BinList_TaskList = [
        item_to_bin_1(TaskList_Item) || TaskList_Item <- TaskList
    ], 

    TaskList_Len = length(TaskList), 
    Bin_TaskList = list_to_binary(BinList_TaskList),

    Data = <<
        TaskList_Len:16, Bin_TaskList/binary
    >>,
    {ok, pt:encode(16505, Data, Src_Data)};

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

write (16507,[
    MyRank,
    RankList
] = Src_Data) ->
    BinList_MyRank = [
        item_to_bin_2(MyRank_Item) || MyRank_Item <- MyRank
    ], 

    MyRank_Len = length(MyRank), 
    Bin_MyRank = list_to_binary(BinList_MyRank),

    BinList_RankList = [
        item_to_bin_3(RankList_Item) || RankList_Item <- RankList
    ], 

    RankList_Len = length(RankList), 
    Bin_RankList = list_to_binary(BinList_RankList),

    Data = <<
        MyRank_Len:16, Bin_MyRank/binary,
        RankList_Len:16, Bin_RankList/binary
    >>,
    {ok, pt:encode(16507, Data, Src_Data)};

write (16508,[
    BeVoteLog
] = Src_Data) ->
    BinList_BeVoteLog = [
        item_to_bin_4(BeVoteLog_Item) || BeVoteLog_Item <- BeVoteLog
    ], 

    BeVoteLog_Len = length(BeVoteLog), 
    Bin_BeVoteLog = list_to_binary(BinList_BeVoteLog),

    Data = <<
        BeVoteLog_Len:16, Bin_BeVoteLog/binary
    >>,
    {ok, pt:encode(16508, Data, Src_Data)};

write (16509,[
    Channel,
    HasShareCount
] = Src_Data) ->
    Data = <<
        Channel:8,
        HasShareCount:8
    >>,
    {ok, pt:encode(16509, Data, Src_Data)};

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

write (16511,[
    RoleId,
    BeVotedNum
] = Src_Data) ->
    Data = <<
        RoleId:64,
        BeVotedNum:32
    >>,
    {ok, pt:encode(16511, Data, Src_Data)};

write (16512,[
    SkillList
] = Src_Data) ->
    BinList_SkillList = [
        item_to_bin_5(SkillList_Item) || SkillList_Item <- SkillList
    ], 

    SkillList_Len = length(SkillList), 
    Bin_SkillList = list_to_binary(BinList_SkillList),

    Data = <<
        SkillList_Len:16, Bin_SkillList/binary
    >>,
    {ok, pt:encode(16512, Data, Src_Data)};

write (16513,[
    SkillId,
    SkillLv
] = Src_Data) ->
    Data = <<
        SkillId:32,
        SkillLv:16
    >>,
    {ok, pt:encode(16513, Data, Src_Data)};

write (16514,[
    ShowVehicle,
    VehicleList
] = Src_Data) ->
    BinList_VehicleList = [
        item_to_bin_6(VehicleList_Item) || VehicleList_Item <- VehicleList
    ], 

    VehicleList_Len = length(VehicleList), 
    Bin_VehicleList = list_to_binary(BinList_VehicleList),

    Data = <<
        ShowVehicle:32,
        VehicleList_Len:16, Bin_VehicleList/binary
    >>,
    {ok, pt:encode(16514, Data, Src_Data)};

write (16515,[
    VehicleId,
    VehicleStage
] = Src_Data) ->
    Data = <<
        VehicleId:32,
        VehicleStage:16
    >>,
    {ok, pt:encode(16515, Data, Src_Data)};

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

write (16517,[
    Type,
    VehicleId
] = Src_Data) ->
    Data = <<
        Type:8,
        VehicleId:32
    >>,
    {ok, pt:encode(16517, Data, Src_Data)};

write (16518,[
    RoleId,
    ChildSex,
    ChildAgeMonth,
    ChildIsFollow,
    VehicleId,
    FashionList
] = Src_Data) ->
    BinList_FashionList = [
        item_to_bin_7(FashionList_Item) || FashionList_Item <- FashionList
    ], 

    FashionList_Len = length(FashionList), 
    Bin_FashionList = list_to_binary(BinList_FashionList),

    Data = <<
        RoleId:64,
        ChildSex:8,
        ChildAgeMonth:8,
        ChildIsFollow:8,
        VehicleId:32,
        FashionList_Len:16, Bin_FashionList/binary
    >>,
    {ok, pt:encode(16518, Data, Src_Data)};

write (16519,[
    RoleList
] = Src_Data) ->
    BinList_RoleList = [
        item_to_bin_8(RoleList_Item) || RoleList_Item <- RoleList
    ], 

    RoleList_Len = length(RoleList), 
    Bin_RoleList = list_to_binary(BinList_RoleList),

    Data = <<
        RoleList_Len:16, Bin_RoleList/binary
    >>,
    {ok, pt:encode(16519, Data, Src_Data)};

write (16520,[
    CarryWeight,
    CanCarry,
    SlotList,
    BagList
] = Src_Data) ->
    BinList_SlotList = [
        item_to_bin_9(SlotList_Item) || SlotList_Item <- SlotList
    ], 

    SlotList_Len = length(SlotList), 
    Bin_SlotList = list_to_binary(BinList_SlotList),

    BinList_BagList = [
        item_to_bin_10(BagList_Item) || BagList_Item <- BagList
    ], 

    BagList_Len = length(BagList), 
    Bin_BagList = list_to_binary(BinList_BagList),

    Data = <<
        CarryWeight:16,
        CanCarry:16,
        SlotList_Len:16, Bin_SlotList/binary,
        BagList_Len:16, Bin_BagList/binary
    >>,
    {ok, pt:encode(16520, Data, Src_Data)};

write (16521,[
    GoodsId,
    GoodsTypeId,
    Lv,
    IsOnSlot
] = Src_Data) ->
    Data = <<
        GoodsId:64,
        GoodsTypeId:32,
        Lv:16,
        IsOnSlot:8
    >>,
    {ok, pt:encode(16521, Data, Src_Data)};

write (16522,[
    Type,
    SlotId,
    GoodsId
] = Src_Data) ->
    Data = <<
        Type:8,
        SlotId:8,
        GoodsId:64
    >>,
    {ok, pt:encode(16522, Data, Src_Data)};

write (16523,[
    Type,
    GoodsId,
    Lv
] = Src_Data) ->
    Data = <<
        Type:8,
        GoodsId:64,
        Lv:16
    >>,
    {ok, pt:encode(16523, Data, Src_Data)};

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

write (16525,[
    SlotList
] = Src_Data) ->
    BinList_SlotList = [
        item_to_bin_11(SlotList_Item) || SlotList_Item <- SlotList
    ], 

    SlotList_Len = length(SlotList), 
    Bin_SlotList = list_to_binary(BinList_SlotList),

    Data = <<
        SlotList_Len:16, Bin_SlotList/binary
    >>,
    {ok, pt:encode(16525, Data, Src_Data)};

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

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

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

write (16529,[
    Type,
    FashionList
] = Src_Data) ->
    BinList_FashionList = [
        item_to_bin_12(FashionList_Item) || FashionList_Item <- FashionList
    ], 

    FashionList_Len = length(FashionList), 
    Bin_FashionList = list_to_binary(BinList_FashionList),

    Data = <<
        Type:8,
        FashionList_Len:16, Bin_FashionList/binary
    >>,
    {ok, pt:encode(16529, Data, Src_Data)};

write (16530,[
    Option,
    Type,
    FashionId
] = Src_Data) ->
    Data = <<
        Option:8,
        Type:8,
        FashionId:32
    >>,
    {ok, pt:encode(16530, Data, Src_Data)};

write (16531,[
    Type,
    FashionId,
    Lv
] = Src_Data) ->
    Data = <<
        Type:8,
        FashionId:32,
        Lv:16
    >>,
    {ok, pt:encode(16531, Data, Src_Data)};

write (16532,[
    Type,
    SlotId
] = Src_Data) ->
    Data = <<
        Type:8,
        SlotId:32
    >>,
    {ok, pt:encode(16532, Data, Src_Data)};

write (16533,[
    ToyBoxLv,
    ToyList
] = Src_Data) ->
    BinList_ToyList = [
        item_to_bin_13(ToyList_Item) || ToyList_Item <- ToyList
    ], 

    ToyList_Len = length(ToyList), 
    Bin_ToyList = list_to_binary(BinList_ToyList),

    Data = <<
        ToyBoxLv:16,
        ToyList_Len:16, Bin_ToyList/binary
    >>,
    {ok, pt:encode(16533, Data, Src_Data)};

write (16534,[
    SuitList
] = Src_Data) ->
    BinList_SuitList = [
        item_to_bin_14(SuitList_Item) || SuitList_Item <- SuitList
    ], 

    SuitList_Len = length(SuitList), 
    Bin_SuitList = list_to_binary(BinList_SuitList),

    Data = <<
        SuitList_Len:16, Bin_SuitList/binary
    >>,
    {ok, pt:encode(16534, Data, Src_Data)};

write (16535,[
    SuitType,
    Progress,
    Status,
    Time
] = Src_Data) ->
    Data = <<
        SuitType:8,
        Progress:8,
        Status:8,
        Time:64
    >>,
    {ok, pt:encode(16535, Data, Src_Data)};

write (16536,[
    SuitType,
    ToyId
] = Src_Data) ->
    Data = <<
        SuitType:8,
        ToyId:32
    >>,
    {ok, pt:encode(16536, Data, Src_Data)};

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

write (16538,[
    Sequence,
    Progress,
    TaskState
] = Src_Data) ->
    Data = <<
        Sequence:8,
        Progress:8,
        TaskState:8
    >>,
    {ok, pt:encode(16538, Data, Src_Data)};

write (16539,[
    HeartReward
] = Src_Data) ->
    BinList_HeartReward = [
        item_to_bin_15(HeartReward_Item) || HeartReward_Item <- HeartReward
    ], 

    HeartReward_Len = length(HeartReward), 
    Bin_HeartReward = list_to_binary(BinList_HeartReward),

    Data = <<
        HeartReward_Len:16, Bin_HeartReward/binary
    >>,
    {ok, pt:encode(16539, Data, Src_Data)};

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

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


item_to_bin_0 ({
    RewardId,
    Status
}) ->
    Data = <<
        RewardId:8,
        Status:8
    >>,
    Data.
item_to_bin_1 ({
    Sequence,
    Progress,
    TaskState
}) ->
    Data = <<
        Sequence:8,
        Progress:8,
        TaskState:8
    >>,
    Data.
item_to_bin_2 ({
    Rank,
    Figure,
    ChildName,
    RolePower,
    VoteNum
}) ->
    Bin_Figure = pt:write_figure(Figure), 

    Bin_ChildName = pt:write_string(ChildName), 

    Data = <<
        Rank:8,
        Bin_Figure/binary,
        Bin_ChildName/binary,
        RolePower:64,
        VoteNum:32
    >>,
    Data.
item_to_bin_3 ({
    Rank,
    Figure,
    ChildName,
    RolePower,
    VoteNum
}) ->
    Bin_Figure = pt:write_figure(Figure), 

    Bin_ChildName = pt:write_string(ChildName), 

    Data = <<
        Rank:8,
        Bin_Figure/binary,
        Bin_ChildName/binary,
        RolePower:64,
        VoteNum:32
    >>,
    Data.
item_to_bin_4 ({
    VoteRoleId,
    VoteRoleName,
    Time,
    FeedBackStatus
}) ->
    Bin_VoteRoleName = pt:write_string(VoteRoleName), 

    Data = <<
        VoteRoleId:64,
        Bin_VoteRoleName/binary,
        Time:32,
        FeedBackStatus:8
    >>,
    Data.
item_to_bin_5 ({
    SkillId,
    SkillLv
}) ->
    Data = <<
        SkillId:32,
        SkillLv:16
    >>,
    Data.
item_to_bin_6 ({
    VehicleId,
    VehicleStage
}) ->
    Data = <<
        VehicleId:32,
        VehicleStage:16
    >>,
    Data.
item_to_bin_7 ({
    Type,
    FashionId
}) ->
    Data = <<
        Type:8,
        FashionId:32
    >>,
    Data.
item_to_bin_8 ({
    RoleId,
    VoteTimes
}) ->
    Data = <<
        RoleId:64,
        VoteTimes:8
    >>,
    Data.
item_to_bin_9 ({
    SlotId,
    IsOpen,
    GoodsId,
    GoodsTypeId,
    Lv
}) ->
    Data = <<
        SlotId:8,
        IsOpen:8,
        GoodsId:64,
        GoodsTypeId:32,
        Lv:16
    >>,
    Data.
item_to_bin_10 ({
    GoodsId,
    GoodsTypeId,
    Lv
}) ->
    Data = <<
        GoodsId:64,
        GoodsTypeId:32,
        Lv:16
    >>,
    Data.
item_to_bin_11 ({
    SlotId,
    IsOpen,
    UseStatus,
    StartTime,
    SelectId
}) ->
    Data = <<
        SlotId:8,
        IsOpen:8,
        UseStatus:8,
        StartTime:32,
        SelectId:16
    >>,
    Data.
item_to_bin_12 ({
    FashionId,
    Lv,
    State
}) ->
    Data = <<
        FashionId:32,
        Lv:16,
        State:8
    >>,
    Data.
item_to_bin_13 (
    ToyId
) ->
    Data = <<
        ToyId:32
    >>,
    Data.
item_to_bin_14 ({
    SuitType,
    Progress,
    Status,
    Time
}) ->
    Data = <<
        SuitType:8,
        Progress:8,
        Status:8,
        Time:64
    >>,
    Data.
item_to_bin_15 ({
    RewardId,
    Status
}) ->
    Data = <<
        RewardId:8,
        Status:8
    >>,
    Data.
