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

read(11400, _) ->
    {ok, []};
read(11401, Bin0) ->
    <<Type:8, Bin1/binary>> = Bin0, 
    <<TaskId:32, _Bin2/binary>> = Bin1, 
    {ok, [Type, TaskId]};
read(_Cmd, _R) -> {error, no_match}.

write (11400,[
    List
] = Src_Data) ->
    BinList_List = [
        item_to_bin_0(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(11400, Data, Src_Data)};

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

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


item_to_bin_0 ({
    Type,
    TaskId
}) ->
    Data = <<
        Type:8,
        TaskId:32
    >>,
    Data.
