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

read(42500, _) ->
    {ok, []};
read(42501, Bin0) ->
    <<Id:32, _Bin1/binary>> = Bin0, 
    {ok, [Id]};
read(42502, Bin0) ->
    <<Id:32, _Bin1/binary>> = Bin0, 
    {ok, [Id]};
read(42503, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0, 
    {ok, [Type]};
read(42504, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

write (42500,[
    IsRand,
    DanceId,
    Dance
] = Src_Data) ->
    BinList_Dance = [
        item_to_bin_0(Dance_Item) || Dance_Item <- Dance
    ], 

    Dance_Len = length(Dance), 
    Bin_Dance = list_to_binary(BinList_Dance),

    Data = <<
        IsRand:8,
        DanceId:32,
        Dance_Len:16, Bin_Dance/binary
    >>,
    {ok, pt:encode(42500, Data, Src_Data)};

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

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

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



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


item_to_bin_0 (
    Id
) ->
    Data = <<
        Id:32
    >>,
    Data.
