fix proto

This commit is contained in:
anlicheng 2026-04-23 10:46:33 +08:00
parent ebdbd3f84f
commit 8c300b12fe
3 changed files with 767 additions and 882 deletions

View File

@ -16,36 +16,6 @@
}).
-endif.
-ifndef('REPLYFRAME_PB_H').
-define('REPLYFRAME_PB_H', true).
-record('ReplyFrame',
{packet_id = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits
reply :: {result, message_pb:'ReplyResult'()} | {error, message_pb:'ReplyError'()} | undefined % oneof
}).
-endif.
-ifndef('REPLYRESULT_PB_H').
-define('REPLYRESULT_PB_H', true).
-record('ReplyResult',
{data = <<>> :: iodata() | undefined % = 1, optional
}).
-endif.
-ifndef('REPLYERROR_PB_H').
-define('REPLYERROR_PB_H', true).
-record('ReplyError',
{code = 0 :: integer() | undefined, % = 1, optional, 32 bits
message = <<>> :: unicode:chardata() | undefined % = 2, optional
}).
-endif.
-ifndef('CASTFRAME_PB_H').
-define('CASTFRAME_PB_H', true).
-record('CastFrame',
{body :: {pub, message_pb:'Pub'()} | {command, message_pb:'Command'()} | {data, message_pb:'Data'()} | {event_stream, message_pb:'TaskEventStream'()} | undefined % oneof
}).
-endif.
-ifndef('AUTHREQUEST_PB_H').
-define('AUTHREQUEST_PB_H', true).
-record('AuthRequest',
@ -57,40 +27,63 @@
}).
-endif.
-ifndef('PUB_PB_H').
-define('PUB_PB_H', true).
-record('Pub',
-ifndef('REPLYFRAME.ERROR_PB_H').
-define('REPLYFRAME.ERROR_PB_H', true).
-record('ReplyFrame.Error',
{code = 0 :: integer() | undefined, % = 1, optional, 32 bits
message = <<>> :: unicode:chardata() | undefined % = 2, optional
}).
-endif.
-ifndef('REPLYFRAME_PB_H').
-define('REPLYFRAME_PB_H', true).
-record('ReplyFrame',
{packet_id = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits
reply :: {result, iodata()} | {error, message_pb:'ReplyFrame.Error'()} | undefined % oneof
}).
-endif.
-ifndef('CASTFRAME.PUB_PB_H').
-define('CASTFRAME.PUB_PB_H', true).
-record('CastFrame.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',
-ifndef('CASTFRAME.COMMAND_PB_H').
-define('CASTFRAME.COMMAND_PB_H', true).
-record('CastFrame.Command',
{command_type = 0 :: integer() | undefined, % = 1, optional, 32 bits
command = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('DATA_PB_H').
-define('DATA_PB_H', true).
-record('Data',
-ifndef('CASTFRAME.DATA_PB_H').
-define('CASTFRAME.DATA_PB_H', true).
-record('CastFrame.Data',
{route_key = <<>> :: iodata() | undefined, % = 1, optional
metric = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('TASKEVENTSTREAM_PB_H').
-define('TASKEVENTSTREAM_PB_H', true).
-record('TaskEventStream',
-ifndef('CASTFRAME.TASKEVENT_PB_H').
-define('CASTFRAME.TASKEVENT_PB_H', true).
-record('CastFrame.TaskEvent',
{task_id = 0 :: integer() | undefined, % = 1, optional, 32 bits
type = <<>> :: iodata() | undefined, % = 2, optional
stream = <<>> :: iodata() | undefined % = 3, optional
}).
-endif.
-ifndef('CASTFRAME_PB_H').
-define('CASTFRAME_PB_H', true).
-record('CastFrame',
{body :: {pub, message_pb:'CastFrame.Pub'()} | {command, message_pb:'CastFrame.Command'()} | {data, message_pb:'CastFrame.Data'()} | {task_event, message_pb:'CastFrame.TaskEvent'()} | undefined % oneof
}).
-endif.
-ifndef('CONTAINERREF_PB_H').
-define('CONTAINERREF_PB_H', true).
-record('ContainerRef',

File diff suppressed because it is too large Load Diff

View File

@ -85,7 +85,7 @@ callback_mode() ->
-spec handle_event(term(), term(), atom(), #state{}) -> term().
handle_event(cast, {metric_data, RouteKey, Metric}, StateName, State = #state{socket = Socket}) ->
CastFrame = message_pb:encode_msg(#'CastFrame'{
body = {data, #'Data'{route_key = RouteKey, metric = Metric}}
body = {data, #'CastFrame.Data'{route_key = RouteKey, metric = Metric}}
}),
Packet = <<?FRAME_CAST, CastFrame/binary>>,
case StateName of
@ -100,14 +100,14 @@ handle_event(cast, {metric_data, RouteKey, Metric}, StateName, State = #state{so
handle_event(cast, {task_event_stream, TaskId, Type, Stream}, ?STATE_ACTIVATED, State = #state{socket = Socket}) ->
logger:debug("[efka_client] event_stream task_id: ~p, stream: ~ts", [TaskId, Stream]),
EventPacket = message_pb:encode_msg(#'CastFrame'{
body = {event_stream, #'TaskEventStream'{task_id = TaskId, type = Type, stream = Stream}}
body = {task_event, #'CastFrame.TaskEvent'{task_id = TaskId, type = Type, stream = Stream}}
}),
send_packet(Socket, <<?FRAME_CAST, EventPacket/binary>>),
{keep_state, State};
handle_event(cast, {close_task_event_stream, TaskId, Reason}, ?STATE_ACTIVATED, State = #state{socket = Socket}) ->
EventPacket = message_pb:encode_msg(#'CastFrame'{
body = {event_stream, #'TaskEventStream'{task_id = TaskId, type = <<"close">>, stream = Reason}}
body = {task_event, #'CastFrame.TaskEvent'{task_id = TaskId, type = <<"close">>, stream = Reason}}
}),
send_packet(Socket, <<?FRAME_CAST, EventPacket/binary>>),
{keep_state, State};
@ -197,16 +197,16 @@ handle_event(internal, {decoded_request, #'RequestFrame'{packet_id = PacketId, b
send_error_reply(Socket, PacketId, <<"agent state invalid">>),
{keep_state, State};
handle_event(internal, {decoded_reply, #'ReplyFrame'{packet_id = AuthPacketId, reply = {result, #'ReplyResult'{data = Message}}}},
handle_event(internal, {decoded_reply, #'ReplyFrame'{packet_id = AuthPacketId, reply = {result, Message}}},
?STATE_AUTH, State = #state{auth_packet_id = AuthPacketId}) ->
logger:debug("[efka_client] auth success, message: ~p", [Message]),
{next_state, ?STATE_ACTIVATED, State, [{next_event, info, flush_cache}]};
handle_event(internal, {decoded_reply, #'ReplyFrame'{packet_id = AuthPacketId, reply = {error, #'ReplyError'{code = 1, message = Message}}}},
handle_event(internal, {decoded_reply, #'ReplyFrame'{packet_id = AuthPacketId, reply = {error, #'ReplyFrame.Error'{code = 1, message = Message}}}},
?STATE_AUTH, State = #state{auth_packet_id = AuthPacketId}) ->
logger:debug("[efka_client] auth denied, message: ~p", [Message]),
{next_state, ?STATE_RESTRICTED, State};
handle_event(internal, {decoded_reply, #'ReplyFrame'{packet_id = AuthPacketId, reply = {error, #'ReplyError'{message = Message}}}},
handle_event(internal, {decoded_reply, #'ReplyFrame'{packet_id = AuthPacketId, reply = {error, #'ReplyFrame.Error'{message = Message}}}},
?STATE_AUTH, State = #state{socket = Socket, auth_packet_id = AuthPacketId}) ->
logger:debug("[efka_client] auth failed, message: ~p", [Message]),
disconnect(Socket),
@ -217,7 +217,7 @@ handle_event(internal, {decoded_reply, ReplyFrame}, StateName, State) ->
{keep_state, State};
%%
handle_event(internal, {decoded_cast, #'CastFrame'{body = {command, #'Command'{command_type = ?COMMAND_AUTH, command = Auth0}}}},
handle_event(internal, {decoded_cast, #'CastFrame'{body = {command, #'CastFrame.Command'{command_type = ?COMMAND_AUTH, command = Auth0}}}},
StateName, State = #state{socket = Socket, next_packet_id = PacketId}) ->
Auth = binary_to_integer(Auth0),
@ -235,7 +235,7 @@ handle_event(internal, {decoded_cast, #'CastFrame'{body = {command, #'Command'{c
end;
%% Pub/Sub机制
handle_event(internal, {decoded_cast, #'CastFrame'{body = {pub, #'Pub'{topic = Topic, qos = Qos, content = Content}}}}, ?STATE_ACTIVATED, State) ->
handle_event(internal, {decoded_cast, #'CastFrame'{body = {pub, #'CastFrame.Pub'{topic = Topic, qos = Qos, content = Content}}}}, ?STATE_ACTIVATED, State) ->
logger:debug("[efka_client] get pub topic: ~p, qos: ~p, content: ~p", [Topic, Qos, Content]),
efka_subscription:publish(Topic, Qos, Content),
{keep_state, State};
@ -307,7 +307,7 @@ schedule_reconnect() ->
send_result_reply(Socket, PacketId, Payload) when is_binary(Payload) ->
Packet = message_pb:encode_msg(#'ReplyFrame'{
packet_id = PacketId,
reply = {result, #'ReplyResult'{data = Payload}}
reply = {result, Payload}
}),
send_packet(Socket, Packet).
@ -315,6 +315,6 @@ send_result_reply(Socket, PacketId, Payload) when is_binary(Payload) ->
send_error_reply(Socket, PacketId, Reason) when is_binary(Reason) ->
Packet = message_pb:encode_msg(#'ReplyFrame'{
packet_id = PacketId,
reply = {error, #'ReplyError'{code = -1, message = Reason}}
reply = {error, #'ReplyFrame.Error'{code = -1, message = Reason}}
}),
send_packet(Socket, Packet).