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

read(11001, Bin0) ->
    <<Channel:8, Bin1/binary>> = Bin0, 
    <<ReceiveId:64, Bin2/binary>> = Bin1, 
    {Msg, Bin3} = pt:read_string(Bin2), 
    {Args, Bin4} = pt:read_string(Bin3), 
    <<TkTime:32, Bin5/binary>> = Bin4, 
    {Ticket, Bin6} = pt:read_string(Bin5), 
    <<IsSystemMsg:8, _Bin7/binary>> = Bin6, 
    {ok, [Channel, ReceiveId, Msg, Args, TkTime, Ticket, IsSystemMsg]};
read(11003, Bin0) ->
    <<Channel:8, Bin1/binary>> = Bin0, 
    <<ReceiveId:64, Bin2/binary>> = Bin1, 
    <<VoiceMsgTime:32, Bin3/binary>> = Bin2, 
    <<TkTime:32, Bin4/binary>> = Bin3, 
    {Ticket, Bin5} = pt:read_string(Bin4), 
    {DataSend, Bin6} = pt:read_voice_bin(Bin5), 
    {VoiceText, Bin7} = pt:read_string_binary(Bin6), 
    <<AutoId:64, Bin8/binary>> = Bin7, 
    <<IsEnd:8, _Bin9/binary>> = Bin8, 
    {ok, [Channel, ReceiveId, VoiceMsgTime, TkTime, Ticket, DataSend, VoiceText, AutoId, IsEnd]};
read(11004, Bin0) ->
    <<AutoId:64, Bin1/binary>> = Bin0, 
    <<PlayerId:64, Bin2/binary>> = Bin1, 
    <<TkTime:32, Bin3/binary>> = Bin2, 
    {Ticket, _Bin4} = pt:read_string(Bin3), 
    {ok, [AutoId, PlayerId, TkTime, Ticket]};
read(11005, Bin0) ->
    <<Channel:8, Bin1/binary>> = Bin0, 
    <<ReceiveId:64, Bin2/binary>> = Bin1, 
    <<AutoId:64, Bin3/binary>> = Bin2, 
    {VoiceText, _Bin4} = pt:read_string_binary(Bin3), 
    {ok, [Channel, ReceiveId, AutoId, VoiceText]};
read(11006, Bin0) ->
    <<AutoId:64, Bin1/binary>> = Bin0, 
    <<PlayerId:64, _Bin2/binary>> = Bin1, 
    {ok, [AutoId, PlayerId]};
read(11007, Bin0) ->
    <<Channel:8, Bin1/binary>> = Bin0, 
    <<PreceiveId:64, Bin2/binary>> = Bin1, 
    <<IsEnd:8, Bin3/binary>> = Bin2, 
    <<TkTime:32, Bin4/binary>> = Bin3, 
    {Ticket, Bin5} = pt:read_string(Bin4), 
    {TinyPicture, Bin6} = pt:read_string(Bin5), 
    {RealPicture, _Bin7} = pt:read_string(Bin6), 
    {ok, [Channel, PreceiveId, IsEnd, TkTime, Ticket, TinyPicture, RealPicture]};
read(11008, Bin0) ->
    <<AutoId:64, Bin1/binary>> = Bin0, 
    <<TkTime:32, Bin2/binary>> = Bin1, 
    {Ticket, _Bin3} = pt:read_string(Bin2), 
    {ok, [AutoId, TkTime, Ticket]};
read(11010, Bin0) ->
    <<Channel:8, _Bin1/binary>> = Bin0, 
    {ok, [Channel]};
read(11011, Bin0) ->
    <<Channel:8, _Bin1/binary>> = Bin0, 
    {ok, [Channel]};
read(11016, Bin0) ->
    <<ModuleId:16, Bin1/binary>> = Bin0, 
    <<Type:16, _Bin2/binary>> = Bin1, 
    {ok, [ModuleId, Type]};
read(11022, Bin0) ->
    <<BossType:8, Bin1/binary>> = Bin0, 
    <<KillId:64, Bin2/binary>> = Bin1, 
    {KillName, _Bin3} = pt:read_string(Bin2), 
    {ok, [BossType, KillId, KillName]};
