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

read(18000, Bin0) ->
    <<RoleId:64, Bin1/binary>> = Bin0,
    <<Id:16, _Bin2/binary>> = Bin1,
    {ok, [RoleId, Id]};
read(18002, Bin0) ->
    <<Type:8, _Bin1/binary>> = Bin0,
    {ok, [Type]};
read(18003, _) ->
    {ok, []};
read(_Cmd, _R) -> {error, no_match}.

write (18000,[
    Code
]) ->
    Data = <<
        Code:32
    >>,
    {ok, pt:pack(18000, Data)};

write (18001,[
    RoleId,
    Id
]) ->
    Data = <<
        RoleId:64,
        Id:16
    >>,
    {ok, pt:pack(18001, Data)};

write (18002,[
    Code
]) ->
    Data = <<
        Code:32
    >>,
    {ok, pt:pack(18002, Data)};



write (18004,[
    RoleId,
    OtherRoleId,
    Id,
    Mode
]) ->
    Data = <<
        RoleId:64,
        OtherRoleId:64,
        Id:16,
        Mode:8
    >>,
    {ok, pt:pack(18004, Data)};

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


