fix
This commit is contained in:
parent
c6e7f7669e
commit
849fdb50a7
@ -23,21 +23,21 @@
|
||||
-define(TASK_STATUS_FAILED, 0). %% 离线
|
||||
-define(TASK_STATUS_OK, 1). %% 在线
|
||||
|
||||
%% 消息体类型
|
||||
%% efka主动发起的消息体类型
|
||||
-define(PACKET_REQUEST, 16#01).
|
||||
-define(PACKET_RESPONSE, 16#02).
|
||||
|
||||
%% 服务器端推送消息
|
||||
-define(PACKET_PUBLISH, 16#03).
|
||||
-define(PACKET_PUBLISH_RESPONSE, 16#04).
|
||||
|
||||
%% 消息体类型
|
||||
-define(PACKET_REQUEST, 16#01).
|
||||
-define(PACKET_RESPONSE, 16#02).
|
||||
%% 服务器基于pub/sub的消息
|
||||
-define(PACKET_PUB, 16#03).
|
||||
%% push调用不需要返回
|
||||
-define(PACKET_COMMAND, 16#04).
|
||||
|
||||
%% 服务器端推送消息
|
||||
-define(PACKET_PUBLISH, 16#03).
|
||||
-define(PACKET_PUBLISH_RESPONSE, 16#04).
|
||||
-define(PACKET_ASYNC_REQUEST, 16#5).
|
||||
-define(PACKET_ASYNC_RESPONSE, 16#6).
|
||||
|
||||
%% 授权
|
||||
-define(COMMAND_AUTH, 16#8).
|
||||
|
||||
%% 主机端上报数据类型标识
|
||||
%% 建立到websocket的register关系
|
||||
@ -50,12 +50,10 @@
|
||||
-define(METHOD_FEEDBACK_STEP, 16#05).
|
||||
|
||||
-define(METHOD_EVENT, 16#07).
|
||||
|
||||
-define(METHOD_PHASE, 16#09).
|
||||
|
||||
%% 部署微服务
|
||||
-define(METHOD_DEPLOY, 16#10).
|
||||
-define(METHOD_CONFIG, 16#11).
|
||||
|
||||
%% 事件类型
|
||||
-define(EVENT_DEVICE, 16#01).
|
||||
|
||||
@ -27,13 +27,6 @@
|
||||
}).
|
||||
-endif.
|
||||
|
||||
-ifndef('ACTIVATE_PUSH_PB_H').
|
||||
-define('ACTIVATE_PUSH_PB_H', true).
|
||||
-record(activate_push,
|
||||
{auth = false :: boolean() | 0 | 1 | undefined % = 1, optional
|
||||
}).
|
||||
-endif.
|
||||
|
||||
-ifndef('DEPLOY_PB_H').
|
||||
-define('DEPLOY_PB_H', true).
|
||||
-record(deploy,
|
||||
@ -52,14 +45,31 @@
|
||||
}).
|
||||
-endif.
|
||||
|
||||
-ifndef('TOPIC_MESSAGE_PB_H').
|
||||
-define('TOPIC_MESSAGE_PB_H', true).
|
||||
-record(topic_message,
|
||||
-ifndef('PUB_PB_H').
|
||||
-define('PUB_PB_H', true).
|
||||
-record(pub,
|
||||
{topic = <<>> :: unicode:chardata() | undefined, % = 1, optional
|
||||
content = <<>> :: unicode:chardata() | undefined % = 2, optional
|
||||
}).
|
||||
-endif.
|
||||
|
||||
-ifndef('ASYNC_REQUEST_PB_H').
|
||||
-define('ASYNC_REQUEST_PB_H', true).
|
||||
-record(async_request,
|
||||
{method = <<>> :: unicode:chardata() | undefined, % = 1, optional
|
||||
params = <<>> :: unicode:chardata() | undefined % = 2, optional
|
||||
}).
|
||||
-endif.
|
||||
|
||||
-ifndef('ASYNC_RESPONSE_PB_H').
|
||||
-define('ASYNC_RESPONSE_PB_H', true).
|
||||
-record(async_response,
|
||||
{code = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits
|
||||
result = <<>> :: unicode:chardata() | undefined, % = 2, optional
|
||||
message = <<>> :: unicode:chardata() | undefined % = 3, optional
|
||||
}).
|
||||
-endif.
|
||||
|
||||
-ifndef('SERVICE_CONFIG_PB_H').
|
||||
-define('SERVICE_CONFIG_PB_H', true).
|
||||
-record(service_config,
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
-module(service_handler).
|
||||
-author("licheng5").
|
||||
-include("iot.hrl").
|
||||
-include("iot_tables.hrl").
|
||||
-include("message_pb.hrl").
|
||||
|
||||
%% API
|
||||
-export([handle_request/4]).
|
||||
@ -19,7 +21,7 @@
|
||||
|
||||
handle_request("POST", "/service/set_config", _, #{<<"service_id">> := ServiceId, <<"config_json">> := ConfigJson, <<"last_edit_user">> := LastEditUser})
|
||||
when is_binary(ServiceId), is_binary(ConfigJson), is_integer(LastEditUser) ->
|
||||
lager:debug("[service_handler] service_id: ~p, config_json: ~p, last_edit_user:~p", [ServiceId, ConfigJson, LastEditUser]),
|
||||
lager:debug("[service_handler] set_config service_id: ~p, config_json: ~p, last_edit_user:~p", [ServiceId, ConfigJson, LastEditUser]),
|
||||
|
||||
case service_config_model:update(ServiceId, ConfigJson, LastEditUser) of
|
||||
ok ->
|
||||
@ -29,6 +31,34 @@ handle_request("POST", "/service/set_config", _, #{<<"service_id">> := ServiceId
|
||||
{ok, 200, iot_util:json_error(404, <<"set service config failed">>)}
|
||||
end;
|
||||
|
||||
handle_request("POST", "/service/push_config", _, #{<<"host_uuid">> := HostUUID, <<"service_id">> := ServiceId})
|
||||
when is_binary(ServiceId), is_binary(HostUUID) ->
|
||||
lager:debug("[service_handler] push_config host_uuid: ~p, service_id: ~p", [ServiceId, HostUUID, ServiceId]),
|
||||
|
||||
case service_config_model:get_config(ServiceId) of
|
||||
error ->
|
||||
{ok, 200, iot_util:json_error(404, <<"service config not found">>)};
|
||||
{ok, #service_config{config_json = ConfigJson}} ->
|
||||
case iot_host:get_pid(HostUUID) of
|
||||
undefined ->
|
||||
{ok, 200, iot_util:json_error(404, <<"host not found">>)};
|
||||
HostPid ->
|
||||
case iot_host:push_config(HostPid, ConfigJson) of
|
||||
{ok, Ref} ->
|
||||
receive
|
||||
{async_response, Ref, #async_response{code = 1}} ->
|
||||
{ok, 200, iot_util:json_data(<<"success">>)};
|
||||
{async_response, Ref, #async_response{code = 0, message = Message}} ->
|
||||
{ok, 200, iot_util:json_error(404, Message)}
|
||||
after 15000 ->
|
||||
{ok, 200, iot_util:json_error(404, <<"request timeout">>)}
|
||||
end;
|
||||
{error, Reason} when is_binary(Reason) ->
|
||||
{ok, 200, iot_util:json_error(404, Reason)}
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
handle_request("GET", "/service/get_config", #{<<"service_id">> := ServiceId}, _) when is_binary(ServiceId) ->
|
||||
case service_config_model:get_config(ServiceId) of
|
||||
error ->
|
||||
|
||||
@ -23,8 +23,9 @@
|
||||
%% API
|
||||
-export([start_link/2, get_name/1, get_alias_name/1, get_pid/1, handle/2, activate/2]).
|
||||
-export([get_metric/1, get_status/1]).
|
||||
-export([publish_directive/4, send_directive/3]).
|
||||
-export([attach_channel/2]).
|
||||
%% 通讯相关
|
||||
-export([pub/3, async_request/3, attach_channel/2, command/3, push_config/2]).
|
||||
%% 设备管理
|
||||
-export([reload_device/2, delete_device/2, activate_device/3]).
|
||||
-export([heartbeat/1]).
|
||||
|
||||
@ -87,30 +88,24 @@ get_metric(Pid) when is_pid(Pid) ->
|
||||
attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) ->
|
||||
gen_statem:call(Pid, {attach_channel, ChannelPid}).
|
||||
|
||||
-spec publish_directive(Pid :: pid(), Topic :: binary(), Content :: binary(), Timeout :: integer()) ->
|
||||
ok | {ok, Response :: binary()} | {error, Reason :: any()}.
|
||||
publish_directive(Pid, Topic, Content, Timeout) when is_pid(Pid), is_binary(Topic), is_binary(Content), is_integer(Timeout) ->
|
||||
case gen_statem:call(Pid, {publish_directive, self(), Topic, Content}) of
|
||||
{ok, Ref} ->
|
||||
receive
|
||||
{ws_response, Ref} ->
|
||||
ok;
|
||||
{ws_response, Ref, Response} ->
|
||||
{ok, Response}
|
||||
after Timeout ->
|
||||
{error, timeout}
|
||||
end;
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
end.
|
||||
-spec push_config(Pid :: pid(), ConfigJson :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||
push_config(Pid, ConfigJson) when is_pid(Pid), is_binary(ConfigJson) ->
|
||||
async_request(Pid, <<"$sys:push_config">>, ConfigJson).
|
||||
|
||||
-spec send_directive(Pid :: pid(), Topic :: binary(), Content :: binary()) ->
|
||||
ok | {error, Reason :: any()}.
|
||||
send_directive(Pid, Topic, Content) when is_pid(Pid), is_binary(Topic), is_binary(Content) ->
|
||||
gen_statem:call(Pid, {send_directive, Topic, Content}).
|
||||
%% 响应的消息格式为: {async_response, Ref, #async_response{}}
|
||||
-spec async_request(Pid :: pid(), Method :: binary(), Params :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
|
||||
async_request(Pid, Method, Params) when is_pid(Pid), is_binary(Method), is_binary(Params) ->
|
||||
gen_statem:call(Pid, {async_request, self(), Method, Params}).
|
||||
|
||||
-spec pub(Pid :: pid(), Topic :: binary(), Content :: binary()) -> ok | {error, Reason :: any()}.
|
||||
pub(Pid, Topic, Content) when is_pid(Pid), is_binary(Topic), is_binary(Content) ->
|
||||
gen_statem:call(Pid, {pub, Topic, Content}).
|
||||
|
||||
-spec command(Pid :: pid(), CommandType :: integer(), Command :: binary()) -> ok | {error, Reason :: any()}.
|
||||
command(Pid, CommandType, Command) when is_pid(Pid), is_integer(CommandType), is_binary(Command) ->
|
||||
gen_statem:call(Pid, {command, CommandType, Command}).
|
||||
|
||||
%% 设备管理相关
|
||||
|
||||
-spec reload_device(Pid :: pid(), DeviceUUID :: binary()) -> ok | {error, Reason :: any()}.
|
||||
reload_device(Pid, DeviceUUID) when is_pid(Pid), is_binary(DeviceUUID) ->
|
||||
gen_statem:call(Pid, {reload_device, DeviceUUID}).
|
||||
@ -190,7 +185,7 @@ handle_event({call, From}, get_metric, _, State = #state{metrics = Metrics}) ->
|
||||
{keep_state, State, [{reply, From, {ok, Metrics}}]};
|
||||
|
||||
%% 获取主机的状态
|
||||
handle_event({call, From}, get_status, _, State = #state{host_id = HostId, channel_pid = ChannelPid, heartbeat_counter = HeartbeatCounter, metrics = Metrics, has_session = HasSession}) ->
|
||||
handle_event({call, From}, get_status, _, State = #state{channel_pid = ChannelPid, heartbeat_counter = HeartbeatCounter, metrics = Metrics, has_session = HasSession}) ->
|
||||
HasChannel = (ChannelPid /= undefined),
|
||||
Reply = #{
|
||||
<<"has_channel">> => HasChannel,
|
||||
@ -201,61 +196,52 @@ handle_event({call, From}, get_status, _, State = #state{host_id = HostId, chann
|
||||
{keep_state, State, [{reply, From, {ok, Reply}}]};
|
||||
|
||||
%% 只要channel存在,就负责将消息推送到边缘端主机
|
||||
handle_event({call, From}, {publish_message, ReceiverPid, CommandType, Command}, _,
|
||||
State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = true}) when is_binary(Command), is_pid(ChannelPid) ->
|
||||
handle_event({call, From}, {async_request, ReceiverPid, Method, Params}, _, State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = HasSession}) ->
|
||||
case HasSession andalso is_pid(ChannelPid) of
|
||||
true ->
|
||||
%% 通过websocket发送请求
|
||||
lager:debug("[iot_host] host: ~p, will async_request method: ~p, params: ~p", [UUID, Method, Params]),
|
||||
Ref = tcp_channel:async_request(ChannelPid, ReceiverPid, Method, Params),
|
||||
|
||||
%% 通过websocket发送请求
|
||||
lager:debug("[iot_host] host: ~p, will publish message: ~p", [UUID, Command]),
|
||||
Ref = tcp_channel:publish(ChannelPid, ReceiverPid, <<CommandType:8, Command/binary>>),
|
||||
{keep_state, State, [{reply, From, {ok, Ref}}]};
|
||||
false ->
|
||||
lager:debug("[iot_host] uuid: ~p, publish_message invalid state: ~p", [UUID, state_map(State)]),
|
||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送请求失败"/utf8>>}}]}
|
||||
end;
|
||||
|
||||
{keep_state, State, [{reply, From, {ok, Ref}}]};
|
||||
%% 发送指令时, pub/sub
|
||||
handle_event({call, From}, {pub, Topic, Content}, ?STATE_ACTIVATED, State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = HasSession}) ->
|
||||
case HasSession andalso is_pid(ChannelPid) of
|
||||
true ->
|
||||
lager:debug("[iot_host] host: ~p, publish to topic: ~p, content: ~p", [UUID, Topic, Content]),
|
||||
%% 通过websocket发送请求
|
||||
tcp_channel:pub(ChannelPid, Topic, Content),
|
||||
|
||||
handle_event({call, From}, {publish_message, _, _, _}, _, State = #state{uuid = UUID}) ->
|
||||
lager:debug("[iot_host] uuid: ~p, publish_message invalid state: ~p", [UUID, state_map(State)]),
|
||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送命令失败"/utf8>>}}]};
|
||||
{keep_state, State, [{reply, From, ok}]};
|
||||
false ->
|
||||
lager:debug("[iot_host] uuid: ~p, publish to topic: ~p, content: ~p, invalid state: ~p", [UUID, Topic, Content, state_map(State)]),
|
||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送失败"/utf8>>}}]}
|
||||
end;
|
||||
|
||||
%% 发送指令时, 指令要通过aes加密,必须要求session是存在的
|
||||
handle_event({call, From}, {publish_directive, ReceiverPid, Topic, Content}, ?STATE_ACTIVATED,
|
||||
State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = true}) ->
|
||||
lager:debug("[iot_host] host: ~p, publish_directive to topic: ~p, content: ~p", [UUID, Topic, Content]),
|
||||
BinTopicMessage = message_pb:encode_msg(#topic_message{topic = Topic, content = Content}),
|
||||
|
||||
%% 通过websocket发送请求
|
||||
Ref = tcp_channel:publish(ChannelPid, ReceiverPid, <<16:8, BinTopicMessage/binary>>),
|
||||
|
||||
{keep_state, State, [{reply, From, {ok, Ref}}]};
|
||||
|
||||
%% 其他情况下,发送指令是失败的
|
||||
handle_event({call, From}, {publish_directive, _, Topic, Content}, _, State = #state{uuid = UUID}) ->
|
||||
lager:debug("[iot_host] uuid: ~p, publish_directive to topic: ~p, content: ~p, invalid state: ~p", [UUID, Topic, Content, state_map(State)]),
|
||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送指令失败"/utf8>>}}]};
|
||||
|
||||
%% 发送指令时!! 指令要明确发送到的目标device_uuid, 因为指令内容采用了json的格式
|
||||
handle_event({call, From}, {send_directive, Topic, Content}, ?STATE_ACTIVATED,
|
||||
State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = true}) ->
|
||||
|
||||
BinTopicMessage = message_pb:encode_msg(#topic_message{topic = Topic, content = Content}),
|
||||
lager:debug("[iot_host] host: ~p, will publish_directive: ~p", [UUID, Content]),
|
||||
|
||||
%% 通过websocket发送请求
|
||||
tcp_channel:send(ChannelPid, <<16:8, BinTopicMessage/binary>>),
|
||||
|
||||
{keep_state, State, [{reply, From, ok}]};
|
||||
|
||||
%% 其他情况下,发送指令是失败的
|
||||
handle_event({call, From}, {send_directive, Topic, Content}, _, State = #state{uuid = UUID}) ->
|
||||
lager:debug("[iot_host] host_uuid: ~p, send_directive to topic: ~p, content: ~p, invalid state: ~p",
|
||||
[UUID, Topic, Content, state_map(State)]),
|
||||
|
||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送指令失败"/utf8>>}}]};
|
||||
%% 发送指令时
|
||||
handle_event({call, From}, {command, CommandType, Command}, ?STATE_ACTIVATED, State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = HasSession}) ->
|
||||
case HasSession andalso is_pid(ChannelPid) of
|
||||
true ->
|
||||
lager:debug("[iot_host] host: ~p, command_type: ~p, command: ~p", [UUID, CommandType, Command]),
|
||||
%% 通过websocket发送请求
|
||||
tcp_channel:command(ChannelPid, CommandType, Command),
|
||||
{keep_state, State, [{reply, From, ok}]};
|
||||
false ->
|
||||
lager:debug("[iot_host] host: ~p, command_type: ~p, command: ~p, invalid state: ~p", [UUID, CommandType, Command, state_map(State)]),
|
||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送指令失败"/utf8>>}}]}
|
||||
end;
|
||||
|
||||
%% 激活主机
|
||||
handle_event({call, From}, {activate, true}, _, State = #state{uuid = UUID, channel_pid = ChannelPid}) ->
|
||||
case is_pid(ChannelPid) of
|
||||
true ->
|
||||
BinReply = message_pb:encode_msg(#activate_push{auth = true}),
|
||||
lager:debug("[iot_host] uuid: ~p, activate: true, will send message: ~p", [UUID, BinReply]),
|
||||
tcp_channel:send(ChannelPid, <<8:8, BinReply/binary>>);
|
||||
lager:debug("[iot_host] uuid: ~p, activate: true", [UUID]),
|
||||
tcp_channel:command(ChannelPid, ?COMMAND_AUTH, <<1:8>>);
|
||||
false ->
|
||||
lager:debug("[iot_host] uuid: ~p, activate: true, no channel", [UUID])
|
||||
end,
|
||||
@ -265,9 +251,8 @@ handle_event({call, From}, {activate, true}, _, State = #state{uuid = UUID, chan
|
||||
handle_event({call, From}, {activate, false}, _, State = #state{uuid = UUID, channel_pid = ChannelPid}) ->
|
||||
case is_pid(ChannelPid) of
|
||||
true ->
|
||||
BinReply = message_pb:encode_msg(#activate_push{auth = false}),
|
||||
tcp_channel:send(ChannelPid, <<8:8, BinReply/binary>>),
|
||||
lager:debug("[iot_host] uuid: ~p, activate: false, will send message: ~p", [UUID, BinReply]),
|
||||
tcp_channel:command(ChannelPid, ?COMMAND_AUTH, <<0:8>>),
|
||||
lager:debug("[iot_host] uuid: ~p, activate: false", [UUID]),
|
||||
tcp_channel:stop(ChannelPid, closed);
|
||||
false ->
|
||||
lager:debug("[iot_host] uuid: ~p, activate: false, no channel", [UUID])
|
||||
|
||||
@ -59,13 +59,15 @@
|
||||
|
||||
-type auth_reply() :: #auth_reply{}.
|
||||
|
||||
-type activate_push() :: #activate_push{}.
|
||||
|
||||
-type deploy() :: #deploy{}.
|
||||
|
||||
-type efka_response() :: #efka_response{}.
|
||||
|
||||
-type topic_message() :: #topic_message{}.
|
||||
-type pub() :: #pub{}.
|
||||
|
||||
-type async_request() :: #async_request{}.
|
||||
|
||||
-type async_response() :: #async_response{}.
|
||||
|
||||
-type service_config() :: #service_config{}.
|
||||
|
||||
@ -79,9 +81,9 @@
|
||||
|
||||
-type event() :: #event{}.
|
||||
|
||||
-export_type(['auth_request'/0, 'auth_reply'/0, 'activate_push'/0, 'deploy'/0, 'efka_response'/0, 'topic_message'/0, 'service_config'/0, 'data'/0, 'ping'/0, 'service_inform'/0, 'feedback_phase'/0, 'event'/0]).
|
||||
-type '$msg_name'() :: auth_request | auth_reply | activate_push | deploy | efka_response | topic_message | service_config | data | ping | service_inform | feedback_phase | event.
|
||||
-type '$msg'() :: auth_request() | auth_reply() | activate_push() | deploy() | efka_response() | topic_message() | service_config() | data() | ping() | service_inform() | feedback_phase() | event().
|
||||
-export_type(['auth_request'/0, 'auth_reply'/0, 'deploy'/0, 'efka_response'/0, 'pub'/0, 'async_request'/0, 'async_response'/0, 'service_config'/0, 'data'/0, 'ping'/0, 'service_inform'/0, 'feedback_phase'/0, 'event'/0]).
|
||||
-type '$msg_name'() :: auth_request | auth_reply | deploy | efka_response | pub | async_request | async_response | service_config | data | ping | service_inform | feedback_phase | event.
|
||||
-type '$msg'() :: auth_request() | auth_reply() | deploy() | efka_response() | pub() | async_request() | async_response() | service_config() | data() | ping() | service_inform() | feedback_phase() | event().
|
||||
-export_type(['$msg_name'/0, '$msg'/0]).
|
||||
|
||||
-if(?OTP_RELEASE >= 24).
|
||||
@ -110,10 +112,11 @@ encode_msg(Msg, MsgName, Opts) ->
|
||||
case MsgName of
|
||||
auth_request -> encode_msg_auth_request(id(Msg, TrUserData), TrUserData);
|
||||
auth_reply -> encode_msg_auth_reply(id(Msg, TrUserData), TrUserData);
|
||||
activate_push -> encode_msg_activate_push(id(Msg, TrUserData), TrUserData);
|
||||
deploy -> encode_msg_deploy(id(Msg, TrUserData), TrUserData);
|
||||
efka_response -> encode_msg_efka_response(id(Msg, TrUserData), TrUserData);
|
||||
topic_message -> encode_msg_topic_message(id(Msg, TrUserData), TrUserData);
|
||||
pub -> encode_msg_pub(id(Msg, TrUserData), TrUserData);
|
||||
async_request -> encode_msg_async_request(id(Msg, TrUserData), TrUserData);
|
||||
async_response -> encode_msg_async_response(id(Msg, TrUserData), TrUserData);
|
||||
service_config -> encode_msg_service_config(id(Msg, TrUserData), TrUserData);
|
||||
data -> encode_msg_data(id(Msg, TrUserData), TrUserData);
|
||||
ping -> encode_msg_ping(id(Msg, TrUserData), TrUserData);
|
||||
@ -201,20 +204,6 @@ encode_msg_auth_reply(#auth_reply{code = F1, message = F2}, Bin, TrUserData) ->
|
||||
end
|
||||
end.
|
||||
|
||||
encode_msg_activate_push(Msg, TrUserData) -> encode_msg_activate_push(Msg, <<>>, TrUserData).
|
||||
|
||||
|
||||
encode_msg_activate_push(#activate_push{auth = F1}, Bin, TrUserData) ->
|
||||
if F1 == undefined -> Bin;
|
||||
true ->
|
||||
begin
|
||||
TrF1 = id(F1, TrUserData),
|
||||
if TrF1 =:= false -> Bin;
|
||||
true -> e_type_bool(TrF1, <<Bin/binary, 8>>, TrUserData)
|
||||
end
|
||||
end
|
||||
end.
|
||||
|
||||
encode_msg_deploy(Msg, TrUserData) -> encode_msg_deploy(Msg, <<>>, TrUserData).
|
||||
|
||||
|
||||
@ -283,10 +272,10 @@ encode_msg_efka_response(#efka_response{code = F1, result = F2, message = F3}, B
|
||||
end
|
||||
end.
|
||||
|
||||
encode_msg_topic_message(Msg, TrUserData) -> encode_msg_topic_message(Msg, <<>>, TrUserData).
|
||||
encode_msg_pub(Msg, TrUserData) -> encode_msg_pub(Msg, <<>>, TrUserData).
|
||||
|
||||
|
||||
encode_msg_topic_message(#topic_message{topic = F1, content = F2}, Bin, TrUserData) ->
|
||||
encode_msg_pub(#pub{topic = F1, content = F2}, Bin, TrUserData) ->
|
||||
B1 = if F1 == undefined -> Bin;
|
||||
true ->
|
||||
begin
|
||||
@ -308,6 +297,65 @@ encode_msg_topic_message(#topic_message{topic = F1, content = F2}, Bin, TrUserDa
|
||||
end
|
||||
end.
|
||||
|
||||
encode_msg_async_request(Msg, TrUserData) -> encode_msg_async_request(Msg, <<>>, TrUserData).
|
||||
|
||||
|
||||
encode_msg_async_request(#async_request{method = F1, params = F2}, Bin, TrUserData) ->
|
||||
B1 = if F1 == undefined -> Bin;
|
||||
true ->
|
||||
begin
|
||||
TrF1 = id(F1, TrUserData),
|
||||
case is_empty_string(TrF1) of
|
||||
true -> Bin;
|
||||
false -> e_type_string(TrF1, <<Bin/binary, 10>>, TrUserData)
|
||||
end
|
||||
end
|
||||
end,
|
||||
if F2 == undefined -> B1;
|
||||
true ->
|
||||
begin
|
||||
TrF2 = id(F2, TrUserData),
|
||||
case is_empty_string(TrF2) of
|
||||
true -> B1;
|
||||
false -> e_type_string(TrF2, <<B1/binary, 18>>, TrUserData)
|
||||
end
|
||||
end
|
||||
end.
|
||||
|
||||
encode_msg_async_response(Msg, TrUserData) -> encode_msg_async_response(Msg, <<>>, TrUserData).
|
||||
|
||||
|
||||
encode_msg_async_response(#async_response{code = F1, result = F2, message = F3}, Bin, TrUserData) ->
|
||||
B1 = if F1 == undefined -> Bin;
|
||||
true ->
|
||||
begin
|
||||
TrF1 = id(F1, TrUserData),
|
||||
if TrF1 =:= 0 -> Bin;
|
||||
true -> e_varint(TrF1, <<Bin/binary, 8>>, TrUserData)
|
||||
end
|
||||
end
|
||||
end,
|
||||
B2 = if F2 == undefined -> B1;
|
||||
true ->
|
||||
begin
|
||||
TrF2 = id(F2, TrUserData),
|
||||
case is_empty_string(TrF2) of
|
||||
true -> B1;
|
||||
false -> e_type_string(TrF2, <<B1/binary, 18>>, TrUserData)
|
||||
end
|
||||
end
|
||||
end,
|
||||
if F3 == undefined -> B2;
|
||||
true ->
|
||||
begin
|
||||
TrF3 = id(F3, TrUserData),
|
||||
case is_empty_string(TrF3) of
|
||||
true -> B2;
|
||||
false -> e_type_string(TrF3, <<B2/binary, 26>>, TrUserData)
|
||||
end
|
||||
end
|
||||
end.
|
||||
|
||||
encode_msg_service_config(Msg, TrUserData) -> encode_msg_service_config(Msg, <<>>, TrUserData).
|
||||
|
||||
|
||||
@ -777,10 +825,11 @@ decode_msg_1_catch(Bin, MsgName, TrUserData) ->
|
||||
|
||||
decode_msg_2_doit(auth_request, Bin, TrUserData) -> id(decode_msg_auth_request(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(auth_reply, Bin, TrUserData) -> id(decode_msg_auth_reply(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(activate_push, Bin, TrUserData) -> id(decode_msg_activate_push(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(deploy, Bin, TrUserData) -> id(decode_msg_deploy(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(efka_response, Bin, TrUserData) -> id(decode_msg_efka_response(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(topic_message, Bin, TrUserData) -> id(decode_msg_topic_message(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(pub, Bin, TrUserData) -> id(decode_msg_pub(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(async_request, Bin, TrUserData) -> id(decode_msg_async_request(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(async_response, Bin, TrUserData) -> id(decode_msg_async_response(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(service_config, Bin, TrUserData) -> id(decode_msg_service_config(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(data, Bin, TrUserData) -> id(decode_msg_data(Bin, TrUserData), TrUserData);
|
||||
decode_msg_2_doit(ping, Bin, TrUserData) -> id(decode_msg_ping(Bin, TrUserData), TrUserData);
|
||||
@ -913,50 +962,6 @@ skip_32_auth_reply(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) ->
|
||||
|
||||
skip_64_auth_reply(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_auth_reply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
decode_msg_activate_push(Bin, TrUserData) -> dfp_read_field_def_activate_push(Bin, 0, 0, 0, id(false, TrUserData), TrUserData).
|
||||
|
||||
dfp_read_field_def_activate_push(<<8, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> d_field_activate_push_auth(Rest, Z1, Z2, F, F@_1, TrUserData);
|
||||
dfp_read_field_def_activate_push(<<>>, 0, 0, _, F@_1, _) -> #activate_push{auth = F@_1};
|
||||
dfp_read_field_def_activate_push(Other, Z1, Z2, F, F@_1, TrUserData) -> dg_read_field_def_activate_push(Other, Z1, Z2, F, F@_1, TrUserData).
|
||||
|
||||
dg_read_field_def_activate_push(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 32 - 7 -> dg_read_field_def_activate_push(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData);
|
||||
dg_read_field_def_activate_push(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, TrUserData) ->
|
||||
Key = X bsl N + Acc,
|
||||
case Key of
|
||||
8 -> d_field_activate_push_auth(Rest, 0, 0, 0, F@_1, TrUserData);
|
||||
_ ->
|
||||
case Key band 7 of
|
||||
0 -> skip_varint_activate_push(Rest, 0, 0, Key bsr 3, F@_1, TrUserData);
|
||||
1 -> skip_64_activate_push(Rest, 0, 0, Key bsr 3, F@_1, TrUserData);
|
||||
2 -> skip_length_delimited_activate_push(Rest, 0, 0, Key bsr 3, F@_1, TrUserData);
|
||||
3 -> skip_group_activate_push(Rest, 0, 0, Key bsr 3, F@_1, TrUserData);
|
||||
5 -> skip_32_activate_push(Rest, 0, 0, Key bsr 3, F@_1, TrUserData)
|
||||
end
|
||||
end;
|
||||
dg_read_field_def_activate_push(<<>>, 0, 0, _, F@_1, _) -> #activate_push{auth = F@_1}.
|
||||
|
||||
d_field_activate_push_auth(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> d_field_activate_push_auth(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData);
|
||||
d_field_activate_push_auth(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, TrUserData) ->
|
||||
{NewFValue, RestF} = {id(X bsl N + Acc =/= 0, TrUserData), Rest},
|
||||
dfp_read_field_def_activate_push(RestF, 0, 0, F, NewFValue, TrUserData).
|
||||
|
||||
skip_varint_activate_push(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> skip_varint_activate_push(Rest, Z1, Z2, F, F@_1, TrUserData);
|
||||
skip_varint_activate_push(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_activate_push(Rest, Z1, Z2, F, F@_1, TrUserData).
|
||||
|
||||
skip_length_delimited_activate_push(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) when N < 57 -> skip_length_delimited_activate_push(Rest, N + 7, X bsl N + Acc, F, F@_1, TrUserData);
|
||||
skip_length_delimited_activate_push(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, TrUserData) ->
|
||||
Length = X bsl N + Acc,
|
||||
<<_:Length/binary, Rest2/binary>> = Rest,
|
||||
dfp_read_field_def_activate_push(Rest2, 0, 0, F, F@_1, TrUserData).
|
||||
|
||||
skip_group_activate_push(Bin, _, Z2, FNum, F@_1, TrUserData) ->
|
||||
{_, Rest} = read_group(Bin, FNum),
|
||||
dfp_read_field_def_activate_push(Rest, 0, Z2, FNum, F@_1, TrUserData).
|
||||
|
||||
skip_32_activate_push(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_activate_push(Rest, Z1, Z2, F, F@_1, TrUserData).
|
||||
|
||||
skip_64_activate_push(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, TrUserData) -> dfp_read_field_def_activate_push(Rest, Z1, Z2, F, F@_1, TrUserData).
|
||||
|
||||
decode_msg_deploy(Bin, TrUserData) -> dfp_read_field_def_deploy(Bin, 0, 0, 0, id(0, TrUserData), id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData).
|
||||
|
||||
dfp_read_field_def_deploy(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_deploy_task_id(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
@ -1073,56 +1078,165 @@ skip_32_efka_response(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUser
|
||||
|
||||
skip_64_efka_response(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_efka_response(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData).
|
||||
|
||||
decode_msg_topic_message(Bin, TrUserData) -> dfp_read_field_def_topic_message(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData).
|
||||
decode_msg_pub(Bin, TrUserData) -> dfp_read_field_def_pub(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData).
|
||||
|
||||
dfp_read_field_def_topic_message(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_topic_message_topic(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
dfp_read_field_def_topic_message(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_topic_message_content(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
dfp_read_field_def_topic_message(<<>>, 0, 0, _, F@_1, F@_2, _) -> #topic_message{topic = F@_1, content = F@_2};
|
||||
dfp_read_field_def_topic_message(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_topic_message(Other, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
dfp_read_field_def_pub(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_pub_topic(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
dfp_read_field_def_pub(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_pub_content(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
dfp_read_field_def_pub(<<>>, 0, 0, _, F@_1, F@_2, _) -> #pub{topic = F@_1, content = F@_2};
|
||||
dfp_read_field_def_pub(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_pub(Other, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
dg_read_field_def_topic_message(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_topic_message(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
dg_read_field_def_topic_message(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) ->
|
||||
dg_read_field_def_pub(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_pub(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
dg_read_field_def_pub(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) ->
|
||||
Key = X bsl N + Acc,
|
||||
case Key of
|
||||
10 -> d_field_topic_message_topic(Rest, 0, 0, 0, F@_1, F@_2, TrUserData);
|
||||
18 -> d_field_topic_message_content(Rest, 0, 0, 0, F@_1, F@_2, TrUserData);
|
||||
10 -> d_field_pub_topic(Rest, 0, 0, 0, F@_1, F@_2, TrUserData);
|
||||
18 -> d_field_pub_content(Rest, 0, 0, 0, F@_1, F@_2, TrUserData);
|
||||
_ ->
|
||||
case Key band 7 of
|
||||
0 -> skip_varint_topic_message(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
1 -> skip_64_topic_message(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
2 -> skip_length_delimited_topic_message(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
3 -> skip_group_topic_message(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
5 -> skip_32_topic_message(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData)
|
||||
0 -> skip_varint_pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
1 -> skip_64_pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
2 -> skip_length_delimited_pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
3 -> skip_group_pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
5 -> skip_32_pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData)
|
||||
end
|
||||
end;
|
||||
dg_read_field_def_topic_message(<<>>, 0, 0, _, F@_1, F@_2, _) -> #topic_message{topic = F@_1, content = F@_2}.
|
||||
dg_read_field_def_pub(<<>>, 0, 0, _, F@_1, F@_2, _) -> #pub{topic = F@_1, content = F@_2}.
|
||||
|
||||
d_field_topic_message_topic(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_topic_message_topic(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
d_field_topic_message_topic(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) ->
|
||||
d_field_pub_topic(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_pub_topic(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
d_field_pub_topic(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) ->
|
||||
{NewFValue, RestF} = begin Len = X bsl N + Acc, <<Bytes:Len/binary, Rest2/binary>> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end,
|
||||
dfp_read_field_def_topic_message(RestF, 0, 0, F, NewFValue, F@_2, TrUserData).
|
||||
dfp_read_field_def_pub(RestF, 0, 0, F, NewFValue, F@_2, TrUserData).
|
||||
|
||||
d_field_topic_message_content(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_topic_message_content(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
d_field_topic_message_content(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) ->
|
||||
d_field_pub_content(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_pub_content(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
d_field_pub_content(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) ->
|
||||
{NewFValue, RestF} = begin Len = X bsl N + Acc, <<Bytes:Len/binary, Rest2/binary>> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end,
|
||||
dfp_read_field_def_topic_message(RestF, 0, 0, F, F@_1, NewFValue, TrUserData).
|
||||
dfp_read_field_def_pub(RestF, 0, 0, F, F@_1, NewFValue, TrUserData).
|
||||
|
||||
skip_varint_topic_message(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_topic_message(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
skip_varint_topic_message(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_topic_message(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
skip_varint_pub(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_pub(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
skip_varint_pub(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_pub(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
skip_length_delimited_topic_message(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_topic_message(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
skip_length_delimited_topic_message(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) ->
|
||||
skip_length_delimited_pub(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_pub(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
skip_length_delimited_pub(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) ->
|
||||
Length = X bsl N + Acc,
|
||||
<<_:Length/binary, Rest2/binary>> = Rest,
|
||||
dfp_read_field_def_topic_message(Rest2, 0, 0, F, F@_1, F@_2, TrUserData).
|
||||
dfp_read_field_def_pub(Rest2, 0, 0, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
skip_group_topic_message(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) ->
|
||||
skip_group_pub(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) ->
|
||||
{_, Rest} = read_group(Bin, FNum),
|
||||
dfp_read_field_def_topic_message(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData).
|
||||
dfp_read_field_def_pub(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData).
|
||||
|
||||
skip_32_topic_message(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_topic_message(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
skip_32_pub(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_pub(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
skip_64_topic_message(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_topic_message(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
skip_64_pub(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_pub(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
decode_msg_async_request(Bin, TrUserData) -> dfp_read_field_def_async_request(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData).
|
||||
|
||||
dfp_read_field_def_async_request(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_async_request_method(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
dfp_read_field_def_async_request(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_async_request_params(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
dfp_read_field_def_async_request(<<>>, 0, 0, _, F@_1, F@_2, _) -> #async_request{method = F@_1, params = F@_2};
|
||||
dfp_read_field_def_async_request(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_async_request(Other, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
dg_read_field_def_async_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_async_request(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
dg_read_field_def_async_request(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) ->
|
||||
Key = X bsl N + Acc,
|
||||
case Key of
|
||||
10 -> d_field_async_request_method(Rest, 0, 0, 0, F@_1, F@_2, TrUserData);
|
||||
18 -> d_field_async_request_params(Rest, 0, 0, 0, F@_1, F@_2, TrUserData);
|
||||
_ ->
|
||||
case Key band 7 of
|
||||
0 -> skip_varint_async_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
1 -> skip_64_async_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
2 -> skip_length_delimited_async_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
3 -> skip_group_async_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData);
|
||||
5 -> skip_32_async_request(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData)
|
||||
end
|
||||
end;
|
||||
dg_read_field_def_async_request(<<>>, 0, 0, _, F@_1, F@_2, _) -> #async_request{method = F@_1, params = F@_2}.
|
||||
|
||||
d_field_async_request_method(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_async_request_method(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
d_field_async_request_method(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) ->
|
||||
{NewFValue, RestF} = begin Len = X bsl N + Acc, <<Bytes:Len/binary, Rest2/binary>> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end,
|
||||
dfp_read_field_def_async_request(RestF, 0, 0, F, NewFValue, F@_2, TrUserData).
|
||||
|
||||
d_field_async_request_params(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_async_request_params(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
d_field_async_request_params(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) ->
|
||||
{NewFValue, RestF} = begin Len = X bsl N + Acc, <<Bytes:Len/binary, Rest2/binary>> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end,
|
||||
dfp_read_field_def_async_request(RestF, 0, 0, F, F@_1, NewFValue, TrUserData).
|
||||
|
||||
skip_varint_async_request(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_async_request(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData);
|
||||
skip_varint_async_request(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_async_request(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
skip_length_delimited_async_request(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_async_request(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData);
|
||||
skip_length_delimited_async_request(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) ->
|
||||
Length = X bsl N + Acc,
|
||||
<<_:Length/binary, Rest2/binary>> = Rest,
|
||||
dfp_read_field_def_async_request(Rest2, 0, 0, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
skip_group_async_request(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) ->
|
||||
{_, Rest} = read_group(Bin, FNum),
|
||||
dfp_read_field_def_async_request(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData).
|
||||
|
||||
skip_32_async_request(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_async_request(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
skip_64_async_request(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_async_request(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData).
|
||||
|
||||
decode_msg_async_response(Bin, TrUserData) -> dfp_read_field_def_async_response(Bin, 0, 0, 0, id(0, TrUserData), id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData).
|
||||
|
||||
dfp_read_field_def_async_response(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_async_response_code(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
dfp_read_field_def_async_response(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_async_response_result(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
dfp_read_field_def_async_response(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_async_response_message(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
dfp_read_field_def_async_response(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #async_response{code = F@_1, result = F@_2, message = F@_3};
|
||||
dfp_read_field_def_async_response(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dg_read_field_def_async_response(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData).
|
||||
|
||||
dg_read_field_def_async_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 32 - 7 -> dg_read_field_def_async_response(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
dg_read_field_def_async_response(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, TrUserData) ->
|
||||
Key = X bsl N + Acc,
|
||||
case Key of
|
||||
8 -> d_field_async_response_code(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData);
|
||||
18 -> d_field_async_response_result(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData);
|
||||
26 -> d_field_async_response_message(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData);
|
||||
_ ->
|
||||
case Key band 7 of
|
||||
0 -> skip_varint_async_response(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData);
|
||||
1 -> skip_64_async_response(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData);
|
||||
2 -> skip_length_delimited_async_response(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData);
|
||||
3 -> skip_group_async_response(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData);
|
||||
5 -> skip_32_async_response(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData)
|
||||
end
|
||||
end;
|
||||
dg_read_field_def_async_response(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #async_response{code = F@_1, result = F@_2, message = F@_3}.
|
||||
|
||||
d_field_async_response_code(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_async_response_code(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
d_field_async_response_code(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, TrUserData) ->
|
||||
{NewFValue, RestF} = {id((X bsl N + Acc) band 4294967295, TrUserData), Rest},
|
||||
dfp_read_field_def_async_response(RestF, 0, 0, F, NewFValue, F@_2, F@_3, TrUserData).
|
||||
|
||||
d_field_async_response_result(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_async_response_result(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
d_field_async_response_result(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, TrUserData) ->
|
||||
{NewFValue, RestF} = begin Len = X bsl N + Acc, <<Bytes:Len/binary, Rest2/binary>> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end,
|
||||
dfp_read_field_def_async_response(RestF, 0, 0, F, F@_1, NewFValue, F@_3, TrUserData).
|
||||
|
||||
d_field_async_response_message(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_async_response_message(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
d_field_async_response_message(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, TrUserData) ->
|
||||
{NewFValue, RestF} = begin Len = X bsl N + Acc, <<Bytes:Len/binary, Rest2/binary>> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end,
|
||||
dfp_read_field_def_async_response(RestF, 0, 0, F, F@_1, F@_2, NewFValue, TrUserData).
|
||||
|
||||
skip_varint_async_response(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> skip_varint_async_response(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
skip_varint_async_response(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_async_response(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData).
|
||||
|
||||
skip_length_delimited_async_response(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> skip_length_delimited_async_response(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData);
|
||||
skip_length_delimited_async_response(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) ->
|
||||
Length = X bsl N + Acc,
|
||||
<<_:Length/binary, Rest2/binary>> = Rest,
|
||||
dfp_read_field_def_async_response(Rest2, 0, 0, F, F@_1, F@_2, F@_3, TrUserData).
|
||||
|
||||
skip_group_async_response(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, TrUserData) ->
|
||||
{_, Rest} = read_group(Bin, FNum),
|
||||
dfp_read_field_def_async_response(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, TrUserData).
|
||||
|
||||
skip_32_async_response(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_async_response(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData).
|
||||
|
||||
skip_64_async_response(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_async_response(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData).
|
||||
|
||||
decode_msg_service_config(Bin, TrUserData) -> dfp_read_field_def_service_config(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), id(0, TrUserData), TrUserData).
|
||||
|
||||
@ -1709,10 +1823,11 @@ merge_msgs(Prev, New, MsgName, Opts) ->
|
||||
case MsgName of
|
||||
auth_request -> merge_msg_auth_request(Prev, New, TrUserData);
|
||||
auth_reply -> merge_msg_auth_reply(Prev, New, TrUserData);
|
||||
activate_push -> merge_msg_activate_push(Prev, New, TrUserData);
|
||||
deploy -> merge_msg_deploy(Prev, New, TrUserData);
|
||||
efka_response -> merge_msg_efka_response(Prev, New, TrUserData);
|
||||
topic_message -> merge_msg_topic_message(Prev, New, TrUserData);
|
||||
pub -> merge_msg_pub(Prev, New, TrUserData);
|
||||
async_request -> merge_msg_async_request(Prev, New, TrUserData);
|
||||
async_response -> merge_msg_async_response(Prev, New, TrUserData);
|
||||
service_config -> merge_msg_service_config(Prev, New, TrUserData);
|
||||
data -> merge_msg_data(Prev, New, TrUserData);
|
||||
ping -> merge_msg_ping(Prev, New, TrUserData);
|
||||
@ -1755,13 +1870,6 @@ merge_msg_auth_reply(#auth_reply{code = PFcode, message = PFmessage}, #auth_repl
|
||||
true -> NFmessage
|
||||
end}.
|
||||
|
||||
-compile({nowarn_unused_function,merge_msg_activate_push/3}).
|
||||
merge_msg_activate_push(#activate_push{auth = PFauth}, #activate_push{auth = NFauth}, _) ->
|
||||
#activate_push{auth =
|
||||
if NFauth =:= undefined -> PFauth;
|
||||
true -> NFauth
|
||||
end}.
|
||||
|
||||
-compile({nowarn_unused_function,merge_msg_deploy/3}).
|
||||
merge_msg_deploy(#deploy{task_id = PFtask_id, service_id = PFservice_id, tar_url = PFtar_url}, #deploy{task_id = NFtask_id, service_id = NFservice_id, tar_url = NFtar_url}, _) ->
|
||||
#deploy{task_id =
|
||||
@ -1792,17 +1900,43 @@ merge_msg_efka_response(#efka_response{code = PFcode, result = PFresult, message
|
||||
true -> NFmessage
|
||||
end}.
|
||||
|
||||
-compile({nowarn_unused_function,merge_msg_topic_message/3}).
|
||||
merge_msg_topic_message(#topic_message{topic = PFtopic, content = PFcontent}, #topic_message{topic = NFtopic, content = NFcontent}, _) ->
|
||||
#topic_message{topic =
|
||||
if NFtopic =:= undefined -> PFtopic;
|
||||
true -> NFtopic
|
||||
-compile({nowarn_unused_function,merge_msg_pub/3}).
|
||||
merge_msg_pub(#pub{topic = PFtopic, content = PFcontent}, #pub{topic = NFtopic, content = NFcontent}, _) ->
|
||||
#pub{topic =
|
||||
if NFtopic =:= undefined -> PFtopic;
|
||||
true -> NFtopic
|
||||
end,
|
||||
content =
|
||||
if NFcontent =:= undefined -> PFcontent;
|
||||
true -> NFcontent
|
||||
end}.
|
||||
|
||||
-compile({nowarn_unused_function,merge_msg_async_request/3}).
|
||||
merge_msg_async_request(#async_request{method = PFmethod, params = PFparams}, #async_request{method = NFmethod, params = NFparams}, _) ->
|
||||
#async_request{method =
|
||||
if NFmethod =:= undefined -> PFmethod;
|
||||
true -> NFmethod
|
||||
end,
|
||||
content =
|
||||
if NFcontent =:= undefined -> PFcontent;
|
||||
true -> NFcontent
|
||||
params =
|
||||
if NFparams =:= undefined -> PFparams;
|
||||
true -> NFparams
|
||||
end}.
|
||||
|
||||
-compile({nowarn_unused_function,merge_msg_async_response/3}).
|
||||
merge_msg_async_response(#async_response{code = PFcode, result = PFresult, message = PFmessage}, #async_response{code = NFcode, result = NFresult, message = NFmessage}, _) ->
|
||||
#async_response{code =
|
||||
if NFcode =:= undefined -> PFcode;
|
||||
true -> NFcode
|
||||
end,
|
||||
result =
|
||||
if NFresult =:= undefined -> PFresult;
|
||||
true -> NFresult
|
||||
end,
|
||||
message =
|
||||
if NFmessage =:= undefined -> PFmessage;
|
||||
true -> NFmessage
|
||||
end}.
|
||||
|
||||
-compile({nowarn_unused_function,merge_msg_service_config/3}).
|
||||
merge_msg_service_config(#service_config{service_id = PFservice_id, config_json = PFconfig_json, timeout = PFtimeout}, #service_config{service_id = NFservice_id, config_json = NFconfig_json, timeout = NFtimeout}, _) ->
|
||||
#service_config{service_id =
|
||||
@ -1957,10 +2091,11 @@ verify_msg(Msg, MsgName, Opts) ->
|
||||
case MsgName of
|
||||
auth_request -> v_msg_auth_request(Msg, [MsgName], TrUserData);
|
||||
auth_reply -> v_msg_auth_reply(Msg, [MsgName], TrUserData);
|
||||
activate_push -> v_msg_activate_push(Msg, [MsgName], TrUserData);
|
||||
deploy -> v_msg_deploy(Msg, [MsgName], TrUserData);
|
||||
efka_response -> v_msg_efka_response(Msg, [MsgName], TrUserData);
|
||||
topic_message -> v_msg_topic_message(Msg, [MsgName], TrUserData);
|
||||
pub -> v_msg_pub(Msg, [MsgName], TrUserData);
|
||||
async_request -> v_msg_async_request(Msg, [MsgName], TrUserData);
|
||||
async_response -> v_msg_async_response(Msg, [MsgName], TrUserData);
|
||||
service_config -> v_msg_service_config(Msg, [MsgName], TrUserData);
|
||||
data -> v_msg_data(Msg, [MsgName], TrUserData);
|
||||
ping -> v_msg_ping(Msg, [MsgName], TrUserData);
|
||||
@ -2004,15 +2139,6 @@ v_msg_auth_reply(#auth_reply{code = F1, message = F2}, Path, TrUserData) ->
|
||||
ok;
|
||||
v_msg_auth_reply(X, Path, _TrUserData) -> mk_type_error({expected_msg, auth_reply}, X, Path).
|
||||
|
||||
-compile({nowarn_unused_function,v_msg_activate_push/3}).
|
||||
-dialyzer({nowarn_function,v_msg_activate_push/3}).
|
||||
v_msg_activate_push(#activate_push{auth = F1}, Path, TrUserData) ->
|
||||
if F1 == undefined -> ok;
|
||||
true -> v_type_bool(F1, [auth | Path], TrUserData)
|
||||
end,
|
||||
ok;
|
||||
v_msg_activate_push(X, Path, _TrUserData) -> mk_type_error({expected_msg, activate_push}, X, Path).
|
||||
|
||||
-compile({nowarn_unused_function,v_msg_deploy/3}).
|
||||
-dialyzer({nowarn_function,v_msg_deploy/3}).
|
||||
v_msg_deploy(#deploy{task_id = F1, service_id = F2, tar_url = F3}, Path, TrUserData) ->
|
||||
@ -2043,9 +2169,9 @@ v_msg_efka_response(#efka_response{code = F1, result = F2, message = F3}, Path,
|
||||
ok;
|
||||
v_msg_efka_response(X, Path, _TrUserData) -> mk_type_error({expected_msg, efka_response}, X, Path).
|
||||
|
||||
-compile({nowarn_unused_function,v_msg_topic_message/3}).
|
||||
-dialyzer({nowarn_function,v_msg_topic_message/3}).
|
||||
v_msg_topic_message(#topic_message{topic = F1, content = F2}, Path, TrUserData) ->
|
||||
-compile({nowarn_unused_function,v_msg_pub/3}).
|
||||
-dialyzer({nowarn_function,v_msg_pub/3}).
|
||||
v_msg_pub(#pub{topic = F1, content = F2}, Path, TrUserData) ->
|
||||
if F1 == undefined -> ok;
|
||||
true -> v_type_string(F1, [topic | Path], TrUserData)
|
||||
end,
|
||||
@ -2053,7 +2179,34 @@ v_msg_topic_message(#topic_message{topic = F1, content = F2}, Path, TrUserData)
|
||||
true -> v_type_string(F2, [content | Path], TrUserData)
|
||||
end,
|
||||
ok;
|
||||
v_msg_topic_message(X, Path, _TrUserData) -> mk_type_error({expected_msg, topic_message}, X, Path).
|
||||
v_msg_pub(X, Path, _TrUserData) -> mk_type_error({expected_msg, pub}, X, Path).
|
||||
|
||||
-compile({nowarn_unused_function,v_msg_async_request/3}).
|
||||
-dialyzer({nowarn_function,v_msg_async_request/3}).
|
||||
v_msg_async_request(#async_request{method = F1, params = F2}, Path, TrUserData) ->
|
||||
if F1 == undefined -> ok;
|
||||
true -> v_type_string(F1, [method | Path], TrUserData)
|
||||
end,
|
||||
if F2 == undefined -> ok;
|
||||
true -> v_type_string(F2, [params | Path], TrUserData)
|
||||
end,
|
||||
ok;
|
||||
v_msg_async_request(X, Path, _TrUserData) -> mk_type_error({expected_msg, async_request}, X, Path).
|
||||
|
||||
-compile({nowarn_unused_function,v_msg_async_response/3}).
|
||||
-dialyzer({nowarn_function,v_msg_async_response/3}).
|
||||
v_msg_async_response(#async_response{code = F1, result = F2, message = F3}, Path, TrUserData) ->
|
||||
if F1 == undefined -> ok;
|
||||
true -> v_type_uint32(F1, [code | Path], TrUserData)
|
||||
end,
|
||||
if F2 == undefined -> ok;
|
||||
true -> v_type_string(F2, [result | Path], TrUserData)
|
||||
end,
|
||||
if F3 == undefined -> ok;
|
||||
true -> v_type_string(F3, [message | Path], TrUserData)
|
||||
end,
|
||||
ok;
|
||||
v_msg_async_response(X, Path, _TrUserData) -> mk_type_error({expected_msg, async_response}, X, Path).
|
||||
|
||||
-compile({nowarn_unused_function,v_msg_service_config/3}).
|
||||
-dialyzer({nowarn_function,v_msg_service_config/3}).
|
||||
@ -2196,14 +2349,6 @@ v_type_uint32(N, _Path, _TrUserData) when is_integer(N), 0 =< N, N =< 4294967295
|
||||
v_type_uint32(N, Path, _TrUserData) when is_integer(N) -> mk_type_error({value_out_of_range, uint32, unsigned, 32}, N, Path);
|
||||
v_type_uint32(X, Path, _TrUserData) -> mk_type_error({bad_integer, uint32, unsigned, 32}, X, Path).
|
||||
|
||||
-compile({nowarn_unused_function,v_type_bool/3}).
|
||||
-dialyzer({nowarn_function,v_type_bool/3}).
|
||||
v_type_bool(false, _Path, _TrUserData) -> ok;
|
||||
v_type_bool(true, _Path, _TrUserData) -> ok;
|
||||
v_type_bool(0, _Path, _TrUserData) -> ok;
|
||||
v_type_bool(1, _Path, _TrUserData) -> ok;
|
||||
v_type_bool(X, Path, _TrUserData) -> mk_type_error(bad_boolean_value, X, Path).
|
||||
|
||||
-compile({nowarn_unused_function,v_type_float/3}).
|
||||
-dialyzer({nowarn_function,v_type_float/3}).
|
||||
v_type_float(N, _Path, _TrUserData) when is_float(N) -> ok;
|
||||
@ -2269,7 +2414,6 @@ get_msg_defs() ->
|
||||
#field{name = token, fnum = 5, rnum = 5, type = string, occurrence = optional, opts = []},
|
||||
#field{name = timestamp, fnum = 6, rnum = 6, type = uint32, occurrence = optional, opts = []}]},
|
||||
{{msg, auth_reply}, [#field{name = code, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []}, #field{name = message, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}]},
|
||||
{{msg, activate_push}, [#field{name = auth, fnum = 1, rnum = 2, type = bool, occurrence = optional, opts = []}]},
|
||||
{{msg, deploy},
|
||||
[#field{name = task_id, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []},
|
||||
#field{name = service_id, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []},
|
||||
@ -2278,7 +2422,12 @@ get_msg_defs() ->
|
||||
[#field{name = code, fnum = 1, rnum = 2, type = int32, occurrence = optional, opts = []},
|
||||
#field{name = result, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []},
|
||||
#field{name = message, fnum = 3, rnum = 4, type = string, occurrence = optional, opts = []}]},
|
||||
{{msg, topic_message}, [#field{name = topic, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []}, #field{name = content, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}]},
|
||||
{{msg, pub}, [#field{name = topic, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []}, #field{name = content, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}]},
|
||||
{{msg, async_request}, [#field{name = method, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []}, #field{name = params, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}]},
|
||||
{{msg, async_response},
|
||||
[#field{name = code, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []},
|
||||
#field{name = result, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []},
|
||||
#field{name = message, fnum = 3, rnum = 4, type = string, occurrence = optional, opts = []}]},
|
||||
{{msg, service_config},
|
||||
[#field{name = service_id, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []},
|
||||
#field{name = config_json, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []},
|
||||
@ -2316,13 +2465,13 @@ get_msg_defs() ->
|
||||
#field{name = params, fnum = 3, rnum = 4, type = string, occurrence = optional, opts = []}]}].
|
||||
|
||||
|
||||
get_msg_names() -> [auth_request, auth_reply, activate_push, deploy, efka_response, topic_message, service_config, data, ping, service_inform, feedback_phase, event].
|
||||
get_msg_names() -> [auth_request, auth_reply, deploy, efka_response, pub, async_request, async_response, service_config, data, ping, service_inform, feedback_phase, event].
|
||||
|
||||
|
||||
get_group_names() -> [].
|
||||
|
||||
|
||||
get_msg_or_group_names() -> [auth_request, auth_reply, activate_push, deploy, efka_response, topic_message, service_config, data, ping, service_inform, feedback_phase, event].
|
||||
get_msg_or_group_names() -> [auth_request, auth_reply, deploy, efka_response, pub, async_request, async_response, service_config, data, ping, service_inform, feedback_phase, event].
|
||||
|
||||
|
||||
get_enum_names() -> [].
|
||||
@ -2346,7 +2495,6 @@ find_msg_def(auth_request) ->
|
||||
#field{name = token, fnum = 5, rnum = 5, type = string, occurrence = optional, opts = []},
|
||||
#field{name = timestamp, fnum = 6, rnum = 6, type = uint32, occurrence = optional, opts = []}];
|
||||
find_msg_def(auth_reply) -> [#field{name = code, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []}, #field{name = message, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}];
|
||||
find_msg_def(activate_push) -> [#field{name = auth, fnum = 1, rnum = 2, type = bool, occurrence = optional, opts = []}];
|
||||
find_msg_def(deploy) ->
|
||||
[#field{name = task_id, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []},
|
||||
#field{name = service_id, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []},
|
||||
@ -2355,7 +2503,12 @@ find_msg_def(efka_response) ->
|
||||
[#field{name = code, fnum = 1, rnum = 2, type = int32, occurrence = optional, opts = []},
|
||||
#field{name = result, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []},
|
||||
#field{name = message, fnum = 3, rnum = 4, type = string, occurrence = optional, opts = []}];
|
||||
find_msg_def(topic_message) -> [#field{name = topic, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []}, #field{name = content, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}];
|
||||
find_msg_def(pub) -> [#field{name = topic, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []}, #field{name = content, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}];
|
||||
find_msg_def(async_request) -> [#field{name = method, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []}, #field{name = params, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}];
|
||||
find_msg_def(async_response) ->
|
||||
[#field{name = code, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []},
|
||||
#field{name = result, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []},
|
||||
#field{name = message, fnum = 3, rnum = 4, type = string, occurrence = optional, opts = []}];
|
||||
find_msg_def(service_config) ->
|
||||
[#field{name = service_id, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []},
|
||||
#field{name = config_json, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []},
|
||||
@ -2451,10 +2604,11 @@ service_and_rpc_name_to_fqbins(S, R) -> error({gpb_error, {badservice_or_rpc, {S
|
||||
|
||||
fqbin_to_msg_name(<<"AuthRequest">>) -> auth_request;
|
||||
fqbin_to_msg_name(<<"AuthReply">>) -> auth_reply;
|
||||
fqbin_to_msg_name(<<"ActivatePush">>) -> activate_push;
|
||||
fqbin_to_msg_name(<<"Deploy">>) -> deploy;
|
||||
fqbin_to_msg_name(<<"EfkaResponse">>) -> efka_response;
|
||||
fqbin_to_msg_name(<<"TopicMessage">>) -> topic_message;
|
||||
fqbin_to_msg_name(<<"Pub">>) -> pub;
|
||||
fqbin_to_msg_name(<<"AsyncRequest">>) -> async_request;
|
||||
fqbin_to_msg_name(<<"AsyncResponse">>) -> async_response;
|
||||
fqbin_to_msg_name(<<"ServiceConfig">>) -> service_config;
|
||||
fqbin_to_msg_name(<<"Data">>) -> data;
|
||||
fqbin_to_msg_name(<<"Ping">>) -> ping;
|
||||
@ -2466,10 +2620,11 @@ fqbin_to_msg_name(E) -> error({gpb_error, {badmsg, E}}).
|
||||
|
||||
msg_name_to_fqbin(auth_request) -> <<"AuthRequest">>;
|
||||
msg_name_to_fqbin(auth_reply) -> <<"AuthReply">>;
|
||||
msg_name_to_fqbin(activate_push) -> <<"ActivatePush">>;
|
||||
msg_name_to_fqbin(deploy) -> <<"Deploy">>;
|
||||
msg_name_to_fqbin(efka_response) -> <<"EfkaResponse">>;
|
||||
msg_name_to_fqbin(topic_message) -> <<"TopicMessage">>;
|
||||
msg_name_to_fqbin(pub) -> <<"Pub">>;
|
||||
msg_name_to_fqbin(async_request) -> <<"AsyncRequest">>;
|
||||
msg_name_to_fqbin(async_response) -> <<"AsyncResponse">>;
|
||||
msg_name_to_fqbin(service_config) -> <<"ServiceConfig">>;
|
||||
msg_name_to_fqbin(data) -> <<"Data">>;
|
||||
msg_name_to_fqbin(ping) -> <<"Ping">>;
|
||||
@ -2514,7 +2669,7 @@ get_all_source_basenames() -> ["message_pb.proto"].
|
||||
get_all_proto_names() -> ["message_pb"].
|
||||
|
||||
|
||||
get_msg_containment("message_pb") -> [activate_push, auth_reply, auth_request, data, deploy, efka_response, event, feedback_phase, ping, service_config, service_inform, topic_message];
|
||||
get_msg_containment("message_pb") -> [async_request, async_response, auth_reply, auth_request, data, deploy, efka_response, event, feedback_phase, ping, pub, service_config, service_inform];
|
||||
get_msg_containment(P) -> error({gpb_error, {badproto, P}}).
|
||||
|
||||
|
||||
@ -2535,14 +2690,15 @@ get_enum_containment(P) -> error({gpb_error, {badproto, P}}).
|
||||
|
||||
|
||||
get_proto_by_msg_name_as_fqbin(<<"Data">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"Pub">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"Event">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"AuthRequest">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"TopicMessage">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"AsyncRequest">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"FeedbackPhase">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"EfkaResponse">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"AsyncResponse">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"ServiceConfig">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"Ping">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"ActivatePush">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"Deploy">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"AuthReply">>) -> "message_pb";
|
||||
get_proto_by_msg_name_as_fqbin(<<"ServiceInform">>) -> "message_pb";
|
||||
|
||||
@ -12,7 +12,8 @@
|
||||
-include("message_pb.hrl").
|
||||
|
||||
%% API
|
||||
-export([publish/3, stop/2, send/2]).
|
||||
-export([stop/2, send/2]).
|
||||
-export([pub/3, async_request/4, command/3]).
|
||||
|
||||
-export([start_link/2]).
|
||||
%% gen_server callbacks
|
||||
@ -33,16 +34,21 @@
|
||||
}).
|
||||
|
||||
%% 向通道中写入消息
|
||||
-spec publish(Pid :: pid(), ReceiverPid :: pid(), Msg :: binary()) -> Ref :: reference().
|
||||
publish(Pid, ReceiverPid, Msg) when is_pid(Pid), is_binary(Msg) ->
|
||||
Ref = make_ref(),
|
||||
gen_server:cast(Pid, {publish, ReceiverPid, Ref, Msg}),
|
||||
Ref.
|
||||
-spec pub(Pid :: pid(), Topic :: binary(), Content :: binary()) -> no_return().
|
||||
pub(Pid, Topic, Content) when is_pid(Pid), is_binary(Topic), is_binary(Content) ->
|
||||
gen_server:cast(Pid, {pub, Topic, Content}).
|
||||
|
||||
%% 向通道中写入消息
|
||||
-spec send(Pid :: pid(), Msg :: binary()) -> no_return().
|
||||
send(Pid, Msg) when is_pid(Pid), is_binary(Msg) ->
|
||||
gen_server:cast(Pid, {send, Msg}).
|
||||
-spec command(Pid :: pid(), CommandType :: integer(), Command :: binary()) -> no_return().
|
||||
command(Pid, CommandType, Command) when is_pid(Pid), is_integer(CommandType), is_binary(Command) ->
|
||||
gen_server:cast(Pid, {command, CommandType, Command}).
|
||||
|
||||
%% 向通道中写入消息
|
||||
-spec async_request(Pid :: pid(), ReceiverPid :: pid(), Method :: binary(), Params :: binary()) -> Ref :: reference().
|
||||
async_request(Pid, ReceiverPid, Method, Params) when is_pid(Pid), is_binary(Method), is_binary(Params) ->
|
||||
Ref = make_ref(),
|
||||
gen_server:cast(Pid, {async_request, ReceiverPid, Ref, Method, Params}),
|
||||
Ref.
|
||||
|
||||
%% 关闭方法
|
||||
-spec stop(Pid :: pid(), Reason :: any()) -> no_return().
|
||||
@ -72,16 +78,23 @@ init([Transport, Sock]) ->
|
||||
handle_call(_Request, _From, State) ->
|
||||
{reply, ok, State}.
|
||||
|
||||
%% 发送消息
|
||||
handle_cast({publish, ReceiverPid, Ref, Msg}, State = #state{transport = Transport, socket = Socket, packet_id = PacketId, inflight = Inflight}) when is_binary(Msg) ->
|
||||
NInflight = maps:put(PacketId, {ReceiverPid, Ref}, Inflight),
|
||||
Transport:send(Socket, <<?PACKET_PUBLISH, PacketId:32, Msg/binary>>),
|
||||
{noreply, State#state{packet_id = PacketId + 1, inflight = NInflight}};
|
||||
%% 发送消息, 基于pub/sub机制
|
||||
handle_cast({pub, Topic, Content}, State = #state{transport = Transport, socket = Socket}) ->
|
||||
PubBin = message_pb:encode_msg(#pub{topic = Topic, content = Content}),
|
||||
Transport:send(Socket, <<?PACKET_PUB, 0:32, PubBin/binary>>),
|
||||
{noreply, State};
|
||||
|
||||
%% 发送消息, 不需要等待回复
|
||||
handle_cast({send, Msg}, State = #state{transport = Transport, socket = Socket}) when is_binary(Msg) ->
|
||||
Transport:send(Socket, <<?PACKET_PUBLISH, 0:32, Msg/binary>>),
|
||||
{noreply, State}.
|
||||
%% 发送Command消息
|
||||
handle_cast({command, CommandType, Command}, State = #state{transport = Transport, socket = Socket}) ->
|
||||
Transport:send(Socket, <<?PACKET_COMMAND, 0:32, CommandType:8, Command/binary>>),
|
||||
{noreply, State};
|
||||
|
||||
handle_cast({async_request, ReceiverPid, Ref, Method, Params},
|
||||
State = #state{transport = Transport, socket = Socket, packet_id = PacketId, inflight = Inflight}) ->
|
||||
RequestBin = message_pb:encode_msg(#async_request{method = Method, params = Params}),
|
||||
Transport:send(Socket, <<?PACKET_ASYNC_REQUEST, PacketId:32, RequestBin/binary>>),
|
||||
|
||||
{noreply, State#state{packet_id = PacketId + 1, inflight = maps:put(PacketId, {ReceiverPid, Ref}, Inflight)}}.
|
||||
|
||||
%% auth验证
|
||||
handle_info({tcp, Socket, <<?PACKET_REQUEST, PacketId:32, ?METHOD_AUTH:8, AuthRequestBin/binary>>}, State = #state{transport = Transport, socket = Socket}) ->
|
||||
@ -151,18 +164,19 @@ handle_info({tcp, Socket, <<?PACKET_REQUEST, 0:32, ?METHOD_EVENT:8, EventData/bi
|
||||
{noreply, State};
|
||||
|
||||
%% 主机端的消息响应
|
||||
handle_info({tcp, Socket, <<?PACKET_PUBLISH_RESPONSE, PacketId:32, Body/binary>>}, State = #state{socket = Socket, uuid = UUID, inflight = Inflight}) when PacketId > 0 ->
|
||||
lager:debug("[ws_channel] uuid: ~p, get publish response message: ~p, packet_id: ~p", [UUID, Body, PacketId]),
|
||||
handle_info({tcp, Socket, <<?PACKET_ASYNC_RESPONSE, PacketId:32, ResponseBin/binary>>}, State = #state{socket = Socket, uuid = UUID, inflight = Inflight}) when PacketId > 0 ->
|
||||
AsyncResponse = message_pb:decode_msg(ResponseBin, async_response),
|
||||
lager:debug("[ws_channel] uuid: ~p, get async_response message: ~p, packet_id: ~p", [UUID, AsyncResponse, PacketId]),
|
||||
case maps:take(PacketId, Inflight) of
|
||||
error ->
|
||||
lager:warning("[ws_channel] get unknown publish response message: ~p, packet_id: ~p", [Body, PacketId]),
|
||||
lager:warning("[ws_channel] get unknown async_response message: ~p, packet_id: ~p", [AsyncResponse, PacketId]),
|
||||
{noreply, State};
|
||||
{{ReceiverPid, Ref}, NInflight} ->
|
||||
case is_pid(ReceiverPid) andalso is_process_alive(ReceiverPid) of
|
||||
true ->
|
||||
ReceiverPid ! {ws_response, Ref, Body};
|
||||
ReceiverPid ! {async_response, Ref, AsyncResponse};
|
||||
false ->
|
||||
lager:warning("[ws_channel] get publish response message: ~p, packet_id: ~p, but receiver_pid is deaded", [Body, PacketId])
|
||||
lager:warning("[ws_channel] get async_response message: ~p, packet_id: ~p, but receiver_pid is deaded", [AsyncResponse, PacketId])
|
||||
end,
|
||||
{noreply, State#state{inflight = NInflight}}
|
||||
end;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user