read(11040, Bin0) ->
    <<Uid:64, Bin1/binary>> = Bin0, 
    <<LimitTime:8, _Bin2/binary>> = Bin1, 
    {ok, [Uid, LimitTime]};
read(11041, Bin0) ->
    <<Uid:64, _Bin1/binary>> = Bin0, 
    {ok, [Uid]};
read(11043, Bin0) ->
    <<Uid:64, _Bin1/binary>> = Bin0, 
    {ok, [Uid]};
read(11044, Bin0) ->
    <<TargetId:64, _Bin1/binary>> = Bin0, 
    {ok, [TargetId]};
read(11045, Bin0) ->
    <<TargetId:64, Bin1/binary>> = Bin0, 
    {TargetData, _Bin2} = pt:read_string(Bin1), 
    {ok, [TargetId, TargetData]};
read(11050, _) ->
    {ok, []};
read(11065, _) ->
    {ok, []};
read(11066, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<RoleId:64, _Bin2/binary>> = Bin1, 
    {ok, [Type, RoleId]};
read(_Cmd, _R) -> {error, no_match}.

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

write (11001,[
    Channel,
    SerId,
    SerNum,
    SerName,
    PlayerId,
    Figure,
    Msg,
    Args,
    Result,
    Time,
    LvRank,
    CombatRank
] = Src_Data) ->
    Bin_SerName = pt:write_string(SerName), 

    Bin_Figure = pt:write_figure(Figure), 

    Bin_Msg = pt:write_string(Msg), 

    Bin_Args = pt:write_string(Args), 

    Data = <<
        Channel:8,
        SerId:16,
        SerNum:16,
        Bin_SerName/binary,
        PlayerId:64,
        Bin_Figure/binary,
        Bin_Msg/binary,
        Bin_Args/binary,
        Result:8,
        Time:32,
        LvRank:8,
        CombatRank:8
    >>,
    {ok, pt:encode(11001, Data, Src_Data)};

write (11002,[
    Channel,
    SerId,
    SerNum,
    SerName,
    PlayerList,
    Msg,
    Args,
    Result,
    Time
] = Src_Data) ->
    Bin_SerName = pt:write_string(SerName), 

    BinList_PlayerList = [
        item_to_bin_0(PlayerList_Item) || PlayerList_Item <- PlayerList
    ], 

    PlayerList_Len = length(PlayerList), 
    Bin_PlayerList = list_to_binary(BinList_PlayerList),

    Bin_Msg = pt:write_string(Msg), 

    Bin_Args = pt:write_string(Args), 

    Data = <<
        Channel:8,
        SerId:16,
        SerNum:16,
        Bin_SerName/binary,
        PlayerList_Len:16, Bin_PlayerList/binary,
        Bin_Msg/binary,
        Bin_Args/binary,
        Result:8,
        Time:32
    >>,
    {ok, pt:encode(11002, Data, Src_Data)};

write (11003,[
    Channel,
    SerId,
    SerNum,
    SerName,
    PlayerList,
    ClientVer,
    AutoId,
    ReceiveId,
    VoiceText,
    VoiceMsgTime,
    Time,
    LvRank,
    CombatRank
] = Src_Data) ->
    Bin_SerName = pt:write_string(SerName), 

    BinList_PlayerList = [
        item_to_bin_1(PlayerList_Item) || PlayerList_Item <- PlayerList
    ], 

    PlayerList_Len = length(PlayerList), 
    Bin_PlayerList = list_to_binary(BinList_PlayerList),

    Bin_VoiceText = pt:write_string(VoiceText), 

    Data = <<
        Channel:8,
        SerId:16,
        SerNum:16,
        Bin_SerName/binary,
        PlayerList_Len:16, Bin_PlayerList/binary,
        ClientVer:64,
        AutoId:64,
        ReceiveId:64,
        Bin_VoiceText/binary,
        VoiceMsgTime:16,
        Time:32,
        LvRank:8,
        CombatRank:8
    >>,
    {ok, pt:encode(11003, Data, Src_Data)};

write (11004,[
    ErrorCode,
    AutoId,
    DataSend
] = Src_Data) ->
    Bin_DataSend = pt:write_voice_bin(DataSend), 

    Data = <<
        ErrorCode:32,
        AutoId:64,
        Bin_DataSend/binary
    >>,
    {ok, pt:encode(11004, Data, Src_Data)};

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

write (11006,[
    ErrorCode,
    AutoId,
    VoiceText
] = Src_Data) ->
    Bin_VoiceText = pt:write_string(VoiceText), 

    Data = <<
        ErrorCode:8,
        AutoId:64,
        Bin_VoiceText/binary
    >>,
    {ok, pt:encode(11006, Data, Src_Data)};

write (11007,[
    Channel,
    PlayerId,
    Figure,
    AutoId,
    ReceiveId,
    TinyPicture
] = Src_Data) ->
    Bin_Figure = pt:write_figure(Figure), 

    Bin_TinyPicture = pt:write_string(TinyPicture), 

    Data = <<
        Channel:8,
        PlayerId:64,
        Bin_Figure/binary,
        AutoId:64,
        ReceiveId:64,
        Bin_TinyPicture/binary
    >>,
    {ok, pt:encode(11007, Data, Src_Data)};

write (11008,[
    AutoId,
    Picture
] = Src_Data) ->
    Bin_Picture = pt:write_string(Picture), 

    Data = <<
        AutoId:64,
        Bin_Picture/binary
    >>,
    {ok, pt:encode(11008, Data, Src_Data)};

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

write (11010,[
    CacheList
] = Src_Data) ->
    BinList_CacheList = [
        item_to_bin_2(CacheList_Item) || CacheList_Item <- CacheList
    ], 

    CacheList_Len = length(CacheList), 
    Bin_CacheList = list_to_binary(BinList_CacheList),

    Data = <<
        CacheList_Len:16, Bin_CacheList/binary
    >>,
    {ok, pt:encode(11010, Data, Src_Data)};

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

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

write (11013,[
    Channel,
    AutoId,
    VoiceText
] = Src_Data) ->
    Bin_VoiceText = pt:write_string(VoiceText), 

    Data = <<
        Channel:8,
        AutoId:64,
        Bin_VoiceText/binary
    >>,
    {ok, pt:encode(11013, Data, Src_Data)};

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

write (11015,[
    ModuleId,
    Id,
    Content,
    Tip
] = Src_Data) ->
    Bin_Content = pt:write_string(Content), 

    Data = <<
        ModuleId:16,
        Id:16,
        Bin_Content/binary,
        Tip:8
    >>,
    {ok, pt:encode(11015, Data, Src_Data)};

write (11016,[
    ModuleId,
    Type,
    Num
] = Src_Data) ->
    Data = <<
        ModuleId:16,
        Type:16,
        Num:16
    >>,
    {ok, pt:encode(11016, Data, Src_Data)};

write (11017,[
    Type,
    ErrorCode,
    ErrorCodeArgs
] = Src_Data) ->
    Bin_ErrorCodeArgs = pt:write_string(ErrorCodeArgs), 

    Data = <<
        Type:8,
        ErrorCode:32,
        Bin_ErrorCodeArgs/binary
    >>,
    {ok, pt:encode(11017, Data, Src_Data)};

write (11018,[
    SerId,
    PlayerId,
    Figure,
    ModuleId,
    Id,
    Content,
    Tip
] = Src_Data) ->
    Bin_Figure = pt:write_figure(Figure), 

    Bin_Content = pt:write_string(Content), 

    Data = <<
        SerId:16,
        PlayerId:64,
        Bin_Figure/binary,
        ModuleId:16,
        Id:16,
        Bin_Content/binary,
        Tip:8
    >>,
    {ok, pt:encode(11018, Data, Src_Data)};

write (11019,[
    ModuleId,
    Id,
    ContentList
] = Src_Data) ->
    BinList_ContentList = [
        item_to_bin_4(ContentList_Item) || ContentList_Item <- ContentList
    ], 

    ContentList_Len = length(ContentList), 
    Bin_ContentList = list_to_binary(BinList_ContentList),

    Data = <<
        ModuleId:16,
        Id:16,
        ContentList_Len:16, Bin_ContentList/binary
    >>,
    {ok, pt:encode(11019, Data, Src_Data)};

write (11020,[
    Content
] = Src_Data) ->
    Bin_Content = pt:write_string(Content), 

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

write (11021,[
    Channel,
    Gm,
    Time,
    Msg
] = Src_Data) ->
    Bin_Msg = pt:write_string(Msg), 

    Data = <<
        Channel:8,
        Gm:8,
        Time:16,
        Bin_Msg/binary
    >>,
    {ok, pt:encode(11021, Data, Src_Data)};



write (11023,[
    CacheList
] = Src_Data) ->
    BinList_CacheList = [
        item_to_bin_5(CacheList_Item) || CacheList_Item <- CacheList
    ], 

    CacheList_Len = length(CacheList), 
    Bin_CacheList = list_to_binary(BinList_CacheList),

    Data = <<
        CacheList_Len:16, Bin_CacheList/binary
    >>,
    {ok, pt:encode(11023, Data, Src_Data)};

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

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

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

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

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

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

write (11046,[
    List
] = Src_Data) ->
    BinList_List = [
        item_to_bin_6(List_Item) || List_Item <- List
    ], 

    List_Len = length(List), 
    Bin_List = list_to_binary(BinList_List),

    Data = <<
        List_Len:16, Bin_List/binary
    >>,
    {ok, pt:encode(11046, Data, Src_Data)};

write (11050,[
    NoticeList
] = Src_Data) ->
    BinList_NoticeList = [
        item_to_bin_7(NoticeList_Item) || NoticeList_Item <- NoticeList
    ], 

    NoticeList_Len = length(NoticeList), 
    Bin_NoticeList = list_to_binary(BinList_NoticeList),

    Data = <<
        NoticeList_Len:16, Bin_NoticeList/binary
    >>,
    {ok, pt:encode(11050, Data, Src_Data)};

write (11060,[
    Type,
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_8(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

    GoodsList_Len = length(GoodsList), 
    Bin_GoodsList = list_to_binary(BinList_GoodsList),

    Data = <<
        Type:8,
        GoodsList_Len:16, Bin_GoodsList/binary
    >>,
    {ok, pt:encode(11060, Data, Src_Data)};

write (11061,[
    ObjectList
] = Src_Data) ->
    Bin_ObjectList = pt:write_object_list(ObjectList), 

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

write (11062,[
    LanguageId,
    ArgsList
] = Src_Data) ->
    BinList_ArgsList = [
        item_to_bin_9(ArgsList_Item) || ArgsList_Item <- ArgsList
    ], 

    ArgsList_Len = length(ArgsList), 
    Bin_ArgsList = list_to_binary(BinList_ArgsList),

    Data = <<
        LanguageId:32,
        ArgsList_Len:16, Bin_ArgsList/binary
    >>,
    {ok, pt:encode(11062, Data, Src_Data)};

write (11063,[
    Effect
] = Src_Data) ->
    Bin_Effect = pt:write_string(Effect), 

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

write (11064,[
    ModuleId,
    Id,
    Name
] = Src_Data) ->
    Bin_Name = pt:write_string(Name), 

    Data = <<
        ModuleId:32,
        Id:16,
        Bin_Name/binary
    >>,
    {ok, pt:encode(11064, Data, Src_Data)};

write (11065,[
    FigureList
] = Src_Data) ->
    BinList_FigureList = [
        item_to_bin_10(FigureList_Item) || FigureList_Item <- FigureList
    ], 

    FigureList_Len = length(FigureList), 
    Bin_FigureList = list_to_binary(BinList_FigureList),

    Data = <<
        FigureList_Len:16, Bin_FigureList/binary
    >>,
    {ok, pt:encode(11065, Data, Src_Data)};

write (11066,[
    Errcode,
    Type,
    Figure,
    ServerNum
] = Src_Data) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        Errcode:32,
        Type:8,
        Bin_Figure/binary,
        ServerNum:16
    >>,
    {ok, pt:encode(11066, Data, Src_Data)};

write (11067,[
    ModuleId,
    Id
] = Src_Data) ->
    Data = <<
        ModuleId:32,
        Id:16
    >>,
    {ok, pt:encode(11067, Data, Src_Data)};

write (11091,[
    Type,
    Msg
] = Src_Data) ->
    Bin_Msg = pt:write_string(Msg), 

    Data = <<
        Type:8,
        Bin_Msg/binary
    >>,
    {ok, pt:encode(11091, Data, Src_Data)};

write (11099,[
    Errcode,
    Args
] = Src_Data) ->
    Bin_Args = pt:write_string(Args), 

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

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


item_to_bin_0 ({
    PlayerId,
    Figure
}) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        PlayerId:64,
        Bin_Figure/binary
    >>,
    Data.
item_to_bin_1 ({
    PlayerId,
    Figure
}) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        PlayerId:64,
        Bin_Figure/binary
    >>,
    Data.
item_to_bin_2 ({
    Channel,
    PlayerList,
    Msg,
    Args,
    Result,
    Time,
    ClientVer,
    AutoId,
    VoiceMsgTime
}) ->
    BinList_PlayerList = [
        item_to_bin_3(PlayerList_Item) || PlayerList_Item <- PlayerList
    ], 

    PlayerList_Len = length(PlayerList), 
    Bin_PlayerList = list_to_binary(BinList_PlayerList),

    Bin_Msg = pt:write_string(Msg), 

    Bin_Args = pt:write_string(Args), 

    Data = <<
        Channel:8,
        PlayerList_Len:16, Bin_PlayerList/binary,
        Bin_Msg/binary,
        Bin_Args/binary,
        Result:8,
        Time:32,
        ClientVer:64,
        AutoId:64,
        VoiceMsgTime:32
    >>,
    Data.
item_to_bin_3 ({
    SerId,
    SerNum,
    SerName,
    PlayerId,
    Figure
}) ->
    Bin_SerName = pt:write_string(SerName), 

    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        SerId:16,
        SerNum:16,
        Bin_SerName/binary,
        PlayerId:64,
        Bin_Figure/binary
    >>,
    Data.
item_to_bin_4 (
    Content
) ->
    Bin_Content = pt:write_string(Content), 

    Data = <<
        Bin_Content/binary
    >>,
    Data.
item_to_bin_5 ({
    Name,
    Sex,
    Vip,
    Picture,
    Msg,
    Time,
    Lv
}) ->
    Bin_Name = pt:write_string(Name), 

    Bin_Msg = pt:write_string(Msg), 

    Data = <<
        Bin_Name/binary,
        Sex:8,
        Vip:8,
        Picture:32,
        Bin_Msg/binary,
        Time:32,
        Lv:16
    >>,
    Data.
item_to_bin_6 (
    RoleId
) ->
    Data = <<
        RoleId:64
    >>,
    Data.
item_to_bin_7 ({
    Id,
    Source,
    Type,
    Color,
    Content,
    Url,
    SendCount,
    SendGap,
    StartTime,
    EndTime,
    State
}) ->
    Bin_Source = pt:write_string(Source), 

    Bin_Color = pt:write_string(Color), 

    Bin_Content = pt:write_string(Content), 

    Bin_Url = pt:write_string(Url), 

    Data = <<
        Id:32,
        Bin_Source/binary,
        Type:8,
        Bin_Color/binary,
        Bin_Content/binary,
        Bin_Url/binary,
        SendCount:32,
        SendGap:16,
        StartTime:32,
        EndTime:32,
        State:8
    >>,
    Data.
item_to_bin_8 ({
    GoodsTypeId,
    Num
}) ->
    Data = <<
        GoodsTypeId:32,
        Num:32
    >>,
    Data.
item_to_bin_9 (
    Args
) ->
    Bin_Args = pt:write_string(Args), 

    Data = <<
        Bin_Args/binary
    >>,
    Data.
item_to_bin_10 ({
    Figure,
    ServerNum
}) ->
    Bin_Figure = pt:write_figure(Figure), 

    Data = <<
        Bin_Figure/binary,
        ServerNum:16
    >>,
    Data.
