From 6fd678b42026a7c3b0d62165d93e6b1dd99f345a Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 10 Apr 2025 09:09:12 +0200 Subject: [PATCH] Reduce notification nesting, at 'continue' result --- src/gmmpp_msgs.erl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gmmpp_msgs.erl b/src/gmmpp_msgs.erl index 45c8785..fadfb5e 100644 --- a/src/gmmpp_msgs.erl +++ b/src/gmmpp_msgs.erl @@ -150,7 +150,7 @@ decode(MsgBin, ?PROTOCOL_JSON, Vsn) -> #{ <<"method">> := Method , <<"params">> := Params } -> %% JSON-RPC notification - #{ notification => #{ msg => validate(decode_msg_(Method, Params), Vsn) }}; + #{ notification => validate(decode_msg_(Method, Params), Vsn) }; #{ <<"id">> := Id , <<"result">> := Result } -> #{ reply => #{ id => Id @@ -167,7 +167,7 @@ decode(MsgBin, ?PROTOCOL_JSON, Vsn) -> encode(#{call := Req0}, P, V) -> {Id, Req} = maps:take(id, Req0), encode_request(Req, Id, P, V); -encode(#{notification := #{msg := Msg}}, P, V) -> +encode(#{notification := Msg}, P, V) -> encode_msg(Msg, P, V); encode(#{reply := Reply0}, P, V) when is_map(Reply0) -> {Id, Reply} = maps:take(id, Reply0), @@ -204,7 +204,11 @@ encode_reply(Reply, Id, ?PROTOCOL_JSON, _Vsn) -> ok -> #{ <<"jsonrpc">> => <<"2.0">> , <<"id">> => Id - , <<"result">> => <<"ok">> } + , <<"result">> => <<"ok">> }; + continue -> + #{ <<"jsonrpc">> => <<"2.0">> + , <<"id">> => Id + , <<"result">> => <<"continue">> } end, json_encode(Msg). @@ -231,6 +235,7 @@ error_code(unknown_method ) -> -32601; error_code(_ ) -> -32603. % internal error decode_result(<<"ok">>, _) -> ok; +decode_result(<<"continue">>, _) -> continue; decode_result(#{<<"connect_ack">> := #{ <<"protocol">> := P , <<"version">> := V }}, Vsn) -> Msg = #{connect_ack => #{ protocol => P