From e9c7d64e79eaca7246861e5bcd207c45293fe7ac Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Sat, 18 Apr 2026 16:44:59 +0800 Subject: [PATCH] fix --- include/message_pb.hrl | 80 ++ rebar.config | 9 +- src/codec/message_codec.erl | 141 --- src/host/iot_host.erl | 58 +- src/protobuf/message_pb.erl | 1531 +++++++++++++++++++++++++++++ src/transport/tcp/tcp_channel.erl | 71 +- 6 files changed, 1698 insertions(+), 192 deletions(-) create mode 100644 include/message_pb.hrl delete mode 100644 src/codec/message_codec.erl create mode 100644 src/protobuf/message_pb.erl diff --git a/include/message_pb.hrl b/include/message_pb.hrl new file mode 100644 index 0000000..798f14c --- /dev/null +++ b/include/message_pb.hrl @@ -0,0 +1,80 @@ +%% -*- coding: utf-8 -*- +%% Automatically generated, do not edit +%% Generated by gpb_compile version 4.21.7 + +-ifndef(message_pb). +-define(message_pb, true). + +-define(message_pb_gpb_version, "4.21.7"). + + +-ifndef('AUTHREQUEST_PB_H'). +-define('AUTHREQUEST_PB_H', true). +-record('AuthRequest', + {uuid = <<>> :: iodata() | undefined, % = 1, optional + username = <<>> :: iodata() | undefined, % = 2, optional + salt = <<>> :: iodata() | undefined, % = 3, optional + token = <<>> :: iodata() | undefined, % = 4, optional + timestamp = 0 :: integer() | undefined % = 5, optional, 32 bits + }). +-endif. + +-ifndef('AUTHREPLY_PB_H'). +-define('AUTHREPLY_PB_H', true). +-record('AuthReply', + {code = 0 :: integer() | undefined, % = 1, optional, 32 bits + payload = <<>> :: iodata() | undefined % = 2, optional + }). +-endif. + +-ifndef('PUB_PB_H'). +-define('PUB_PB_H', true). +-record('Pub', + {topic = <<>> :: iodata() | undefined, % = 1, optional + qos = 0 :: integer() | undefined, % = 2, optional, 32 bits + content = <<>> :: iodata() | undefined % = 3, optional + }). +-endif. + +-ifndef('COMMAND_PB_H'). +-define('COMMAND_PB_H', true). +-record('Command', + {command_type = 0 :: integer() | undefined, % = 1, optional, 32 bits + command = <<>> :: iodata() | undefined % = 2, optional + }). +-endif. + +-ifndef('JSONRPCREQUEST_PB_H'). +-define('JSONRPCREQUEST_PB_H', true). +-record('JsonRpcRequest', + {method = <<>> :: iodata() | undefined, % = 1, optional + params = <<>> :: iodata() | undefined % = 2, optional + }). +-endif. + +-ifndef('JSONRPCREPLY_PB_H'). +-define('JSONRPCREPLY_PB_H', true). +-record('JsonRpcReply', + {result = <<>> :: iodata() | undefined, % = 1, optional + error = <<>> :: iodata() | undefined % = 2, optional + }). +-endif. + +-ifndef('DATA_PB_H'). +-define('DATA_PB_H', true). +-record('Data', + {route_key = <<>> :: iodata() | undefined, % = 1, optional + metric = <<>> :: iodata() | undefined % = 2, optional + }). +-endif. + +-ifndef('TASKEVENTSTREAM_PB_H'). +-define('TASKEVENTSTREAM_PB_H', true). +-record('TaskEventStream', + {task_id = 0 :: integer() | undefined, % = 1, optional, 32 bits + type = <<>> :: iodata() | undefined, % = 2, optional + stream = <<>> :: iodata() | undefined % = 3, optional + }). +-endif. + +-endif. diff --git a/rebar.config b/rebar.config index 9b0f5e1..73be5ab 100644 --- a/rebar.config +++ b/rebar.config @@ -12,7 +12,7 @@ {src_dirs, ["proto"]}, % 源码目录(必须) recursive, % 递归查找 proto 文件 {module_name_suffix, "_pb"}, % 生成模块后缀 - {o_erl, "src"}, % .erl 输出目录 + {o_erl, "src/protobuf"}, % .erl 输出目录 {o_hrl, "include"}, % .hrl 输出目录 include_as_lib, % gpb.hrl 通过 -include_lib("gpb/include/gpb.hrl") {strings_as_binaries, true}, % proto string → Erlang binary @@ -21,6 +21,13 @@ verbose % 打印详细信息 ]}. +{provider_hooks, [ + {pre, [ + {compile, {protobuf, compile}}, + {clean, {protobuf, clean}} + ]} +]}. + {deps, [ {poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}}, {hackney, ".*", {git, "https://github.com/benoitc/hackney.git", {tag, "1.25.0"}}}, diff --git a/src/codec/message_codec.erl b/src/codec/message_codec.erl deleted file mode 100644 index 769c11e..0000000 --- a/src/codec/message_codec.erl +++ /dev/null @@ -1,141 +0,0 @@ -%%%------------------------------------------------------------------- -%%% @author anlicheng -%%% @copyright (C) 2025, -%%% @doc -%%% -%%% @end -%%% Created : 17. 9月 2025 16:05 -%%%------------------------------------------------------------------- --module(message_codec). --author("anlicheng"). --include("message.hrl"). - --define(I8, 1). --define(I16, 2). --define(I32, 3). --define(Bytes, 4). - -%% API --export([encode/2, decode/1]). - --spec encode(MessageType :: integer(), Message :: any()) -> binary(). -encode(MessageType, Message) when is_integer(MessageType) -> - Bin = encode0(Message), - <>. -encode0(#auth_request{uuid = UUID, username = Username, salt = Salt, token = Token, timestamp = Timestamp}) -> - iolist_to_binary([ - marshal(?Bytes, UUID), - marshal(?Bytes, Username), - marshal(?Bytes, Salt), - marshal(?Bytes, Token), - marshal(?I32, Timestamp) - ]); -encode0(#auth_reply{code = Code, payload = Payload}) -> - iolist_to_binary([ - marshal(?I32, Code), - marshal(?Bytes, Payload) - ]); -encode0(#jsonrpc_reply{result = Result, error = undefined}) -> - ResultBin = erlang:term_to_binary(#{<<"result">> => Result}), - iolist_to_binary([ - marshal(?Bytes, ResultBin) - ]); -encode0(#jsonrpc_reply{result = undefined, error = Error}) -> - ResultBin = erlang:term_to_binary(#{<<"error">> => Error}), - iolist_to_binary([ - marshal(?Bytes, ResultBin) - ]); -encode0(#pub{topic = Topic, qos = Qos, content = Content}) -> - iolist_to_binary([ - marshal(?Bytes, Topic), - marshal(?I8, Qos), - marshal(?Bytes, Content) - ]); -encode0(#command{command_type = CommandType, command = Command}) -> - iolist_to_binary([ - marshal(?I32, CommandType), - marshal(?Bytes, Command) - ]); - -encode0(#jsonrpc_request{method = Method, params = Params}) -> - ReqBody = erlang:term_to_binary(#{<<"method">> => Method, <<"params">> => Params}), - iolist_to_binary([ - marshal(?Bytes, ReqBody) - ]); -encode0(#data{route_key = RouteKey, metric = Metric}) -> - iolist_to_binary([ - marshal(?Bytes, RouteKey), - marshal(?Bytes, Metric) - ]); -encode0(#task_event_stream{task_id = TaskId, type = Type, stream = Stream}) -> - iolist_to_binary([ - marshal(?I32, TaskId), - marshal(?Bytes, Type), - marshal(?Bytes, Stream) - ]). - --spec decode(Bin :: binary()) -> {ok, Message :: any()} | error. -decode(<>) -> - case unmarshal(Packet) of - {ok, Fields} -> - decode0(PacketType, Fields); - error -> - error - end. -decode0(?MESSAGE_AUTH_REQUEST, [UUID, Username, Salt, Token, Timestamp]) -> - {ok, #auth_request{uuid = UUID, username = Username, salt = Salt, token = Token, timestamp = Timestamp}}; -decode0(?MESSAGE_JSONRPC_REPLY, [ReplyBin]) -> - case erlang:binary_to_term(ReplyBin) of - #{<<"result">> := Result} -> - {ok, #jsonrpc_reply{result = Result}}; - #{<<"error">> := Error} -> - {ok, #jsonrpc_reply{error = Error}}; - _ -> - error - end; -decode0(?MESSAGE_PUB, [Topic, Qos, Content]) -> - {ok, #pub{topic = Topic, qos = Qos, content = Content}}; -decode0(?MESSAGE_COMMAND, [CommandType, Command]) -> - {ok, #command{command_type = CommandType, command = Command}}; -decode0(?MESSAGE_AUTH_REPLY, [Code, Payload]) -> - {ok, #auth_reply{code = Code, payload = Payload}}; -decode0(?MESSAGE_JSONRPC_REQUEST, [ReqBody]) -> - #{<<"method">> := Method, <<"params">> := Params} = erlang:binary_to_term(ReqBody), - {ok, #jsonrpc_request{method = Method, params = Params}}; -decode0(?MESSAGE_DATA, [RouteKey, Metric]) -> - {ok, #data{route_key = RouteKey, metric = Metric}}; -decode0(?MESSAGE_EVENT_STREAM, [TaskId, Type, Stream]) -> - {ok, #task_event_stream{task_id = TaskId, type = Type, stream = Stream}}; -decode0(_, _) -> - error. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% helper methods -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - --spec marshal(Type :: ?I8 | ?I16 | ?I32 | ?Bytes, Field :: integer() | binary()) -> binary(). -marshal(?I8, Field) when is_integer(Field) -> - <>; -marshal(?I16, Field) when is_integer(Field) -> - <>; -marshal(?I32, Field) when is_integer(Field) -> - <>; -marshal(?Bytes, Field) when is_binary(Field) -> - Len = byte_size(Field), - <>. - --spec unmarshal(Bin :: binary()) -> {ok, Components :: [any()]} | error. -unmarshal(Bin) when is_binary(Bin) -> - unmarshal(Bin, []). -unmarshal(<<>>, Acc) -> - {ok, lists:reverse(Acc)}; -unmarshal(<>, Acc) -> - unmarshal(Rest, [F|Acc]); -unmarshal(<>, Acc) -> - unmarshal(Rest, [F|Acc]); -unmarshal(<>, Acc) -> - unmarshal(Rest, [F|Acc]); -unmarshal(<>, Acc) -> - unmarshal(Rest, [F|Acc]); -unmarshal(_, _) -> - error. diff --git a/src/host/iot_host.erl b/src/host/iot_host.erl index 5f26c3d..d10254d 100644 --- a/src/host/iot_host.erl +++ b/src/host/iot_host.erl @@ -10,6 +10,7 @@ -author("aresei"). -include("iot.hrl"). -include("message.hrl"). +-include("message_pb.hrl"). -behaviour(gen_statem). @@ -94,52 +95,52 @@ attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) -> -spec get_containers(Pid :: pid()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. get_containers(Pid) when is_pid(Pid) -> - Request = #jsonrpc_request{method = <<"get_containers">>, params = #{}}, - EncConfigBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), - gen_statem:call(Pid, {jsonrpc_call, self(), EncConfigBin}). + Request = #'JsonRpcRequest'{method = <<"get_containers">>, params = erlang:term_to_binary(#{} )}, + gen_statem:call(Pid, {jsonrpc_call, self(), Request}). -spec config_container(Pid :: pid(), ContainerName :: binary(), ConfigJson :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. config_container(Pid, ContainerName, ConfigJson) when is_pid(Pid), is_binary(ContainerName), is_binary(ConfigJson) -> - Request = #jsonrpc_request{method = <<"config_container">>, params = #{<<"container_name">> => ContainerName, <<"config">> => ConfigJson}}, - EncConfigBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), - gen_statem:call(Pid, {jsonrpc_call, self(), EncConfigBin}). + Request = #'JsonRpcRequest'{method = <<"config_container">>, + params = erlang:term_to_binary(#{<<"container_name">> => ContainerName, <<"config">> => ConfigJson})}, + gen_statem:call(Pid, {jsonrpc_call, self(), Request}). -spec deploy_container(Pid :: pid(), TaskId :: integer(), Config :: map()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. deploy_container(Pid, TaskId, Config) when is_pid(Pid), is_integer(TaskId), is_map(Config) -> - Request = #jsonrpc_request{method = <<"deploy">>, params = #{<<"task_id">> => TaskId, <<"config">> => Config}}, - EncDeployBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), - gen_statem:call(Pid, {jsonrpc_call, self(), EncDeployBin}). + Request = #'JsonRpcRequest'{method = <<"deploy">>, + params = erlang:term_to_binary(#{<<"task_id">> => TaskId, <<"config">> => Config})}, + gen_statem:call(Pid, {jsonrpc_call, self(), Request}). -spec start_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. start_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) -> - Request = #jsonrpc_request{method = <<"start_container">>, params = #{<<"container_name">> => ContainerName}}, - EncCallBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), - gen_statem:call(Pid, {jsonrpc_call, self(), EncCallBin}). + Request = #'JsonRpcRequest'{method = <<"start_container">>, + params = erlang:term_to_binary(#{<<"container_name">> => ContainerName})}, + gen_statem:call(Pid, {jsonrpc_call, self(), Request}). -spec stop_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. stop_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) -> - Request = #jsonrpc_request{method = <<"stop_container">>, params = #{<<"container_name">> => ContainerName}}, - EncCallBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), - gen_statem:call(Pid, {jsonrpc_call, self(), EncCallBin}). + Request = #'JsonRpcRequest'{method = <<"stop_container">>, + params = erlang:term_to_binary(#{<<"container_name">> => ContainerName})}, + gen_statem:call(Pid, {jsonrpc_call, self(), Request}). -spec kill_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. kill_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) -> - Request = #jsonrpc_request{method = <<"kill_container">>, params = #{<<"container_name">> => ContainerName}}, - EncCallBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), - gen_statem:call(Pid, {jsonrpc_call, self(), EncCallBin}). + Request = #'JsonRpcRequest'{method = <<"kill_container">>, + params = erlang:term_to_binary(#{<<"container_name">> => ContainerName})}, + gen_statem:call(Pid, {jsonrpc_call, self(), Request}). -spec remove_container(Pid :: pid(), ContainerName :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. remove_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) -> - Request = #jsonrpc_request{method = <<"remove_container">>, params = #{<<"container_name">> => ContainerName}}, - EncCallBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), - gen_statem:call(Pid, {jsonrpc_call, self(), EncCallBin}). + Request = #'JsonRpcRequest'{method = <<"remove_container">>, + params = erlang:term_to_binary(#{<<"container_name">> => ContainerName})}, + gen_statem:call(Pid, {jsonrpc_call, self(), Request}). -spec await_reply(Ref :: reference(), Timeout :: integer()) -> {ok, Result :: binary()} | {error, Reason :: binary()}. await_reply(Ref, Timeout) when is_reference(Ref), is_integer(Timeout) -> receive - {jsonrpc_reply, Ref, #jsonrpc_reply{result = Result, error = undefined}} -> - {ok, Result}; - {jsonrpc_reply, Ref, #jsonrpc_reply{result = undefined, error = #{<<"message">> := Message}}} -> + {jsonrpc_reply, Ref, #'JsonRpcReply'{result = ResultBin, error = <<>>}} -> + {ok, erlang:binary_to_term(iolist_to_binary(ResultBin))}; + {jsonrpc_reply, Ref, #'JsonRpcReply'{result = <<>>, error = ErrorBin}} -> + #{<<"message">> := Message} = erlang:binary_to_term(iolist_to_binary(ErrorBin)), {error, Message} after Timeout -> {error, <<"timeout">>} @@ -302,11 +303,12 @@ handle_event({call, From}, {attach_channel, _}, _, State = #state{uuid = UUID, c {keep_state, State, [{reply, From, {error, <<"channel existed">>}}]}; %% 数据分发 -handle_event(cast, {handle, {data, #data{route_key = RouteKey0, metric = Metric}}}, ?STATE_ACTIVATED, +handle_event(cast, {handle, {data, #'Data'{route_key = RouteKey0, metric = Metric}}}, ?STATE_ACTIVATED, State = #state{uuid = UUID, has_session = true}) -> - logger:debug("[iot_host] metric_data host: ~p, route_key: ~p, metric: ~p", [UUID, RouteKey0, Metric]), - RouteKey = get_route_key(RouteKey0), - endpoint_subscription:publish(RouteKey, Metric), + RouteKey = iolist_to_binary(RouteKey0), + MetricBin = iolist_to_binary(Metric), + logger:debug("[iot_host] metric_data host: ~p, route_key: ~p, metric: ~p", [UUID, RouteKey, MetricBin]), + endpoint_subscription:publish(get_route_key(RouteKey), MetricBin), {keep_state, State}; %% ping的数据是通过aes加密后的,因此需要在有会话的情况下才行 diff --git a/src/protobuf/message_pb.erl b/src/protobuf/message_pb.erl new file mode 100644 index 0000000..e1e8aec --- /dev/null +++ b/src/protobuf/message_pb.erl @@ -0,0 +1,1531 @@ +%% -*- coding: utf-8 -*- +%% @private +%% Automatically @generated, do not edit +%% Generated by gpb_compile version 4.21.7 +%% Version source: file +-module(message_pb). + +-export([encode_msg/1, encode_msg/2, encode_msg/3]). +-export([decode_msg/2, decode_msg/3]). +-export([merge_msgs/2, merge_msgs/3, merge_msgs/4]). +-export([verify_msg/1, verify_msg/2, verify_msg/3]). +-export([get_msg_defs/0]). +-export([get_msg_names/0]). +-export([get_group_names/0]). +-export([get_msg_or_group_names/0]). +-export([get_enum_names/0]). +-export([find_msg_def/1, fetch_msg_def/1]). +-export([find_enum_def/1, fetch_enum_def/1]). +-export([enum_symbol_by_value/2, enum_value_by_symbol/2]). +-export([get_service_names/0]). +-export([get_service_def/1]). +-export([get_rpc_names/1]). +-export([find_rpc_def/2, fetch_rpc_def/2]). +-export([fqbin_to_service_name/1]). +-export([service_name_to_fqbin/1]). +-export([fqbins_to_service_and_rpc_name/2]). +-export([service_and_rpc_name_to_fqbins/2]). +-export([fqbin_to_msg_name/1]). +-export([msg_name_to_fqbin/1]). +-export([fqbin_to_enum_name/1]). +-export([enum_name_to_fqbin/1]). +-export([get_package_name/0]). +-export([uses_packages/0]). +-export([source_basename/0]). +-export([get_all_source_basenames/0]). +-export([get_all_proto_names/0]). +-export([get_msg_containment/1]). +-export([get_pkg_containment/1]). +-export([get_service_containment/1]). +-export([get_rpc_containment/1]). +-export([get_enum_containment/1]). +-export([get_proto_by_msg_name_as_fqbin/1]). +-export([get_proto_by_service_name_as_fqbin/1]). +-export([get_proto_by_enum_name_as_fqbin/1]). +-export([get_protos_by_pkg_name_as_fqbin/1]). +-export([gpb_version_as_string/0, gpb_version_as_list/0]). +-export([gpb_version_source/0]). + +-include("message_pb.hrl"). +-include_lib("gpb/include/gpb.hrl"). + +%% enumerated types + +-export_type([]). + +%% message types +-type 'AuthRequest'() :: #'AuthRequest'{}. + +-type 'AuthReply'() :: #'AuthReply'{}. + +-type 'Pub'() :: #'Pub'{}. + +-type 'Command'() :: #'Command'{}. + +-type 'JsonRpcRequest'() :: #'JsonRpcRequest'{}. + +-type 'JsonRpcReply'() :: #'JsonRpcReply'{}. + +-type 'Data'() :: #'Data'{}. + +-type 'TaskEventStream'() :: #'TaskEventStream'{}. + +-export_type(['AuthRequest'/0, 'AuthReply'/0, 'Pub'/0, 'Command'/0, 'JsonRpcRequest'/0, 'JsonRpcReply'/0, 'Data'/0, 'TaskEventStream'/0]). +-type '$msg_name'() :: 'AuthRequest' | 'AuthReply' | 'Pub' | 'Command' | 'JsonRpcRequest' | 'JsonRpcReply' | 'Data' | 'TaskEventStream'. +-type '$msg'() :: 'AuthRequest'() | 'AuthReply'() | 'Pub'() | 'Command'() | 'JsonRpcRequest'() | 'JsonRpcReply'() | 'Data'() | 'TaskEventStream'(). +-export_type(['$msg_name'/0, '$msg'/0]). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/1}). +-endif. +-spec encode_msg('$msg'()) -> binary(). +encode_msg(Msg) when tuple_size(Msg) >= 1 -> encode_msg(Msg, element(1, Msg), []). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/2}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'() | list()) -> binary(). +encode_msg(Msg, MsgName) when is_atom(MsgName) -> encode_msg(Msg, MsgName, []); +encode_msg(Msg, Opts) when tuple_size(Msg) >= 1, is_list(Opts) -> encode_msg(Msg, element(1, Msg), Opts). + +-if(?OTP_RELEASE >= 24). +-dialyzer({no_underspecs, encode_msg/3}). +-endif. +-spec encode_msg('$msg'(), '$msg_name'(), list()) -> binary(). +encode_msg(Msg, MsgName, Opts) -> + case proplists:get_bool(verify, Opts) of + true -> verify_msg(Msg, MsgName, Opts); + false -> ok + end, + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'AuthRequest' -> encode_msg_AuthRequest(id(Msg, TrUserData), TrUserData); + 'AuthReply' -> encode_msg_AuthReply(id(Msg, TrUserData), TrUserData); + 'Pub' -> encode_msg_Pub(id(Msg, TrUserData), TrUserData); + 'Command' -> encode_msg_Command(id(Msg, TrUserData), TrUserData); + 'JsonRpcRequest' -> encode_msg_JsonRpcRequest(id(Msg, TrUserData), TrUserData); + 'JsonRpcReply' -> encode_msg_JsonRpcReply(id(Msg, TrUserData), TrUserData); + 'Data' -> encode_msg_Data(id(Msg, TrUserData), TrUserData); + 'TaskEventStream' -> encode_msg_TaskEventStream(id(Msg, TrUserData), TrUserData) + end. + + +encode_msg_AuthRequest(Msg, TrUserData) -> encode_msg_AuthRequest(Msg, <<>>, TrUserData). + + +encode_msg_AuthRequest(#'AuthRequest'{uuid = F1, username = F2, salt = F3, token = F4, timestamp = F5}, Bin, TrUserData) -> + B1 = if F1 == undefined -> Bin; + true -> + begin + TrF1 = id(F1, TrUserData), + case iolist_size(TrF1) of + 0 -> Bin; + _ -> e_type_bytes(TrF1, <>, TrUserData) + end + end + end, + B2 = if F2 == undefined -> B1; + true -> + begin + TrF2 = id(F2, TrUserData), + case iolist_size(TrF2) of + 0 -> B1; + _ -> e_type_bytes(TrF2, <>, TrUserData) + end + end + end, + B3 = if F3 == undefined -> B2; + true -> + begin + TrF3 = id(F3, TrUserData), + case iolist_size(TrF3) of + 0 -> B2; + _ -> e_type_bytes(TrF3, <>, TrUserData) + end + end + end, + B4 = if F4 == undefined -> B3; + true -> + begin + TrF4 = id(F4, TrUserData), + case iolist_size(TrF4) of + 0 -> B3; + _ -> e_type_bytes(TrF4, <>, TrUserData) + end + end + end, + if F5 == undefined -> B4; + true -> + begin + TrF5 = id(F5, TrUserData), + if TrF5 =:= 0 -> B4; + true -> e_type_int32(TrF5, <>, TrUserData) + end + end + end. + +encode_msg_AuthReply(Msg, TrUserData) -> encode_msg_AuthReply(Msg, <<>>, TrUserData). + + +encode_msg_AuthReply(#'AuthReply'{code = F1, payload = F2}, Bin, TrUserData) -> + B1 = if F1 == undefined -> Bin; + true -> + begin + TrF1 = id(F1, TrUserData), + if TrF1 =:= 0 -> Bin; + true -> e_type_int32(TrF1, <>, TrUserData) + end + end + end, + if F2 == undefined -> B1; + true -> + begin + TrF2 = id(F2, TrUserData), + case iolist_size(TrF2) of + 0 -> B1; + _ -> e_type_bytes(TrF2, <>, TrUserData) + end + end + end. + +encode_msg_Pub(Msg, TrUserData) -> encode_msg_Pub(Msg, <<>>, TrUserData). + + +encode_msg_Pub(#'Pub'{topic = F1, qos = F2, content = F3}, Bin, TrUserData) -> + B1 = if F1 == undefined -> Bin; + true -> + begin + TrF1 = id(F1, TrUserData), + case iolist_size(TrF1) of + 0 -> Bin; + _ -> e_type_bytes(TrF1, <>, TrUserData) + end + end + end, + B2 = if F2 == undefined -> B1; + true -> + begin + TrF2 = id(F2, TrUserData), + if TrF2 =:= 0 -> B1; + true -> e_type_int32(TrF2, <>, TrUserData) + end + end + end, + if F3 == undefined -> B2; + true -> + begin + TrF3 = id(F3, TrUserData), + case iolist_size(TrF3) of + 0 -> B2; + _ -> e_type_bytes(TrF3, <>, TrUserData) + end + end + end. + +encode_msg_Command(Msg, TrUserData) -> encode_msg_Command(Msg, <<>>, TrUserData). + + +encode_msg_Command(#'Command'{command_type = F1, command = F2}, Bin, TrUserData) -> + B1 = if F1 == undefined -> Bin; + true -> + begin + TrF1 = id(F1, TrUserData), + if TrF1 =:= 0 -> Bin; + true -> e_type_int32(TrF1, <>, TrUserData) + end + end + end, + if F2 == undefined -> B1; + true -> + begin + TrF2 = id(F2, TrUserData), + case iolist_size(TrF2) of + 0 -> B1; + _ -> e_type_bytes(TrF2, <>, TrUserData) + end + end + end. + +encode_msg_JsonRpcRequest(Msg, TrUserData) -> encode_msg_JsonRpcRequest(Msg, <<>>, TrUserData). + + +encode_msg_JsonRpcRequest(#'JsonRpcRequest'{method = F1, params = F2}, Bin, TrUserData) -> + B1 = if F1 == undefined -> Bin; + true -> + begin + TrF1 = id(F1, TrUserData), + case iolist_size(TrF1) of + 0 -> Bin; + _ -> e_type_bytes(TrF1, <>, TrUserData) + end + end + end, + if F2 == undefined -> B1; + true -> + begin + TrF2 = id(F2, TrUserData), + case iolist_size(TrF2) of + 0 -> B1; + _ -> e_type_bytes(TrF2, <>, TrUserData) + end + end + end. + +encode_msg_JsonRpcReply(Msg, TrUserData) -> encode_msg_JsonRpcReply(Msg, <<>>, TrUserData). + + +encode_msg_JsonRpcReply(#'JsonRpcReply'{result = F1, error = F2}, Bin, TrUserData) -> + B1 = if F1 == undefined -> Bin; + true -> + begin + TrF1 = id(F1, TrUserData), + case iolist_size(TrF1) of + 0 -> Bin; + _ -> e_type_bytes(TrF1, <>, TrUserData) + end + end + end, + if F2 == undefined -> B1; + true -> + begin + TrF2 = id(F2, TrUserData), + case iolist_size(TrF2) of + 0 -> B1; + _ -> e_type_bytes(TrF2, <>, TrUserData) + end + end + end. + +encode_msg_Data(Msg, TrUserData) -> encode_msg_Data(Msg, <<>>, TrUserData). + + +encode_msg_Data(#'Data'{route_key = F1, metric = F2}, Bin, TrUserData) -> + B1 = if F1 == undefined -> Bin; + true -> + begin + TrF1 = id(F1, TrUserData), + case iolist_size(TrF1) of + 0 -> Bin; + _ -> e_type_bytes(TrF1, <>, TrUserData) + end + end + end, + if F2 == undefined -> B1; + true -> + begin + TrF2 = id(F2, TrUserData), + case iolist_size(TrF2) of + 0 -> B1; + _ -> e_type_bytes(TrF2, <>, TrUserData) + end + end + end. + +encode_msg_TaskEventStream(Msg, TrUserData) -> encode_msg_TaskEventStream(Msg, <<>>, TrUserData). + + +encode_msg_TaskEventStream(#'TaskEventStream'{task_id = F1, type = F2, stream = F3}, Bin, TrUserData) -> + B1 = if F1 == undefined -> Bin; + true -> + begin + TrF1 = id(F1, TrUserData), + if TrF1 =:= 0 -> Bin; + true -> e_type_int32(TrF1, <>, TrUserData) + end + end + end, + B2 = if F2 == undefined -> B1; + true -> + begin + TrF2 = id(F2, TrUserData), + case iolist_size(TrF2) of + 0 -> B1; + _ -> e_type_bytes(TrF2, <>, TrUserData) + end + end + end, + if F3 == undefined -> B2; + true -> + begin + TrF3 = id(F3, TrUserData), + case iolist_size(TrF3) of + 0 -> B2; + _ -> e_type_bytes(TrF3, <>, TrUserData) + end + end + end. + +-compile({nowarn_unused_function,e_type_sint/3}). +e_type_sint(Value, Bin, _TrUserData) when Value >= 0 -> e_varint(Value * 2, Bin); +e_type_sint(Value, Bin, _TrUserData) -> e_varint(Value * -2 - 1, Bin). + +-compile({nowarn_unused_function,e_type_int32/3}). +e_type_int32(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int32(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_int64/3}). +e_type_int64(Value, Bin, _TrUserData) when 0 =< Value, Value =< 127 -> <>; +e_type_int64(Value, Bin, _TrUserData) -> + <> = <>, + e_varint(N, Bin). + +-compile({nowarn_unused_function,e_type_bool/3}). +e_type_bool(true, Bin, _TrUserData) -> <>; +e_type_bool(false, Bin, _TrUserData) -> <>; +e_type_bool(1, Bin, _TrUserData) -> <>; +e_type_bool(0, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_string/3}). +e_type_string(S, Bin, _TrUserData) -> + Utf8 = unicode:characters_to_binary(S), + Bin2 = e_varint(byte_size(Utf8), Bin), + <>. + +-compile({nowarn_unused_function,e_type_bytes/3}). +e_type_bytes(Bytes, Bin, _TrUserData) when is_binary(Bytes) -> + Bin2 = e_varint(byte_size(Bytes), Bin), + <>; +e_type_bytes(Bytes, Bin, _TrUserData) when is_list(Bytes) -> + BytesBin = iolist_to_binary(Bytes), + Bin2 = e_varint(byte_size(BytesBin), Bin), + <>. + +-compile({nowarn_unused_function,e_type_fixed32/3}). +e_type_fixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed32/3}). +e_type_sfixed32(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_fixed64/3}). +e_type_fixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_sfixed64/3}). +e_type_sfixed64(Value, Bin, _TrUserData) -> <>. + +-compile({nowarn_unused_function,e_type_float/3}). +e_type_float(V, Bin, _) when is_number(V) -> <>; +e_type_float(infinity, Bin, _) -> <>; +e_type_float('-infinity', Bin, _) -> <>; +e_type_float(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_type_double/3}). +e_type_double(V, Bin, _) when is_number(V) -> <>; +e_type_double(infinity, Bin, _) -> <>; +e_type_double('-infinity', Bin, _) -> <>; +e_type_double(nan, Bin, _) -> <>. + +-compile({nowarn_unused_function,e_unknown_elems/2}). +e_unknown_elems([Elem | Rest], Bin) -> + BinR = case Elem of + {varint, FNum, N} -> + BinF = e_varint(FNum bsl 3, Bin), + e_varint(N, BinF); + {length_delimited, FNum, Data} -> + BinF = e_varint(FNum bsl 3 bor 2, Bin), + BinL = e_varint(byte_size(Data), BinF), + <>; + {group, FNum, GroupFields} -> + Bin1 = e_varint(FNum bsl 3 bor 3, Bin), + Bin2 = e_unknown_elems(GroupFields, Bin1), + e_varint(FNum bsl 3 bor 4, Bin2); + {fixed32, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 5, Bin), + <>; + {fixed64, FNum, V} -> + BinF = e_varint(FNum bsl 3 bor 1, Bin), + <> + end, + e_unknown_elems(Rest, BinR); +e_unknown_elems([], Bin) -> Bin. + +-compile({nowarn_unused_function,e_varint/3}). +e_varint(N, Bin, _TrUserData) -> e_varint(N, Bin). + +-compile({nowarn_unused_function,e_varint/2}). +e_varint(N, Bin) when N =< 127 -> <>; +e_varint(N, Bin) -> + Bin2 = <>, + e_varint(N bsr 7, Bin2). + + +decode_msg(Bin, MsgName) when is_binary(Bin) -> decode_msg(Bin, MsgName, []). + +decode_msg(Bin, MsgName, Opts) when is_binary(Bin) -> + TrUserData = proplists:get_value(user_data, Opts), + decode_msg_1_catch(Bin, MsgName, TrUserData). + +-ifdef('OTP_RELEASE'). +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason:StackTrace -> + erlang:raise(error, Reason, StackTrace); + Class:Reason:StackTrace -> error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-else. +decode_msg_1_catch(Bin, MsgName, TrUserData) -> + try decode_msg_2_doit(MsgName, Bin, TrUserData) + catch + error:{gpb_error,_}=Reason -> + erlang:raise(error, Reason, + erlang:get_stacktrace()); + Class:Reason -> + StackTrace = erlang:get_stacktrace(), + error({gpb_error,{decoding_failure, {Bin, MsgName, {Class, Reason, StackTrace}}}}) + end. +-endif. + +decode_msg_2_doit('AuthRequest', Bin, TrUserData) -> id(decode_msg_AuthRequest(Bin, TrUserData), TrUserData); +decode_msg_2_doit('AuthReply', Bin, TrUserData) -> id(decode_msg_AuthReply(Bin, TrUserData), TrUserData); +decode_msg_2_doit('Pub', Bin, TrUserData) -> id(decode_msg_Pub(Bin, TrUserData), TrUserData); +decode_msg_2_doit('Command', Bin, TrUserData) -> id(decode_msg_Command(Bin, TrUserData), TrUserData); +decode_msg_2_doit('JsonRpcRequest', Bin, TrUserData) -> id(decode_msg_JsonRpcRequest(Bin, TrUserData), TrUserData); +decode_msg_2_doit('JsonRpcReply', Bin, TrUserData) -> id(decode_msg_JsonRpcReply(Bin, TrUserData), TrUserData); +decode_msg_2_doit('Data', Bin, TrUserData) -> id(decode_msg_Data(Bin, TrUserData), TrUserData); +decode_msg_2_doit('TaskEventStream', Bin, TrUserData) -> id(decode_msg_TaskEventStream(Bin, TrUserData), TrUserData). + + + +decode_msg_AuthRequest(Bin, TrUserData) -> dfp_read_field_def_AuthRequest(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), id(<<>>, TrUserData), id(<<>>, TrUserData), id(0, TrUserData), TrUserData). + +dfp_read_field_def_AuthRequest(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_AuthRequest_uuid(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_AuthRequest(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_AuthRequest_username(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_AuthRequest(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_AuthRequest_salt(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_AuthRequest(<<34, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_AuthRequest_token(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_AuthRequest(<<40, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> d_field_AuthRequest_timestamp(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dfp_read_field_def_AuthRequest(<<>>, 0, 0, _, F@_1, F@_2, F@_3, F@_4, F@_5, _) -> #'AuthRequest'{uuid = F@_1, username = F@_2, salt = F@_3, token = F@_4, timestamp = F@_5}; +dfp_read_field_def_AuthRequest(Other, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dg_read_field_def_AuthRequest(Other, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +dg_read_field_def_AuthRequest(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 32 - 7 -> dg_read_field_def_AuthRequest(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +dg_read_field_def_AuthRequest(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_AuthRequest_uuid(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 18 -> d_field_AuthRequest_username(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 26 -> d_field_AuthRequest_salt(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 34 -> d_field_AuthRequest_token(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 40 -> d_field_AuthRequest_timestamp(Rest, 0, 0, 0, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_AuthRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 1 -> skip_64_AuthRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 2 -> skip_length_delimited_AuthRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 3 -> skip_group_AuthRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); + 5 -> skip_32_AuthRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) + end + end; +dg_read_field_def_AuthRequest(<<>>, 0, 0, _, F@_1, F@_2, F@_3, F@_4, F@_5, _) -> #'AuthRequest'{uuid = F@_1, username = F@_2, salt = F@_3, token = F@_4, timestamp = F@_5}. + +d_field_AuthRequest_uuid(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_AuthRequest_uuid(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_AuthRequest_uuid(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_AuthRequest(RestF, 0, 0, F, NewFValue, F@_2, F@_3, F@_4, F@_5, TrUserData). + +d_field_AuthRequest_username(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_AuthRequest_username(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_AuthRequest_username(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_AuthRequest(RestF, 0, 0, F, F@_1, NewFValue, F@_3, F@_4, F@_5, TrUserData). + +d_field_AuthRequest_salt(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_AuthRequest_salt(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_AuthRequest_salt(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, F@_4, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_AuthRequest(RestF, 0, 0, F, F@_1, F@_2, NewFValue, F@_4, F@_5, TrUserData). + +d_field_AuthRequest_token(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_AuthRequest_token(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_AuthRequest_token(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, _, F@_5, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_AuthRequest(RestF, 0, 0, F, F@_1, F@_2, F@_3, NewFValue, F@_5, TrUserData). + +d_field_AuthRequest_timestamp(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> d_field_AuthRequest_timestamp(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +d_field_AuthRequest_timestamp(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, _, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end, Rest}, + dfp_read_field_def_AuthRequest(RestF, 0, 0, F, F@_1, F@_2, F@_3, F@_4, NewFValue, TrUserData). + +skip_varint_AuthRequest(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> skip_varint_AuthRequest(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +skip_varint_AuthRequest(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_AuthRequest(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_length_delimited_AuthRequest(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) when N < 57 -> skip_length_delimited_AuthRequest(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData); +skip_length_delimited_AuthRequest(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + Length = X bsl N + Acc, + <<_:Length/binary, Rest2/binary>> = Rest, + dfp_read_field_def_AuthRequest(Rest2, 0, 0, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_group_AuthRequest(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_AuthRequest(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_32_AuthRequest(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_AuthRequest(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +skip_64_AuthRequest(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData) -> dfp_read_field_def_AuthRequest(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, F@_4, F@_5, TrUserData). + +decode_msg_AuthReply(Bin, TrUserData) -> dfp_read_field_def_AuthReply(Bin, 0, 0, 0, id(0, TrUserData), id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_AuthReply(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_AuthReply_code(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_AuthReply(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_AuthReply_payload(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_AuthReply(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'AuthReply'{code = F@_1, payload = F@_2}; +dfp_read_field_def_AuthReply(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_AuthReply(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_AuthReply(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_AuthReply(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_AuthReply(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 8 -> d_field_AuthReply_code(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 18 -> d_field_AuthReply_payload(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_AuthReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_AuthReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_AuthReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_AuthReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_AuthReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_AuthReply(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'AuthReply'{code = F@_1, payload = F@_2}. + +d_field_AuthReply_code(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_AuthReply_code(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_AuthReply_code(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end, Rest}, + dfp_read_field_def_AuthReply(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_AuthReply_payload(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_AuthReply_payload(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_AuthReply_payload(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_AuthReply(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_AuthReply(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_AuthReply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_AuthReply(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_AuthReply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_AuthReply(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_AuthReply(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_AuthReply(<<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_AuthReply(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_AuthReply(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_AuthReply(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_AuthReply(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_AuthReply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_AuthReply(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_AuthReply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +decode_msg_Pub(Bin, TrUserData) -> dfp_read_field_def_Pub(Bin, 0, 0, 0, id(<<>>, TrUserData), id(0, TrUserData), id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_Pub(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Pub_topic(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Pub(<<16, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Pub_qos(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Pub(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_Pub_content(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_Pub(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #'Pub'{topic = F@_1, qos = F@_2, content = F@_3}; +dfp_read_field_def_Pub(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dg_read_field_def_Pub(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +dg_read_field_def_Pub(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 32 - 7 -> dg_read_field_def_Pub(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +dg_read_field_def_Pub(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_Pub_topic(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 16 -> d_field_Pub_qos(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 26 -> d_field_Pub_content(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 1 -> skip_64_Pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 2 -> skip_length_delimited_Pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 3 -> skip_group_Pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 5 -> skip_32_Pub(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData) + end + end; +dg_read_field_def_Pub(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #'Pub'{topic = F@_1, qos = F@_2, content = F@_3}. + +d_field_Pub_topic(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Pub_topic(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Pub_topic(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Pub(RestF, 0, 0, F, NewFValue, F@_2, F@_3, TrUserData). + +d_field_Pub_qos(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Pub_qos(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Pub_qos(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end, Rest}, + dfp_read_field_def_Pub(RestF, 0, 0, F, F@_1, NewFValue, F@_3, TrUserData). + +d_field_Pub_content(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_Pub_content(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_Pub_content(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Pub(RestF, 0, 0, F, F@_1, F@_2, NewFValue, TrUserData). + +skip_varint_Pub(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> skip_varint_Pub(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +skip_varint_Pub(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Pub(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_length_delimited_Pub(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> skip_length_delimited_Pub(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +skip_length_delimited_Pub(<<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_Pub(Rest2, 0, 0, F, F@_1, F@_2, F@_3, TrUserData). + +skip_group_Pub(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Pub(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, TrUserData). + +skip_32_Pub(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Pub(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_64_Pub(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_Pub(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +decode_msg_Command(Bin, TrUserData) -> dfp_read_field_def_Command(Bin, 0, 0, 0, id(0, TrUserData), id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_Command(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_Command_command_type(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_Command(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_Command_command(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_Command(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'Command'{command_type = F@_1, command = F@_2}; +dfp_read_field_def_Command(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_Command(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_Command(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_Command(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_Command(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 8 -> d_field_Command_command_type(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 18 -> d_field_Command_command(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Command(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_Command(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_Command(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_Command(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_Command(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_Command(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'Command'{command_type = F@_1, command = F@_2}. + +d_field_Command_command_type(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_Command_command_type(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_Command_command_type(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end, Rest}, + dfp_read_field_def_Command(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_Command_command(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_Command_command(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_Command_command(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Command(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_Command(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_Command(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_Command(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Command(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_Command(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_Command(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_Command(<<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_Command(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_Command(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Command(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_Command(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Command(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_Command(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Command(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +decode_msg_JsonRpcRequest(Bin, TrUserData) -> dfp_read_field_def_JsonRpcRequest(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_JsonRpcRequest(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_JsonRpcRequest_method(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_JsonRpcRequest(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_JsonRpcRequest_params(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_JsonRpcRequest(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'JsonRpcRequest'{method = F@_1, params = F@_2}; +dfp_read_field_def_JsonRpcRequest(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_JsonRpcRequest(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_JsonRpcRequest(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_JsonRpcRequest(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_JsonRpcRequest(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_JsonRpcRequest_method(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 18 -> d_field_JsonRpcRequest_params(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_JsonRpcRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_JsonRpcRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_JsonRpcRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_JsonRpcRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_JsonRpcRequest(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_JsonRpcRequest(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'JsonRpcRequest'{method = F@_1, params = F@_2}. + +d_field_JsonRpcRequest_method(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_JsonRpcRequest_method(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_JsonRpcRequest_method(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_JsonRpcRequest(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_JsonRpcRequest_params(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_JsonRpcRequest_params(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_JsonRpcRequest_params(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_JsonRpcRequest(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_JsonRpcRequest(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_JsonRpcRequest(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_JsonRpcRequest(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_JsonRpcRequest(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_JsonRpcRequest(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_JsonRpcRequest(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_JsonRpcRequest(<<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_JsonRpcRequest(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_JsonRpcRequest(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_JsonRpcRequest(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_JsonRpcRequest(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_JsonRpcRequest(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_JsonRpcRequest(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_JsonRpcRequest(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +decode_msg_JsonRpcReply(Bin, TrUserData) -> dfp_read_field_def_JsonRpcReply(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_JsonRpcReply(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_JsonRpcReply_result(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_JsonRpcReply(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_JsonRpcReply_error(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_JsonRpcReply(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'JsonRpcReply'{result = F@_1, error = F@_2}; +dfp_read_field_def_JsonRpcReply(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_JsonRpcReply(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_JsonRpcReply(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_JsonRpcReply(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_JsonRpcReply(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_JsonRpcReply_result(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 18 -> d_field_JsonRpcReply_error(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_JsonRpcReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_JsonRpcReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_JsonRpcReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_JsonRpcReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_JsonRpcReply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_JsonRpcReply(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'JsonRpcReply'{result = F@_1, error = F@_2}. + +d_field_JsonRpcReply_result(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_JsonRpcReply_result(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_JsonRpcReply_result(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_JsonRpcReply(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_JsonRpcReply_error(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_JsonRpcReply_error(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_JsonRpcReply_error(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_JsonRpcReply(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_JsonRpcReply(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_JsonRpcReply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_JsonRpcReply(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_JsonRpcReply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_JsonRpcReply(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_JsonRpcReply(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_JsonRpcReply(<<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_JsonRpcReply(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_JsonRpcReply(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_JsonRpcReply(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_JsonRpcReply(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_JsonRpcReply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_JsonRpcReply(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_JsonRpcReply(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +decode_msg_Data(Bin, TrUserData) -> dfp_read_field_def_Data(Bin, 0, 0, 0, id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_Data(<<10, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_Data_route_key(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_Data(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> d_field_Data_metric(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +dfp_read_field_def_Data(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'Data'{route_key = F@_1, metric = F@_2}; +dfp_read_field_def_Data(Other, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dg_read_field_def_Data(Other, Z1, Z2, F, F@_1, F@_2, TrUserData). + +dg_read_field_def_Data(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 32 - 7 -> dg_read_field_def_Data(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +dg_read_field_def_Data(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, TrUserData) -> + Key = X bsl N + Acc, + case Key of + 10 -> d_field_Data_route_key(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + 18 -> d_field_Data_metric(Rest, 0, 0, 0, F@_1, F@_2, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_Data(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 1 -> skip_64_Data(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 2 -> skip_length_delimited_Data(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 3 -> skip_group_Data(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData); + 5 -> skip_32_Data(Rest, 0, 0, Key bsr 3, F@_1, F@_2, TrUserData) + end + end; +dg_read_field_def_Data(<<>>, 0, 0, _, F@_1, F@_2, _) -> #'Data'{route_key = F@_1, metric = F@_2}. + +d_field_Data_route_key(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_Data_route_key(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_Data_route_key(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Data(RestF, 0, 0, F, NewFValue, F@_2, TrUserData). + +d_field_Data_metric(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> d_field_Data_metric(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +d_field_Data_metric(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_Data(RestF, 0, 0, F, F@_1, NewFValue, TrUserData). + +skip_varint_Data(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> skip_varint_Data(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData); +skip_varint_Data(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Data(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_length_delimited_Data(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, TrUserData) when N < 57 -> skip_length_delimited_Data(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, TrUserData); +skip_length_delimited_Data(<<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_Data(Rest2, 0, 0, F, F@_1, F@_2, TrUserData). + +skip_group_Data(Bin, _, Z2, FNum, F@_1, F@_2, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_Data(Rest, 0, Z2, FNum, F@_1, F@_2, TrUserData). + +skip_32_Data(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Data(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +skip_64_Data(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_Data(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). + +decode_msg_TaskEventStream(Bin, TrUserData) -> dfp_read_field_def_TaskEventStream(Bin, 0, 0, 0, id(0, TrUserData), id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData). + +dfp_read_field_def_TaskEventStream(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_TaskEventStream_task_id(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_TaskEventStream(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_TaskEventStream_type(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_TaskEventStream(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_TaskEventStream_stream(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_TaskEventStream(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #'TaskEventStream'{task_id = F@_1, type = F@_2, stream = F@_3}; +dfp_read_field_def_TaskEventStream(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dg_read_field_def_TaskEventStream(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +dg_read_field_def_TaskEventStream(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 32 - 7 -> dg_read_field_def_TaskEventStream(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +dg_read_field_def_TaskEventStream(<<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_TaskEventStream_task_id(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 18 -> d_field_TaskEventStream_type(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 26 -> d_field_TaskEventStream_stream(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + _ -> + case Key band 7 of + 0 -> skip_varint_TaskEventStream(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 1 -> skip_64_TaskEventStream(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 2 -> skip_length_delimited_TaskEventStream(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 3 -> skip_group_TaskEventStream(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 5 -> skip_32_TaskEventStream(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData) + end + end; +dg_read_field_def_TaskEventStream(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #'TaskEventStream'{task_id = F@_1, type = F@_2, stream = F@_3}. + +d_field_TaskEventStream_task_id(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_TaskEventStream_task_id(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_TaskEventStream_task_id(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, TrUserData) -> + {NewFValue, RestF} = {begin <> = <<(X bsl N + Acc):32/unsigned-native>>, id(Res, TrUserData) end, Rest}, + dfp_read_field_def_TaskEventStream(RestF, 0, 0, F, NewFValue, F@_2, F@_3, TrUserData). + +d_field_TaskEventStream_type(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_TaskEventStream_type(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_TaskEventStream_type(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_TaskEventStream(RestF, 0, 0, F, F@_1, NewFValue, F@_3, TrUserData). + +d_field_TaskEventStream_stream(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_TaskEventStream_stream(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_TaskEventStream_stream(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, TrUserData) -> + {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, + dfp_read_field_def_TaskEventStream(RestF, 0, 0, F, F@_1, F@_2, NewFValue, TrUserData). + +skip_varint_TaskEventStream(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> skip_varint_TaskEventStream(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +skip_varint_TaskEventStream(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_TaskEventStream(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_length_delimited_TaskEventStream(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> skip_length_delimited_TaskEventStream(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +skip_length_delimited_TaskEventStream(<<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_TaskEventStream(Rest2, 0, 0, F, F@_1, F@_2, F@_3, TrUserData). + +skip_group_TaskEventStream(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, TrUserData) -> + {_, Rest} = read_group(Bin, FNum), + dfp_read_field_def_TaskEventStream(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, TrUserData). + +skip_32_TaskEventStream(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_TaskEventStream(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +skip_64_TaskEventStream(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_TaskEventStream(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). + +read_group(Bin, FieldNum) -> + {NumBytes, EndTagLen} = read_gr_b(Bin, 0, 0, 0, 0, FieldNum), + <> = Bin, + {Group, Rest}. + +%% Like skipping over fields, but record the total length, +%% Each field is <(FieldNum bsl 3) bor FieldType> ++ +%% Record the length because varints may be non-optimally encoded. +%% +%% Groups can be nested, but assume the same FieldNum cannot be nested +%% because group field numbers are shared with the rest of the fields +%% numbers. Thus we can search just for an group-end with the same +%% field number. +%% +%% (The only time the same group field number could occur would +%% be in a nested sub message, but then it would be inside a +%% length-delimited entry, which we skip-read by length.) +read_gr_b(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, FieldNum) + when N < (32-7) -> + read_gr_b(Tl, N+7, X bsl N + Acc, NumBytes, TagLen+1, FieldNum); +read_gr_b(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, TagLen, + FieldNum) -> + Key = X bsl N + Acc, + TagLen1 = TagLen + 1, + case {Key bsr 3, Key band 7} of + {FieldNum, 4} -> % 4 = group_end + {NumBytes, TagLen1}; + {_, 0} -> % 0 = varint + read_gr_vi(Tl, 0, NumBytes + TagLen1, FieldNum); + {_, 1} -> % 1 = bits64 + <<_:64, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 8, 0, FieldNum); + {_, 2} -> % 2 = length_delimited + read_gr_ld(Tl, 0, 0, NumBytes + TagLen1, FieldNum); + {_, 3} -> % 3 = group_start + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 4} -> % 4 = group_end + read_gr_b(Tl, 0, 0, NumBytes + TagLen1, 0, FieldNum); + {_, 5} -> % 5 = bits32 + <<_:32, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes + TagLen1 + 4, 0, FieldNum) + end. + +read_gr_vi(<<1:1, _:7, Tl/binary>>, N, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_vi(Tl, N+7, NumBytes+1, FieldNum); +read_gr_vi(<<0:1, _:7, Tl/binary>>, _, NumBytes, FieldNum) -> + read_gr_b(Tl, 0, 0, NumBytes+1, 0, FieldNum). + +read_gr_ld(<<1:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) + when N < (64-7) -> + read_gr_ld(Tl, N+7, X bsl N + Acc, NumBytes+1, FieldNum); +read_gr_ld(<<0:1, X:7, Tl/binary>>, N, Acc, NumBytes, FieldNum) -> + Len = X bsl N + Acc, + NumBytes1 = NumBytes + 1, + <<_:Len/binary, Tl2/binary>> = Tl, + read_gr_b(Tl2, 0, 0, NumBytes1 + Len, 0, FieldNum). + +merge_msgs(Prev, New) when element(1, Prev) =:= element(1, New) -> merge_msgs(Prev, New, element(1, Prev), []). + +merge_msgs(Prev, New, MsgName) when is_atom(MsgName) -> merge_msgs(Prev, New, MsgName, []); +merge_msgs(Prev, New, Opts) when element(1, Prev) =:= element(1, New), is_list(Opts) -> merge_msgs(Prev, New, element(1, Prev), Opts). + +merge_msgs(Prev, New, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'AuthRequest' -> merge_msg_AuthRequest(Prev, New, TrUserData); + 'AuthReply' -> merge_msg_AuthReply(Prev, New, TrUserData); + 'Pub' -> merge_msg_Pub(Prev, New, TrUserData); + 'Command' -> merge_msg_Command(Prev, New, TrUserData); + 'JsonRpcRequest' -> merge_msg_JsonRpcRequest(Prev, New, TrUserData); + 'JsonRpcReply' -> merge_msg_JsonRpcReply(Prev, New, TrUserData); + 'Data' -> merge_msg_Data(Prev, New, TrUserData); + 'TaskEventStream' -> merge_msg_TaskEventStream(Prev, New, TrUserData) + end. + +-compile({nowarn_unused_function,merge_msg_AuthRequest/3}). +merge_msg_AuthRequest(#'AuthRequest'{uuid = PFuuid, username = PFusername, salt = PFsalt, token = PFtoken, timestamp = PFtimestamp}, #'AuthRequest'{uuid = NFuuid, username = NFusername, salt = NFsalt, token = NFtoken, timestamp = NFtimestamp}, _) -> + #'AuthRequest'{uuid = + if NFuuid =:= undefined -> PFuuid; + true -> NFuuid + end, + username = + if NFusername =:= undefined -> PFusername; + true -> NFusername + end, + salt = + if NFsalt =:= undefined -> PFsalt; + true -> NFsalt + end, + token = + if NFtoken =:= undefined -> PFtoken; + true -> NFtoken + end, + timestamp = + if NFtimestamp =:= undefined -> PFtimestamp; + true -> NFtimestamp + end}. + +-compile({nowarn_unused_function,merge_msg_AuthReply/3}). +merge_msg_AuthReply(#'AuthReply'{code = PFcode, payload = PFpayload}, #'AuthReply'{code = NFcode, payload = NFpayload}, _) -> + #'AuthReply'{code = + if NFcode =:= undefined -> PFcode; + true -> NFcode + end, + payload = + if NFpayload =:= undefined -> PFpayload; + true -> NFpayload + end}. + +-compile({nowarn_unused_function,merge_msg_Pub/3}). +merge_msg_Pub(#'Pub'{topic = PFtopic, qos = PFqos, content = PFcontent}, #'Pub'{topic = NFtopic, qos = NFqos, content = NFcontent}, _) -> + #'Pub'{topic = + if NFtopic =:= undefined -> PFtopic; + true -> NFtopic + end, + qos = + if NFqos =:= undefined -> PFqos; + true -> NFqos + end, + content = + if NFcontent =:= undefined -> PFcontent; + true -> NFcontent + end}. + +-compile({nowarn_unused_function,merge_msg_Command/3}). +merge_msg_Command(#'Command'{command_type = PFcommand_type, command = PFcommand}, #'Command'{command_type = NFcommand_type, command = NFcommand}, _) -> + #'Command'{command_type = + if NFcommand_type =:= undefined -> PFcommand_type; + true -> NFcommand_type + end, + command = + if NFcommand =:= undefined -> PFcommand; + true -> NFcommand + end}. + +-compile({nowarn_unused_function,merge_msg_JsonRpcRequest/3}). +merge_msg_JsonRpcRequest(#'JsonRpcRequest'{method = PFmethod, params = PFparams}, #'JsonRpcRequest'{method = NFmethod, params = NFparams}, _) -> + #'JsonRpcRequest'{method = + if NFmethod =:= undefined -> PFmethod; + true -> NFmethod + end, + params = + if NFparams =:= undefined -> PFparams; + true -> NFparams + end}. + +-compile({nowarn_unused_function,merge_msg_JsonRpcReply/3}). +merge_msg_JsonRpcReply(#'JsonRpcReply'{result = PFresult, error = PFerror}, #'JsonRpcReply'{result = NFresult, error = NFerror}, _) -> + #'JsonRpcReply'{result = + if NFresult =:= undefined -> PFresult; + true -> NFresult + end, + error = + if NFerror =:= undefined -> PFerror; + true -> NFerror + end}. + +-compile({nowarn_unused_function,merge_msg_Data/3}). +merge_msg_Data(#'Data'{route_key = PFroute_key, metric = PFmetric}, #'Data'{route_key = NFroute_key, metric = NFmetric}, _) -> + #'Data'{route_key = + if NFroute_key =:= undefined -> PFroute_key; + true -> NFroute_key + end, + metric = + if NFmetric =:= undefined -> PFmetric; + true -> NFmetric + end}. + +-compile({nowarn_unused_function,merge_msg_TaskEventStream/3}). +merge_msg_TaskEventStream(#'TaskEventStream'{task_id = PFtask_id, type = PFtype, stream = PFstream}, #'TaskEventStream'{task_id = NFtask_id, type = NFtype, stream = NFstream}, _) -> + #'TaskEventStream'{task_id = + if NFtask_id =:= undefined -> PFtask_id; + true -> NFtask_id + end, + type = + if NFtype =:= undefined -> PFtype; + true -> NFtype + end, + stream = + if NFstream =:= undefined -> PFstream; + true -> NFstream + end}. + + +verify_msg(Msg) when tuple_size(Msg) >= 1 -> verify_msg(Msg, element(1, Msg), []); +verify_msg(X) -> mk_type_error(not_a_known_message, X, []). + +verify_msg(Msg, MsgName) when is_atom(MsgName) -> verify_msg(Msg, MsgName, []); +verify_msg(Msg, Opts) when tuple_size(Msg) >= 1 -> verify_msg(Msg, element(1, Msg), Opts); +verify_msg(X, _Opts) -> mk_type_error(not_a_known_message, X, []). + +verify_msg(Msg, MsgName, Opts) -> + TrUserData = proplists:get_value(user_data, Opts), + case MsgName of + 'AuthRequest' -> v_msg_AuthRequest(Msg, [MsgName], TrUserData); + 'AuthReply' -> v_msg_AuthReply(Msg, [MsgName], TrUserData); + 'Pub' -> v_msg_Pub(Msg, [MsgName], TrUserData); + 'Command' -> v_msg_Command(Msg, [MsgName], TrUserData); + 'JsonRpcRequest' -> v_msg_JsonRpcRequest(Msg, [MsgName], TrUserData); + 'JsonRpcReply' -> v_msg_JsonRpcReply(Msg, [MsgName], TrUserData); + 'Data' -> v_msg_Data(Msg, [MsgName], TrUserData); + 'TaskEventStream' -> v_msg_TaskEventStream(Msg, [MsgName], TrUserData); + _ -> mk_type_error(not_a_known_message, Msg, []) + end. + + +-compile({nowarn_unused_function,v_msg_AuthRequest/3}). +-dialyzer({nowarn_function,v_msg_AuthRequest/3}). +v_msg_AuthRequest(#'AuthRequest'{uuid = F1, username = F2, salt = F3, token = F4, timestamp = F5}, Path, TrUserData) -> + if F1 == undefined -> ok; + true -> v_type_bytes(F1, [uuid | Path], TrUserData) + end, + if F2 == undefined -> ok; + true -> v_type_bytes(F2, [username | Path], TrUserData) + end, + if F3 == undefined -> ok; + true -> v_type_bytes(F3, [salt | Path], TrUserData) + end, + if F4 == undefined -> ok; + true -> v_type_bytes(F4, [token | Path], TrUserData) + end, + if F5 == undefined -> ok; + true -> v_type_int32(F5, [timestamp | Path], TrUserData) + end, + ok; +v_msg_AuthRequest(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'AuthRequest'}, X, Path). + +-compile({nowarn_unused_function,v_msg_AuthReply/3}). +-dialyzer({nowarn_function,v_msg_AuthReply/3}). +v_msg_AuthReply(#'AuthReply'{code = F1, payload = F2}, Path, TrUserData) -> + if F1 == undefined -> ok; + true -> v_type_int32(F1, [code | Path], TrUserData) + end, + if F2 == undefined -> ok; + true -> v_type_bytes(F2, [payload | Path], TrUserData) + end, + ok; +v_msg_AuthReply(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'AuthReply'}, X, Path). + +-compile({nowarn_unused_function,v_msg_Pub/3}). +-dialyzer({nowarn_function,v_msg_Pub/3}). +v_msg_Pub(#'Pub'{topic = F1, qos = F2, content = F3}, Path, TrUserData) -> + if F1 == undefined -> ok; + true -> v_type_bytes(F1, [topic | Path], TrUserData) + end, + if F2 == undefined -> ok; + true -> v_type_int32(F2, [qos | Path], TrUserData) + end, + if F3 == undefined -> ok; + true -> v_type_bytes(F3, [content | Path], TrUserData) + end, + ok; +v_msg_Pub(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Pub'}, X, Path). + +-compile({nowarn_unused_function,v_msg_Command/3}). +-dialyzer({nowarn_function,v_msg_Command/3}). +v_msg_Command(#'Command'{command_type = F1, command = F2}, Path, TrUserData) -> + if F1 == undefined -> ok; + true -> v_type_int32(F1, [command_type | Path], TrUserData) + end, + if F2 == undefined -> ok; + true -> v_type_bytes(F2, [command | Path], TrUserData) + end, + ok; +v_msg_Command(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Command'}, X, Path). + +-compile({nowarn_unused_function,v_msg_JsonRpcRequest/3}). +-dialyzer({nowarn_function,v_msg_JsonRpcRequest/3}). +v_msg_JsonRpcRequest(#'JsonRpcRequest'{method = F1, params = F2}, Path, TrUserData) -> + if F1 == undefined -> ok; + true -> v_type_bytes(F1, [method | Path], TrUserData) + end, + if F2 == undefined -> ok; + true -> v_type_bytes(F2, [params | Path], TrUserData) + end, + ok; +v_msg_JsonRpcRequest(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'JsonRpcRequest'}, X, Path). + +-compile({nowarn_unused_function,v_msg_JsonRpcReply/3}). +-dialyzer({nowarn_function,v_msg_JsonRpcReply/3}). +v_msg_JsonRpcReply(#'JsonRpcReply'{result = F1, error = F2}, Path, TrUserData) -> + if F1 == undefined -> ok; + true -> v_type_bytes(F1, [result | Path], TrUserData) + end, + if F2 == undefined -> ok; + true -> v_type_bytes(F2, [error | Path], TrUserData) + end, + ok; +v_msg_JsonRpcReply(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'JsonRpcReply'}, X, Path). + +-compile({nowarn_unused_function,v_msg_Data/3}). +-dialyzer({nowarn_function,v_msg_Data/3}). +v_msg_Data(#'Data'{route_key = F1, metric = F2}, Path, TrUserData) -> + if F1 == undefined -> ok; + true -> v_type_bytes(F1, [route_key | Path], TrUserData) + end, + if F2 == undefined -> ok; + true -> v_type_bytes(F2, [metric | Path], TrUserData) + end, + ok; +v_msg_Data(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'Data'}, X, Path). + +-compile({nowarn_unused_function,v_msg_TaskEventStream/3}). +-dialyzer({nowarn_function,v_msg_TaskEventStream/3}). +v_msg_TaskEventStream(#'TaskEventStream'{task_id = F1, type = F2, stream = F3}, Path, TrUserData) -> + if F1 == undefined -> ok; + true -> v_type_int32(F1, [task_id | Path], TrUserData) + end, + if F2 == undefined -> ok; + true -> v_type_bytes(F2, [type | Path], TrUserData) + end, + if F3 == undefined -> ok; + true -> v_type_bytes(F3, [stream | Path], TrUserData) + end, + ok; +v_msg_TaskEventStream(X, Path, _TrUserData) -> mk_type_error({expected_msg, 'TaskEventStream'}, X, Path). + +-compile({nowarn_unused_function,v_type_int32/3}). +-dialyzer({nowarn_function,v_type_int32/3}). +v_type_int32(N, _Path, _TrUserData) when is_integer(N), -2147483648 =< N, N =< 2147483647 -> ok; +v_type_int32(N, Path, _TrUserData) when is_integer(N) -> mk_type_error({value_out_of_range, int32, signed, 32}, N, Path); +v_type_int32(X, Path, _TrUserData) -> mk_type_error({bad_integer, int32, signed, 32}, X, Path). + +-compile({nowarn_unused_function,v_type_bytes/3}). +-dialyzer({nowarn_function,v_type_bytes/3}). +v_type_bytes(B, _Path, _TrUserData) when is_binary(B) -> ok; +v_type_bytes(B, _Path, _TrUserData) when is_list(B) -> ok; +v_type_bytes(X, Path, _TrUserData) -> mk_type_error(bad_binary_value, X, Path). + +-compile({nowarn_unused_function,mk_type_error/3}). +-spec mk_type_error(_, _, list()) -> no_return(). +mk_type_error(Error, ValueSeen, Path) -> + Path2 = prettify_path(Path), + erlang:error({gpb_type_error, {Error, [{value, ValueSeen}, {path, Path2}]}}). + + +-compile({nowarn_unused_function,prettify_path/1}). +-dialyzer({nowarn_function,prettify_path/1}). +prettify_path([]) -> top_level; +prettify_path(PathR) -> lists:append(lists:join(".", lists:map(fun atom_to_list/1, lists:reverse(PathR)))). + + +-compile({nowarn_unused_function,id/2}). +-compile({inline,id/2}). +id(X, _TrUserData) -> X. + +-compile({nowarn_unused_function,v_ok/3}). +-compile({inline,v_ok/3}). +v_ok(_Value, _Path, _TrUserData) -> ok. + +-compile({nowarn_unused_function,m_overwrite/3}). +-compile({inline,m_overwrite/3}). +m_overwrite(_Prev, New, _TrUserData) -> New. + +-compile({nowarn_unused_function,cons/3}). +-compile({inline,cons/3}). +cons(Elem, Acc, _TrUserData) -> [Elem | Acc]. + +-compile({nowarn_unused_function,lists_reverse/2}). +-compile({inline,lists_reverse/2}). +'lists_reverse'(L, _TrUserData) -> lists:reverse(L). +-compile({nowarn_unused_function,'erlang_++'/3}). +-compile({inline,'erlang_++'/3}). +'erlang_++'(A, B, _TrUserData) -> A ++ B. + + +get_msg_defs() -> + [{{msg, 'AuthRequest'}, + [#field{name = uuid, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, + #field{name = username, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}, + #field{name = salt, fnum = 3, rnum = 4, type = bytes, occurrence = optional, opts = []}, + #field{name = token, fnum = 4, rnum = 5, type = bytes, occurrence = optional, opts = []}, + #field{name = timestamp, fnum = 5, rnum = 6, type = int32, occurrence = optional, opts = []}]}, + {{msg, 'AuthReply'}, [#field{name = code, fnum = 1, rnum = 2, type = int32, occurrence = optional, opts = []}, #field{name = payload, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]}, + {{msg, 'Pub'}, + [#field{name = topic, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, + #field{name = qos, fnum = 2, rnum = 3, type = int32, occurrence = optional, opts = []}, + #field{name = content, fnum = 3, rnum = 4, type = bytes, occurrence = optional, opts = []}]}, + {{msg, 'Command'}, [#field{name = command_type, fnum = 1, rnum = 2, type = int32, occurrence = optional, opts = []}, #field{name = command, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]}, + {{msg, 'JsonRpcRequest'}, [#field{name = method, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, #field{name = params, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]}, + {{msg, 'JsonRpcReply'}, [#field{name = result, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, #field{name = error, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]}, + {{msg, 'Data'}, [#field{name = route_key, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, #field{name = metric, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]}, + {{msg, 'TaskEventStream'}, + [#field{name = task_id, fnum = 1, rnum = 2, type = int32, occurrence = optional, opts = []}, + #field{name = type, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}, + #field{name = stream, fnum = 3, rnum = 4, type = bytes, occurrence = optional, opts = []}]}]. + + +get_msg_names() -> ['AuthRequest', 'AuthReply', 'Pub', 'Command', 'JsonRpcRequest', 'JsonRpcReply', 'Data', 'TaskEventStream']. + + +get_group_names() -> []. + + +get_msg_or_group_names() -> ['AuthRequest', 'AuthReply', 'Pub', 'Command', 'JsonRpcRequest', 'JsonRpcReply', 'Data', 'TaskEventStream']. + + +get_enum_names() -> []. + + +fetch_msg_def(MsgName) -> + case find_msg_def(MsgName) of + Fs when is_list(Fs) -> Fs; + error -> erlang:error({no_such_msg, MsgName}) + end. + + +-spec fetch_enum_def(_) -> no_return(). +fetch_enum_def(EnumName) -> erlang:error({no_such_enum, EnumName}). + + +find_msg_def('AuthRequest') -> + [#field{name = uuid, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, + #field{name = username, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}, + #field{name = salt, fnum = 3, rnum = 4, type = bytes, occurrence = optional, opts = []}, + #field{name = token, fnum = 4, rnum = 5, type = bytes, occurrence = optional, opts = []}, + #field{name = timestamp, fnum = 5, rnum = 6, type = int32, occurrence = optional, opts = []}]; +find_msg_def('AuthReply') -> [#field{name = code, fnum = 1, rnum = 2, type = int32, occurrence = optional, opts = []}, #field{name = payload, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]; +find_msg_def('Pub') -> + [#field{name = topic, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, + #field{name = qos, fnum = 2, rnum = 3, type = int32, occurrence = optional, opts = []}, + #field{name = content, fnum = 3, rnum = 4, type = bytes, occurrence = optional, opts = []}]; +find_msg_def('Command') -> [#field{name = command_type, fnum = 1, rnum = 2, type = int32, occurrence = optional, opts = []}, #field{name = command, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]; +find_msg_def('JsonRpcRequest') -> [#field{name = method, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, #field{name = params, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]; +find_msg_def('JsonRpcReply') -> [#field{name = result, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, #field{name = error, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]; +find_msg_def('Data') -> [#field{name = route_key, fnum = 1, rnum = 2, type = bytes, occurrence = optional, opts = []}, #field{name = metric, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}]; +find_msg_def('TaskEventStream') -> + [#field{name = task_id, fnum = 1, rnum = 2, type = int32, occurrence = optional, opts = []}, + #field{name = type, fnum = 2, rnum = 3, type = bytes, occurrence = optional, opts = []}, + #field{name = stream, fnum = 3, rnum = 4, type = bytes, occurrence = optional, opts = []}]; +find_msg_def(_) -> error. + + +find_enum_def(_) -> error. + + +-spec enum_symbol_by_value(_, _) -> no_return(). +enum_symbol_by_value(E, V) -> erlang:error({no_enum_defs, E, V}). + + +-spec enum_value_by_symbol(_, _) -> no_return(). +enum_value_by_symbol(E, V) -> erlang:error({no_enum_defs, E, V}). + + + +get_service_names() -> []. + + +get_service_def(_) -> error. + + +get_rpc_names(_) -> error. + + +find_rpc_def(_, _) -> error. + + + +-spec fetch_rpc_def(_, _) -> no_return(). +fetch_rpc_def(ServiceName, RpcName) -> erlang:error({no_such_rpc, ServiceName, RpcName}). + + +%% Convert a a fully qualified (ie with package name) service name +%% as a binary to a service name as an atom. +-spec fqbin_to_service_name(_) -> no_return(). +fqbin_to_service_name(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a service name as an atom to a fully qualified +%% (ie with package name) name as a binary. +-spec service_name_to_fqbin(_) -> no_return(). +service_name_to_fqbin(X) -> error({gpb_error, {badservice, X}}). + + +%% Convert a a fully qualified (ie with package name) service name +%% and an rpc name, both as binaries to a service name and an rpc +%% name, as atoms. +-spec fqbins_to_service_and_rpc_name(_, _) -> no_return(). +fqbins_to_service_and_rpc_name(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +%% Convert a service name and an rpc name, both as atoms, +%% to a fully qualified (ie with package name) service name and +%% an rpc name as binaries. +-spec service_and_rpc_name_to_fqbins(_, _) -> no_return(). +service_and_rpc_name_to_fqbins(S, R) -> error({gpb_error, {badservice_or_rpc, {S, R}}}). + + +fqbin_to_msg_name(<<"AuthRequest">>) -> 'AuthRequest'; +fqbin_to_msg_name(<<"AuthReply">>) -> 'AuthReply'; +fqbin_to_msg_name(<<"Pub">>) -> 'Pub'; +fqbin_to_msg_name(<<"Command">>) -> 'Command'; +fqbin_to_msg_name(<<"JsonRpcRequest">>) -> 'JsonRpcRequest'; +fqbin_to_msg_name(<<"JsonRpcReply">>) -> 'JsonRpcReply'; +fqbin_to_msg_name(<<"Data">>) -> 'Data'; +fqbin_to_msg_name(<<"TaskEventStream">>) -> 'TaskEventStream'; +fqbin_to_msg_name(E) -> error({gpb_error, {badmsg, E}}). + + +msg_name_to_fqbin('AuthRequest') -> <<"AuthRequest">>; +msg_name_to_fqbin('AuthReply') -> <<"AuthReply">>; +msg_name_to_fqbin('Pub') -> <<"Pub">>; +msg_name_to_fqbin('Command') -> <<"Command">>; +msg_name_to_fqbin('JsonRpcRequest') -> <<"JsonRpcRequest">>; +msg_name_to_fqbin('JsonRpcReply') -> <<"JsonRpcReply">>; +msg_name_to_fqbin('Data') -> <<"Data">>; +msg_name_to_fqbin('TaskEventStream') -> <<"TaskEventStream">>; +msg_name_to_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +-spec fqbin_to_enum_name(_) -> no_return(). +fqbin_to_enum_name(E) -> error({gpb_error, {badenum, E}}). + + +-spec enum_name_to_fqbin(_) -> no_return(). +enum_name_to_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +get_package_name() -> undefined. + + +%% Whether or not the message names +%% are prepended with package name or not. +uses_packages() -> false. + + +source_basename() -> "message.proto". + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned with extension, +%% see get_all_proto_names/0 for a version that returns +%% the basenames sans extension +get_all_source_basenames() -> ["message.proto"]. + + +%% Retrieve all proto file names, also imported ones. +%% The order is top-down. The first element is always the main +%% source file. The files are returned sans .proto extension, +%% to make it easier to use them with the various get_xyz_containment +%% functions. +get_all_proto_names() -> ["message"]. + + +get_msg_containment("message") -> ['AuthReply', 'AuthRequest', 'Command', 'Data', 'JsonRpcReply', 'JsonRpcRequest', 'Pub', 'TaskEventStream']; +get_msg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_pkg_containment("message") -> undefined; +get_pkg_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_service_containment("message") -> []; +get_service_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_rpc_containment("message") -> []; +get_rpc_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_enum_containment("message") -> []; +get_enum_containment(P) -> error({gpb_error, {badproto, P}}). + + +get_proto_by_msg_name_as_fqbin(<<"Data">>) -> "message"; +get_proto_by_msg_name_as_fqbin(<<"Pub">>) -> "message"; +get_proto_by_msg_name_as_fqbin(<<"JsonRpcRequest">>) -> "message"; +get_proto_by_msg_name_as_fqbin(<<"Command">>) -> "message"; +get_proto_by_msg_name_as_fqbin(<<"AuthRequest">>) -> "message"; +get_proto_by_msg_name_as_fqbin(<<"JsonRpcReply">>) -> "message"; +get_proto_by_msg_name_as_fqbin(<<"AuthReply">>) -> "message"; +get_proto_by_msg_name_as_fqbin(<<"TaskEventStream">>) -> "message"; +get_proto_by_msg_name_as_fqbin(E) -> error({gpb_error, {badmsg, E}}). + + +-spec get_proto_by_service_name_as_fqbin(_) -> no_return(). +get_proto_by_service_name_as_fqbin(E) -> error({gpb_error, {badservice, E}}). + + +-spec get_proto_by_enum_name_as_fqbin(_) -> no_return(). +get_proto_by_enum_name_as_fqbin(E) -> error({gpb_error, {badenum, E}}). + + +-spec get_protos_by_pkg_name_as_fqbin(_) -> no_return(). +get_protos_by_pkg_name_as_fqbin(E) -> error({gpb_error, {badpkg, E}}). + + + +gpb_version_as_string() -> + "4.21.7". + +gpb_version_as_list() -> + [4,21,7]. + +gpb_version_source() -> + "file". diff --git a/src/transport/tcp/tcp_channel.erl b/src/transport/tcp/tcp_channel.erl index 8834c20..2c0c41f 100644 --- a/src/transport/tcp/tcp_channel.erl +++ b/src/transport/tcp/tcp_channel.erl @@ -9,6 +9,7 @@ -module(tcp_channel). -author("licheng5"). -include("message.hrl"). +-include("message_pb.hrl"). -behaviour(ranch_protocol). %% API @@ -43,10 +44,10 @@ command(Pid, CommandType, Command) when is_pid(Pid), is_integer(CommandType), is gen_server:cast(Pid, {command, CommandType, Command}). %% 向通道中写入消息 --spec jsonrpc_call(Pid :: pid(), ReceiverPid :: pid(), CallBin :: binary()) -> Ref :: reference(). -jsonrpc_call(Pid, ReceiverPid, CallBin) when is_pid(Pid), is_pid(ReceiverPid), is_binary(CallBin) -> +-spec jsonrpc_call(Pid :: pid(), ReceiverPid :: pid(), Request :: #'JsonRpcRequest'{}) -> Ref :: reference(). +jsonrpc_call(Pid, ReceiverPid, Request = #'JsonRpcRequest'{}) when is_pid(Pid), is_pid(ReceiverPid) -> Ref = make_ref(), - gen_server:cast(Pid, {jsonrpc_call, ReceiverPid, Ref, CallBin}), + gen_server:cast(Pid, {jsonrpc_call, ReceiverPid, Ref, Request}), Ref. %% 关闭方法 @@ -76,24 +77,33 @@ handle_call(_Request, _From, State) -> %% 发送消息, 基于pub/sub机制 handle_cast({pub, Topic, Qos, Content}, State = #state{transport = Transport, socket = Socket}) -> - EncPub = message_codec:encode(?MESSAGE_PUB, #pub{topic = Topic, qos = Qos, content = Content}), + Encoded = message_pb:encode_msg(#'Pub'{topic = Topic, qos = Qos, content = Content}, 'Pub'), + EncPub = <>, Transport:send(Socket, <>), {noreply, State}; %% 发送Command消息 handle_cast({command, CommandType, Command}, State = #state{transport = Transport, socket = Socket}) -> - EncCommand = message_codec:encode(?MESSAGE_COMMAND, #command{command_type = CommandType, command = Command}), + Encoded = message_pb:encode_msg(#'Command'{command_type = CommandType, command = Command}, 'Command'), + EncCommand = <>, Transport:send(Socket, <>), {noreply, State}; %% 推送消息 -handle_cast({jsonrpc_call, ReceiverPid, Ref, CallBin}, State = #state{transport = Transport, socket = Socket, packet_id = PacketId, inflight = Inflight}) -> - Transport:send(Socket, <>), +handle_cast({jsonrpc_call, ReceiverPid, Ref, Request = #'JsonRpcRequest'{}}, State = #state{transport = Transport, socket = Socket, packet_id = PacketId, inflight = Inflight}) -> + Encoded = message_pb:encode_msg(Request, 'JsonRpcRequest'), + EncRequest = <>, + Transport:send(Socket, <>), {noreply, State#state{packet_id = PacketId + 1, inflight = maps:put(PacketId, {ReceiverPid, Ref}, Inflight)}}. %% auth验证 -handle_info({tcp, Socket, <>}, State = #state{transport = Transport, socket = Socket}) -> - {ok, #auth_request{uuid = UUID, username = Username, token = Token, salt = Salt, timestamp = Timestamp}} = message_codec:decode(RequestBin), +handle_info({tcp, Socket, <>}, State = #state{transport = Transport, socket = Socket}) -> + #'AuthRequest'{uuid = UUID0, username = Username0, token = Token0, salt = Salt0, timestamp = Timestamp} = + message_pb:decode_msg(RequestBin, 'AuthRequest'), + UUID = iolist_to_binary(UUID0), + Username = iolist_to_binary(Username0), + Token = iolist_to_binary(Token0), + Salt = iolist_to_binary(Salt0), logger:debug("[ws_channel] auth uuid: ~p", [UUID]), case iot_auth:check(Username, Token, UUID, Salt, Timestamp) of true -> @@ -108,20 +118,23 @@ handle_info({tcp, Socket, <>}, ok -> %% 建立到host的monitor erlang:monitor(process, HostPid), - AuthReplyBin = message_codec:encode(?MESSAGE_AUTH_REPLY, #auth_reply{code = 0, payload = <<"ok">>}), + Encoded = message_pb:encode_msg(#'AuthReply'{code = 0, payload = <<"ok">>}, 'AuthReply'), + AuthReplyBin = <>, Transport:send(Socket, <>), {noreply, State#state{uuid = UUID, host_pid = HostPid}}; {denied, Reason} when is_binary(Reason) -> erlang:monitor(process, HostPid), - AuthReplyBin = message_codec:encode(?MESSAGE_AUTH_REPLY, #auth_reply{code = 1, payload = Reason}), + Encoded = message_pb:encode_msg(#'AuthReply'{code = 1, payload = Reason}, 'AuthReply'), + AuthReplyBin = <>, Transport:send(Socket, <>), logger:debug("[ws_channel] uuid: ~p, attach channel get error: ~p, stop channel", [UUID, Reason]), {noreply, State#state{uuid = UUID, host_pid = HostPid}}; {error, Reason} when is_binary(Reason) -> - AuthReplyBin = message_codec:encode(?MESSAGE_AUTH_REPLY, #auth_reply{code = 2, payload = Reason}), + Encoded = message_pb:encode_msg(#'AuthReply'{code = 2, payload = Reason}, 'AuthReply'), + AuthReplyBin = <>, Transport:send(Socket, <>), logger:debug("[ws_channel] uuid: ~p, attach channel get error: ~p, stop channel", [UUID, Reason]), @@ -132,19 +145,32 @@ handle_info({tcp, Socket, <>}, logger:warning("[ws_channel] uuid: ~p, user: ~p, auth failed", [UUID, Username]), {stop, State} end; +handle_info({tcp, Socket, <>}, State = #state{socket = Socket}) -> + logger:warning("[ws_channel] unsupported request message type: ~p", [MsgType]), + {stop, State}; -handle_info({tcp, Socket, <>}, State = #state{socket = Socket, host_pid = HostPid}) when is_pid(HostPid) -> - {ok, CastMessage} = message_codec:decode(CastBin), +handle_info({tcp, Socket, <>}, State = #state{socket = Socket, host_pid = HostPid}) when is_pid(HostPid) -> + CastMessage = message_pb:decode_msg(CastBin, 'Data'), case CastMessage of - #data{} = Data -> - iot_host:handle(HostPid, {data, Data}); - #task_event_stream{task_id = TaskId, type = <<"close">>, stream = Reason} -> - iot_event_stream_observer:stream_close(TaskId, Reason); - #task_event_stream{task_id = TaskId, type = Type, stream = Stream} -> - logger:debug("[tcp_channel] get task_id: ~p, type: ~ts, stream: ~ts", [TaskId, Type, Stream]), - iot_event_stream_observer:stream_data(TaskId, Type, Stream) + #'Data'{} = Data -> + iot_host:handle(HostPid, {data, Data}) end, {noreply, State}; +handle_info({tcp, Socket, <>}, State = #state{socket = Socket, host_pid = HostPid}) when is_pid(HostPid) -> + CastMessage = message_pb:decode_msg(CastBin, 'TaskEventStream'), + case CastMessage of + #'TaskEventStream'{task_id = TaskId, type = Type0, stream = Reason0} when Type0 =:= <<"close">>; Type0 =:= [<<"close">>] -> + iot_event_stream_observer:stream_close(TaskId, iolist_to_binary(Reason0)); + #'TaskEventStream'{task_id = TaskId, type = Type, stream = Stream} -> + TypeBin = iolist_to_binary(Type), + StreamBin = iolist_to_binary(Stream), + logger:debug("[tcp_channel] get task_id: ~p, type: ~ts, stream: ~ts", [TaskId, TypeBin, StreamBin]), + iot_event_stream_observer:stream_data(TaskId, TypeBin, StreamBin) + end, + {noreply, State}; +handle_info({tcp, Socket, <>}, State = #state{socket = Socket}) -> + logger:warning("[tcp_channel] unsupported cast message type: ~p", [MsgType]), + {noreply, State}; %handle_info({tcp, Socket, <>}, State = #state{socket = Socket, host_pid = HostPid}) when is_pid(HostPid) -> % Ping = message_pb:decode_msg(PingData, ping), @@ -153,7 +179,8 @@ handle_info({tcp, Socket, <>}, State = #state{sock %% 主机端的消息响应 handle_info({tcp, Socket, <>}, State = #state{socket = Socket, inflight = Inflight}) when PacketId > 0 -> - {ok, RpcReply} = message_codec:decode(ResponseBin), + <> = ResponseBin, + RpcReply = message_pb:decode_msg(ReplyBin, 'JsonRpcReply'), case maps:take(PacketId, Inflight) of error -> {noreply, State};