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

read(14000, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(14001, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(14002, Bin0) ->
    {RoleName, _Bin1} = pt:read_string(Bin0), 
    {ok, [RoleName]};
read(14003, Bin0) ->
    <<BeAskId:64, _Bin1/binary>> = Bin0, 
    {ok, [BeAskId]};
read(14004, Bin0) ->
    <<ResponseType:8, _Bin1/binary>> = Bin0, 
    {ok, [ResponseType]};
read(14005, Bin0) ->
    <<AskId:64, Bin1/binary>> = Bin0, 
    <<ResponseType:8, _Bin2/binary>> = Bin1, 
    {ok, [AskId, ResponseType]};
read(14006, _) ->
    {ok, []};
read(14007, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<RoleId:64, _Bin2/binary>> = Bin1, 
    {ok, [Type, RoleId]};
read(14010, Bin0) ->
    <<RoleId:64, _Bin1/binary>> = Bin0, 
    {ok, [RoleId]};
read(14011, Bin0) ->
    <<RoleId:64, _Bin1/binary>> = Bin0, 
    {ok, [RoleId]};
read(14015, _) ->
    {ok, []};
read(14016, _) ->
    {ok, []};
read(14017, Bin0) ->
    <<Torole:64, Bin1/binary>> = Bin0, 
    <<Type:8, _Bin2/binary>> = Bin1, 
    {ok, [Torole, Type]};
read(14018, Bin0) ->
    <<Fromid:64, Bin1/binary>> = Bin0, 
    <<Type:8, _Bin2/binary>> = Bin1, 
    {ok, [Fromid, Type]};
read(14019, _) ->
    {ok, []};
read(14020, Bin0) ->
    <<RoleId:64, _Bin1/binary>> = Bin0, 
    {ok, [RoleId]};
read(14021, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<RoleId:64, _Args1/binary>> = RestBin0, 
        {RoleId,_Args1}
        end,
    {FriendList, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [FriendList]};
read(14022, Bin0) ->
    FunArray0 = fun(<<RestBin0/binary>>) -> 
        <<RoleId:64, _Args1/binary>> = RestBin0, 
        {RoleId,_Args1}
        end,
    {RoleList, _Bin1} = pt:read_array(FunArray0, Bin0),

    {ok, [RoleList]};
read(14023, _) ->
    {ok, []};
read(14024, Bin0) ->
    <<Id:64, _Bin1/binary>> = Bin0, 
    {ok, [Id]};
read(_Cmd, _R) -> {error, no_match}.

write (14000,[
    Type,
    RelaList
] = Src_Data) ->
    BinList_RelaList = [
        item_to_bin_0(RelaList_Item) || RelaList_Item <- RelaList
    ], 

    RelaList_Len = length(RelaList), 
    Bin_RelaList = list_to_binary(BinList_RelaList),

    Data = <<
        Type:8,
        RelaList_Len:16, Bin_RelaList/binary
    >>,
    {ok, pt:encode(14000, Data, Src_Data)};

write (14001,[
    Code,
    RecommendedList
] = Src_Data) ->
    BinList_RecommendedList = [
        item_to_bin_1(RecommendedList_Item) || RecommendedList_Item <- RecommendedList
    ], 

    RecommendedList_Len = length(RecommendedList), 
    Bin_RecommendedList = list_to_binary(BinList_RecommendedList),

    Data = <<
        Code:32,
        RecommendedList_Len:16, Bin_RecommendedList/binary
    >>,
    {ok, pt:encode(14001, Data, Src_Data)};

write (14002,[
    Code,
    RoleId,
    RoleName,
    Career,
    Sex,
    Turn,
    Lv,
    SupVipType,
    Vip,
    Picture,
    PictureVer,
    ProfilePhotoId,
    DressBoard,
    OnlineFlag,
    Power
] = Src_Data) ->
    Bin_RoleName = pt:write_string(RoleName), 

    Bin_Picture = pt:write_string(Picture), 

    Data = <<
        Code:32,
        RoleId:64,
        Bin_RoleName/binary,
        Career:8,
        Sex:8,
        Turn:8,
        Lv:16,
        SupVipType:8,
        Vip:8,
        Bin_Picture/binary,
        PictureVer:32,
        ProfilePhotoId:32,
        DressBoard:32,
        OnlineFlag:8,
        Power:64
    >>,
    {ok, pt:encode(14002, Data, Src_Data)};

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

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

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

write (14006,[
    AskList
] = Src_Data) ->
    BinList_AskList = [
        item_to_bin_2(AskList_Item) || AskList_Item <- AskList
    ], 

    AskList_Len = length(AskList), 
    Bin_AskList = list_to_binary(BinList_AskList),

    Data = <<
        AskList_Len:16, Bin_AskList/binary
    >>,
    {ok, pt:encode(14006, Data, Src_Data)};

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

write (14008,[
    RoleId,
    RoleName,
    Lv,
    AddTime
] = Src_Data) ->
    Bin_RoleName = pt:write_string(RoleName), 

    Data = <<
        RoleId:64,
        Bin_RoleName/binary,
        Lv:16,
        AddTime:32
    >>,
    {ok, pt:encode(14008, Data, Src_Data)};

write (14009,[
    RoleId,
    RoleName,
    RelaType,
    OnlineFlag
] = Src_Data) ->
    Bin_RoleName = pt:write_string(RoleName), 

    Data = <<
        RoleId:64,
        Bin_RoleName/binary,
        RelaType:8,
        OnlineFlag:8
    >>,
    {ok, pt:encode(14009, Data, Src_Data)};

write (14010,[
    Code,
    RoleId,
    Figure,
    Rela,
    Combat,
    WeekCharm,
    Intimacy,
    IsLocal,
    TeamId,
    ServerNum
] = Src_Data) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        Code:32,
        RoleId:64,
        Bin_Figure/binary,
        Rela:8,
        Combat:32,
        WeekCharm:32,
        Intimacy:32,
        IsLocal:8,
        TeamId:64,
        ServerNum:32
    >>,
    {ok, pt:encode(14010, Data, Src_Data)};

write (14011,[
    RoleId,
    Rela
] = Src_Data) ->
    Data = <<
        RoleId:64,
        Rela:8
    >>,
    {ok, pt:encode(14011, Data, Src_Data)};

write (14013,[
    UpdateList
] = Src_Data) ->
    BinList_UpdateList = [
        item_to_bin_3(UpdateList_Item) || UpdateList_Item <- UpdateList
    ], 

    UpdateList_Len = length(UpdateList), 
    Bin_UpdateList = list_to_binary(BinList_UpdateList),

    Data = <<
        UpdateList_Len:16, Bin_UpdateList/binary
    >>,
    {ok, pt:encode(14013, Data, Src_Data)};

write (14014,[
    UpdateList
] = Src_Data) ->
    BinList_UpdateList = [
        item_to_bin_5(UpdateList_Item) || UpdateList_Item <- UpdateList
    ], 

    UpdateList_Len = length(UpdateList), 
    Bin_UpdateList = list_to_binary(BinList_UpdateList),

    Data = <<
        UpdateList_Len:16, Bin_UpdateList/binary
    >>,
    {ok, pt:encode(14014, Data, Src_Data)};

write (14015,[
    SendList
] = Src_Data) ->
    BinList_SendList = [
        item_to_bin_7(SendList_Item) || SendList_Item <- SendList
    ], 

    SendList_Len = length(SendList), 
    Bin_SendList = list_to_binary(BinList_SendList),

    Data = <<
        SendList_Len:16, Bin_SendList/binary
    >>,
    {ok, pt:encode(14015, Data, Src_Data)};

write (14016,[
    SendCount,
    GiftCount,
    SendInfo,
    GiftInfo
] = Src_Data) ->
    BinList_SendInfo = [
        item_to_bin_8(SendInfo_Item) || SendInfo_Item <- SendInfo
    ], 

    SendInfo_Len = length(SendInfo), 
    Bin_SendInfo = list_to_binary(BinList_SendInfo),

    BinList_GiftInfo = [
        item_to_bin_9(GiftInfo_Item) || GiftInfo_Item <- GiftInfo
    ], 

    GiftInfo_Len = length(GiftInfo), 
    Bin_GiftInfo = list_to_binary(BinList_GiftInfo),

    Data = <<
        SendCount:16,
        GiftCount:16,
        SendInfo_Len:16, Bin_SendInfo/binary,
        GiftInfo_Len:16, Bin_GiftInfo/binary
    >>,
    {ok, pt:encode(14016, Data, Src_Data)};

write (14017,[
    Errcode,
    Torole,
    Type
] = Src_Data) ->
    Data = <<
        Errcode:32,
        Torole:64,
        Type:8
    >>,
    {ok, pt:encode(14017, Data, Src_Data)};

write (14018,[
    Errcode,
    Fromid,
    Type
] = Src_Data) ->
    Data = <<
        Errcode:32,
        Fromid:64,
        Type:8
    >>,
    {ok, pt:encode(14018, Data, Src_Data)};

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



write (14021,[
    Type,
    OppRelaList
] = Src_Data) ->
    BinList_OppRelaList = [
        item_to_bin_10(OppRelaList_Item) || OppRelaList_Item <- OppRelaList
    ], 

    OppRelaList_Len = length(OppRelaList), 
    Bin_OppRelaList = list_to_binary(BinList_OppRelaList),

    Data = <<
        Type:8,
        OppRelaList_Len:16, Bin_OppRelaList/binary
    >>,
    {ok, pt:encode(14021, Data, Src_Data)};

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

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

write (14024,[
    Errcode,
    Show
] = Src_Data) ->
    Bin_Show = pt:write_figure(Show), 

    Data = <<
        Errcode:32,
        Bin_Show/binary
    >>,
    {ok, pt:encode(14024, Data, Src_Data)};

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


item_to_bin_0 ({
    RoleId,
    RoleName,
    Career,
    Sex,
    Turn,
    Lv,
    SupVipType,
    Vip,
    Picture,
    PictureVer,
    ProfilePhotoId,
    DressBoard,
    OnlineFlag,
    Intimacy,
    MarriageType,
    LastChatTime,
    AddTime,
    GuildName,
    LastLogoutTime
}) ->
    Bin_RoleName = pt:write_string(RoleName), 

    Bin_Picture = pt:write_string(Picture), 

    Bin_GuildName = pt:write_string(GuildName), 

    Data = <<
        RoleId:64,
        Bin_RoleName/binary,
        Career:8,
        Sex:8,
        Turn:8,
        Lv:16,
        SupVipType:8,
        Vip:8,
        Bin_Picture/binary,
        PictureVer:32,
        ProfilePhotoId:32,
        DressBoard:32,
        OnlineFlag:8,
        Intimacy:32,
        MarriageType:8,
        LastChatTime:32,
        AddTime:32,
        Bin_GuildName/binary,
        LastLogoutTime:32
    >>,
    Data.
item_to_bin_1 ({
    RoleId,
    RoleName,
    Career,
    Sex,
    Turn,
    Lv,
    SupVipType,
    Vip,
    Picture,
    PictureVer,
    ProfilePhotoId,
    DressBoard,
    OnlineFlag,
    Power
}) ->
    Bin_RoleName = pt:write_string(RoleName), 

    Bin_Picture = pt:write_string(Picture), 

    Data = <<
        RoleId:64,
        Bin_RoleName/binary,
        Career:8,
        Sex:8,
        Turn:8,
        Lv:16,
        SupVipType:8,
        Vip:8,
        Bin_Picture/binary,
        PictureVer:32,
        ProfilePhotoId:32,
        DressBoard:32,
        OnlineFlag:8,
        Power:64
    >>,
    Data.
item_to_bin_2 ({
    RoleId,
    RoleName,
    Turn,
    Career,
    Sex,
    Picture,
    PictureVer,
    ProfilePhotoId,
    DressBoard,
    Lv,
    AddTime,
    Power,
    VipFlag,
    SupVipType
}) ->
    Bin_RoleName = pt:write_string(RoleName), 

    Bin_Picture = pt:write_string(Picture), 

    Data = <<
        RoleId:64,
        Bin_RoleName/binary,
        Turn:8,
        Career:8,
        Sex:8,
        Bin_Picture/binary,
        PictureVer:32,
        ProfilePhotoId:32,
        DressBoard:32,
        Lv:16,
        AddTime:32,
        Power:64,
        VipFlag:8,
        SupVipType:8
    >>,
    Data.
item_to_bin_3 ({
    Type,
    RoleList
}) ->
    BinList_RoleList = [
        item_to_bin_4(RoleList_Item) || RoleList_Item <- RoleList
    ], 

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

    Data = <<
        Type:8,
        RoleList_Len:16, Bin_RoleList/binary
    >>,
    Data.
item_to_bin_4 ({
    RoleId,
    RoleName,
    Career,
    Sex,
    Turn,
    Lv,
    SupVipType,
    Vip,
    Picture,
    PictureVer,
    ProfilePhotoId,
    DressBoard,
    OnlineFlag,
    Intimacy,
    MarriageType,
    LastChatTime,
    AddTime,
    GuildName,
    LastLogoutTime
}) ->
    Bin_RoleName = pt:write_string(RoleName), 

    Bin_Picture = pt:write_string(Picture), 

    Bin_GuildName = pt:write_string(GuildName), 

    Data = <<
        RoleId:64,
        Bin_RoleName/binary,
        Career:8,
        Sex:8,
        Turn:8,
        Lv:16,
        SupVipType:8,
        Vip:8,
        Bin_Picture/binary,
        PictureVer:32,
        ProfilePhotoId:32,
        DressBoard:32,
        OnlineFlag:8,
        Intimacy:32,
        MarriageType:8,
        LastChatTime:32,
        AddTime:32,
        Bin_GuildName/binary,
        LastLogoutTime:32
    >>,
    Data.
item_to_bin_5 ({
    Type,
    RoleIds
}) ->
    BinList_RoleIds = [
        item_to_bin_6(RoleIds_Item) || RoleIds_Item <- RoleIds
    ], 

    RoleIds_Len = length(RoleIds), 
    Bin_RoleIds = list_to_binary(BinList_RoleIds),

    Data = <<
        Type:8,
        RoleIds_Len:16, Bin_RoleIds/binary
    >>,
    Data.
item_to_bin_6 (
    RoleId
) ->
    Data = <<
        RoleId:64
    >>,
    Data.
item_to_bin_7 ({
    RoleId,
    Code
}) ->
    Data = <<
        RoleId:64,
        Code:32
    >>,
    Data.
item_to_bin_8 ({
    RoleId0,
    Type
}) ->
    Data = <<
        RoleId0:64,
        Type:8
    >>,
    Data.
item_to_bin_9 ({
    RoleId1,
    Type,
    Val
}) ->
    Data = <<
        RoleId1:64,
        Type:8,
        Val:8
    >>,
    Data.
item_to_bin_10 ({
    RoleId,
    OppRelaType,
    AskResponseStatus
}) ->
    Data = <<
        RoleId:64,
        OppRelaType:8,
        AskResponseStatus:8
    >>,
    Data.
