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

read(18200, _) ->
    {ok, []};
read(18201, Bin0) ->
    <<FuncId:16, _Bin1/binary>> = Bin0, 
    {ok, [FuncId]};
read(_Cmd, _R) -> {error, no_match}.

write (18200,[
    FuncList
] = Src_Data) ->
    BinList_FuncList = [
        item_to_bin_0(FuncList_Item) || FuncList_Item <- FuncList
    ], 

    FuncList_Len = length(FuncList), 
    Bin_FuncList = list_to_binary(BinList_FuncList),

    Data = <<
        FuncList_Len:16, Bin_FuncList/binary
    >>,
    {ok, pt:encode(18200, Data, Src_Data)};

write (18201,[
    Errcode,
    FuncId,
    RewardState
] = Src_Data) ->
    Data = <<
        Errcode:32,
        FuncId:16,
        RewardState:8
    >>,
    {ok, pt:encode(18201, Data, Src_Data)};

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


item_to_bin_0 ({
    FuncId,
    RewardState
}) ->
    Data = <<
        FuncId:16,
        RewardState:8
    >>,
    Data.
