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

read(15501, Bin0) ->
    <<SellType:8, Bin1/binary>> = Bin0, 
    <<Type:8, Bin2/binary>> = Bin1, 
    <<Subtype:8, Bin3/binary>> = Bin2, 
    <<Series:16, Bin4/binary>> = Bin3, 
    <<Color:8, Bin5/binary>> = Bin4, 
    <<Career:8, Bin6/binary>> = Bin5, 
    <<PageSize:16, Bin7/binary>> = Bin6, 
    <<PageNumber:16, Bin8/binary>> = Bin7, 
    <<SortId:8, Bin9/binary>> = Bin8, 
    <<SortOrder:8, _Bin10/binary>> = Bin9, 
    {ok, [SellType, Type, Subtype, Series, Color, Career, PageSize, PageNumber, SortId, SortOrder]};
read(15502, _) ->
    {ok, []};
read(15503, _) ->
    {ok, []};
read(15504, Bin0) ->
    <<Type:16, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(15505, _) ->
    {ok, []};
read(15506, Bin0) ->
    <<GoodsId:64, Bin1/binary>> = Bin0, 
    <<TypeId:32, Bin2/binary>> = Bin1, 
    <<GoodsNum:32, Bin3/binary>> = Bin2, 
    <<SellType:8, Bin4/binary>> = Bin3, 
    <<IsToWorld:8, _Bin5/binary>> = Bin4, 
    {ok, [GoodsId, TypeId, GoodsNum, SellType, IsToWorld]};
read(15507, Bin0) ->
    <<Id:64, Bin1/binary>> = Bin0, 
    <<Price:32, _Bin2/binary>> = Bin1, 
    {ok, [Id, Price]};
read(15508, Bin0) ->
    <<Id:64, _Bin1/binary>> = Bin0, 
    {ok, [Id]};
read(15509, Bin0) ->
    <<Id:64, Bin1/binary>> = Bin0, 
    <<SellType:8, Bin2/binary>> = Bin1, 
    <<IsToWorld:8, _Bin3/binary>> = Bin2, 
    {ok, [Id, SellType, IsToWorld]};
read(15510, Bin0) ->
    <<Id:64, _Bin1/binary>> = Bin0, 
    {ok, [Id]};
read(15511, Bin0) ->
    <<Id:64, _Bin1/binary>> = Bin0, 
    {ok, [Id]};
read(15512, _) ->
    {ok, []};
read(15513, Bin0) ->
    <<TypeId:32, _Bin1/binary>> = Bin0, 
    {ok, [TypeId]};
read(15514, Bin0) ->
    <<TypeId:32, _Bin1/binary>> = Bin0, 
    {ok, [TypeId]};
