From 58d851a0f1c5a41c4e88c07ab6f48894a4fa2454 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Sun, 3 May 2026 16:29:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=8E=89jiffy=E7=9A=84?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rebar.config | 1 - src/http/http_protocol.erl | 2 +- src/policy/maxwell_redis_channel.erl | 2 +- src/sdlan.app.src | 1 - src/sdlan_api.erl | 12 ++++++------ src/sdlan_util.erl | 4 ++-- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/rebar.config b/rebar.config index e8126d0..b19e7d3 100644 --- a/rebar.config +++ b/rebar.config @@ -26,7 +26,6 @@ {deps, [ {poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}}, {hackney, ".*", {git, "https://github.com/benoitc/hackney.git", {tag, "1.16.0"}}}, - {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "1.1.1"}}}, {cowboy, ".*", {git, "https://github.com/ninenines/cowboy.git", {tag, "2.12.0"}}}, {mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp", {tag, "1.8.0"}}}, {throttle, ".*", {git, "https://github.com/lambdaclass/throttle.git", {tag, "0.3.0"}}}, diff --git a/src/http/http_protocol.erl b/src/http/http_protocol.erl index b01a687..9e14724 100644 --- a/src/http/http_protocol.erl +++ b/src/http/http_protocol.erl @@ -66,7 +66,7 @@ parse_body(Req0) -> {ok, Body, Req1} = read_body(Req0), case Body /= <<>> of true -> - {ok, catch jiffy:decode(Body, [return_maps]), Req1}; + {ok, catch json:decode(Body), Req1}; false -> {ok, #{}, Req1} end; diff --git a/src/policy/maxwell_redis_channel.erl b/src/policy/maxwell_redis_channel.erl index 5362f78..4b8adb6 100644 --- a/src/policy/maxwell_redis_channel.erl +++ b/src/policy/maxwell_redis_channel.erl @@ -60,7 +60,7 @@ handle_command([<<"PING">>]) -> {reply, encode({single_line, <<"PONG">>})}; handle_command([<<"PUBLISH">>, _Channel, Msg]) -> - case catch jiffy:decode(Msg, [return_maps]) of + case catch json:decode(Msg) of M when is_map(M) -> handle_data(M); _ -> diff --git a/src/sdlan.app.src b/src/sdlan.app.src index 3b454ab..80128c4 100644 --- a/src/sdlan.app.src +++ b/src/sdlan.app.src @@ -10,7 +10,6 @@ ranch, poolboy, mysql, - jiffy, hackney, throttle, dns_erlang, diff --git a/src/sdlan_api.erl b/src/sdlan_api.erl index 363ebc5..78c55d8 100644 --- a/src/sdlan_api.erl +++ b/src/sdlan_api.erl @@ -121,13 +121,13 @@ safe_request(Fun) when is_function(Fun, 0) -> -spec decode_json(Resp :: binary()) -> {ok, map()} | {error, any()}. decode_json(Resp) when is_binary(Resp) -> - case catch jiffy:decode(Resp, [return_maps]) of + try json:decode(Resp) of Result when is_map(Result) -> {ok, Result}; - {'EXIT', Reason} -> - {error, Reason}; - Error -> - {error, Error} + Other -> + {error, {invalid_json, Other}} + catch error:Reason -> + {error, Reason} end. -spec do_get(Uri :: string(), Params :: [{K :: binary(), V :: binary()}]) -> {ok, Response :: binary()} | {error, Reason :: any()}. @@ -165,7 +165,7 @@ do_post(Uri, Params) when is_list(Uri), is_map(Params) -> {<<"X-sign">>, sign_params(Params)} ], - Body = iolist_to_binary(jiffy:encode(Params, [force_utf8])), + Body = iolist_to_binary(json:encode(Params)), Url = Url0 ++ Uri, case catch hackney:request(post, Url, Headers, Body, [{pool, false}]) of diff --git a/src/sdlan_util.erl b/src/sdlan_util.erl index 95f2860..c675acf 100644 --- a/src/sdlan_util.erl +++ b/src/sdlan_util.erl @@ -63,11 +63,11 @@ hex0(I) -> $0 + I. -spec json_data(Data :: term()) -> iodata(). json_data(Data) -> - jiffy:encode(#{<<"result">> => Data}, [force_utf8]). + json:encode(#{<<"result">> => Data}). -spec json_error(ErrCode :: integer(), ErrMessage :: binary()) -> iodata(). json_error(ErrCode, ErrMessage) when is_integer(ErrCode), is_binary(ErrMessage) -> - jiffy:encode(#{<<"error">> => #{<<"code">> => ErrCode, <<"message">> => ErrMessage}}, [force_utf8]). + json:encode(#{<<"error">> => #{<<"code">> => ErrCode, <<"message">> => ErrMessage}}). -spec assert_call(Condition :: boolean(), F :: fun(() -> T)) -> T | ok. assert_call(true, F) ->