Reduce notification nesting, at 'continue' result

This commit is contained in:
Ulf Wiger 2025-04-10 09:09:12 +02:00
parent abb1bef2b6
commit 6fd678b420

View File

@ -150,7 +150,7 @@ decode(MsgBin, ?PROTOCOL_JSON, Vsn) ->
#{ <<"method">> := Method #{ <<"method">> := Method
, <<"params">> := Params } -> , <<"params">> := Params } ->
%% JSON-RPC notification %% JSON-RPC notification
#{ notification => #{ msg => validate(decode_msg_(Method, Params), Vsn) }}; #{ notification => validate(decode_msg_(Method, Params), Vsn) };
#{ <<"id">> := Id #{ <<"id">> := Id
, <<"result">> := Result } -> , <<"result">> := Result } ->
#{ reply => #{ id => Id #{ reply => #{ id => Id
@ -167,7 +167,7 @@ decode(MsgBin, ?PROTOCOL_JSON, Vsn) ->
encode(#{call := Req0}, P, V) -> encode(#{call := Req0}, P, V) ->
{Id, Req} = maps:take(id, Req0), {Id, Req} = maps:take(id, Req0),
encode_request(Req, Id, P, V); encode_request(Req, Id, P, V);
encode(#{notification := #{msg := Msg}}, P, V) -> encode(#{notification := Msg}, P, V) ->
encode_msg(Msg, P, V); encode_msg(Msg, P, V);
encode(#{reply := Reply0}, P, V) when is_map(Reply0) -> encode(#{reply := Reply0}, P, V) when is_map(Reply0) ->
{Id, Reply} = maps:take(id, Reply0), {Id, Reply} = maps:take(id, Reply0),
@ -204,7 +204,11 @@ encode_reply(Reply, Id, ?PROTOCOL_JSON, _Vsn) ->
ok -> ok ->
#{ <<"jsonrpc">> => <<"2.0">> #{ <<"jsonrpc">> => <<"2.0">>
, <<"id">> => Id , <<"id">> => Id
, <<"result">> => <<"ok">> } , <<"result">> => <<"ok">> };
continue ->
#{ <<"jsonrpc">> => <<"2.0">>
, <<"id">> => Id
, <<"result">> => <<"continue">> }
end, end,
json_encode(Msg). json_encode(Msg).
@ -231,6 +235,7 @@ error_code(unknown_method ) -> -32601;
error_code(_ ) -> -32603. % internal error error_code(_ ) -> -32603. % internal error
decode_result(<<"ok">>, _) -> ok; decode_result(<<"ok">>, _) -> ok;
decode_result(<<"continue">>, _) -> continue;
decode_result(#{<<"connect_ack">> := #{ <<"protocol">> := P decode_result(#{<<"connect_ack">> := #{ <<"protocol">> := P
, <<"version">> := V }}, Vsn) -> , <<"version">> := V }}, Vsn) ->
Msg = #{connect_ack => #{ protocol => P Msg = #{connect_ack => #{ protocol => P