read(15516, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<Subtype:8, _Bin2/binary>> = Bin1, 
    {ok, [Type, Subtype]};
read(15519, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

write (15501,[
    SellType,
    Type,
    Subtype,
    Career,
    PageTotal,
    PageNo,
    SortId,
    SortOrder,
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_0(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

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

    Data = <<
        SellType:8,
        Type:8,
        Subtype:8,
        Career:8,
        PageTotal:16,
        PageNo:16,
        SortId:8,
        SortOrder:8,
        GoodsList_Len:16, Bin_GoodsList/binary
    >>,
    {ok, pt:encode(15501, Data, Src_Data)};

write (15502,[
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_2(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

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

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

write (15503,[
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_4(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

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

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

write (15504,[
    Type,
    LogList
] = Src_Data) ->
    BinList_LogList = [
        item_to_bin_6(LogList_Item) || LogList_Item <- LogList
    ], 

    LogList_Len = length(LogList), 
    Bin_LogList = list_to_binary(BinList_LogList),

    Data = <<
        Type:16,
        LogList_Len:16, Bin_LogList/binary
    >>,
    {ok, pt:encode(15504, Data, Src_Data)};

write (15505,[
    GoodList
] = Src_Data) ->
    BinList_GoodList = [
        item_to_bin_8(GoodList_Item) || GoodList_Item <- GoodList
    ], 

    GoodList_Len = length(GoodList), 
    Bin_GoodList = list_to_binary(BinList_GoodList),

    Data = <<
        GoodList_Len:16, Bin_GoodList/binary
    >>,
    {ok, pt:encode(15505, Data, Src_Data)};

write (15506,[
    GoodsId,
    ResultCode
] = Src_Data) ->
    Data = <<
        GoodsId:64,
        ResultCode:64
    >>,
    {ok, pt:encode(15506, Data, Src_Data)};

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

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

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

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

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

write (15512,[
    GoodsList
] = Src_Data) ->
    BinList_GoodsList = [
        item_to_bin_9(GoodsList_Item) || GoodsList_Item <- GoodsList
    ], 

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

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

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

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

write (15515,[
    TypeId,
    SellType
] = Src_Data) ->
    Data = <<
        TypeId:32,
        SellType:8
    >>,
    {ok, pt:encode(15515, Data, Src_Data)};

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

write (15517,[
    GoodsId,
    OtherData
] = Src_Data) ->
    BinList_OtherData = [
        item_to_bin_11(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        GoodsId:32,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    {ok, pt:encode(15517, Data, Src_Data)};

write (15518,[
    Id,
    Price,
    IsDown
] = Src_Data) ->
    Data = <<
        Id:64,
        Price:32,
        IsDown:8
    >>,
    {ok, pt:encode(15518, Data, Src_Data)};

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

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


item_to_bin_0 ({
    Id,
    RoleId,
    TypeId,
    IsLike,
    UpTime,
    EndTime,
    Price,
    MyPrice,
    GetPrice,
    SellType,
    GoodsNum,
    AutionNum,
    MyBid,
    OtherData
}) ->
    BinList_OtherData = [
        item_to_bin_1(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        Id:64,
        RoleId:64,
        TypeId:32,
        IsLike:8,
        UpTime:32,
        EndTime:32,
        Price:32,
        MyPrice:32,
        GetPrice:32,
        SellType:8,
        GoodsNum:32,
        AutionNum:8,
        MyBid:8,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    Data.
item_to_bin_1 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_2 ({
    Id,
    RoleId,
    TypeId,
    IsLike,
    UpTime,
    EndTime,
    Price,
    MyPrice,
    GetPrice,
    SellType,
    GoodsNum,
    AutionNum,
    MyBid,
    OtherData
}) ->
    BinList_OtherData = [
        item_to_bin_3(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        Id:64,
        RoleId:64,
        TypeId:32,
        IsLike:8,
        UpTime:32,
        EndTime:32,
        Price:32,
        MyPrice:32,
        GetPrice:32,
        SellType:8,
        GoodsNum:32,
        AutionNum:8,
        MyBid:8,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    Data.
item_to_bin_3 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_4 ({
    Id,
    TypeId,
    UpTime,
    EndTime,
    Price,
    GetPrice,
    SellType,
    GoodsNum,
    AutionNum,
    OtherData
}) ->
    BinList_OtherData = [
        item_to_bin_5(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        Id:64,
        TypeId:32,
        UpTime:32,
        EndTime:32,
        Price:32,
        GetPrice:32,
        SellType:8,
        GoodsNum:32,
        AutionNum:8,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    Data.
item_to_bin_5 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_6 ({
    Id,
    TypeId,
    Time,
    Price,
    DealType,
    GoodsNum,
    BuyerName,
    OtherData
}) ->
    Bin_BuyerName = pt:write_string(BuyerName), 

    BinList_OtherData = [
        item_to_bin_7(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        Id:64,
        TypeId:32,
        Time:32,
        Price:32,
        DealType:8,
        GoodsNum:32,
        Bin_BuyerName/binary,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    Data.
item_to_bin_7 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_8 (
    TypeId
) ->
    Data = <<
        TypeId:32
    >>,
    Data.
item_to_bin_9 ({
    Id,
    RoleId,
    TypeId,
    IsLike,
    UpTime,
    EndTime,
    Price,
    MyPrice,
    GetPrice,
    SellType,
    GoodsNum,
    AutionNum,
    MyBid,
    OtherData
}) ->
    BinList_OtherData = [
        item_to_bin_10(OtherData_Item) || OtherData_Item <- OtherData
    ], 

    OtherData_Len = length(OtherData), 
    Bin_OtherData = list_to_binary(BinList_OtherData),

    Data = <<
        Id:64,
        RoleId:64,
        TypeId:32,
        IsLike:8,
        UpTime:32,
        EndTime:32,
        Price:32,
        MyPrice:32,
        GetPrice:32,
        SellType:8,
        GoodsNum:32,
        AutionNum:8,
        MyBid:8,
        OtherData_Len:16, Bin_OtherData/binary
    >>,
    Data.
item_to_bin_10 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
item_to_bin_11 ({
    Type,
    Info
}) ->
    Bin_Info = pt:write_string(Info), 

    Data = <<
        Type:8,
        Bin_Info/binary
    >>,
    Data.
