You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by dl...@apache.org on 2019/06/26 11:31:33 UTC

[dubbo-erlang] branch master updated: change json dependence lib to jsx

This is an automated email from the ASF dual-hosted git repository.

dlive pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-erlang.git


The following commit(s) were added to refs/heads/master by this push:
     new 0605b63  change json dependence lib to jsx
0605b63 is described below

commit 0605b630583a12d102da63eee3712b50a0c984f6
Author: DLive <xs...@163.com>
AuthorDate: Wed Jun 26 19:29:28 2019 +0800

    change json dependence lib to jsx
---
 rebar.config                 |  2 +-
 rebar.lock                   |  4 ++--
 src/dubbo_serializa_json.erl | 30 +++++++++++++-----------------
 3 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/rebar.config b/rebar.config
index aebfaa3..0cf9acd 100644
--- a/rebar.config
+++ b/rebar.config
@@ -23,7 +23,7 @@
     {erlzk, ".*", {git, "https://github.com/huaban/erlzk.git", {tag, "v0.6.2"}}},
     {ranch, ".*",  {git, "https://github.com/ninenines/ranch.git", {tag, "1.4.0"}}},
     {poolboy, ".*",  {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}},
-    {jiffy, "0.15.1"}
+	{jsx, "2.10.0"}
 ]}.
 
 
diff --git a/rebar.lock b/rebar.lock
index f57b258..f188a62 100644
--- a/rebar.lock
+++ b/rebar.lock
@@ -3,7 +3,7 @@
   {git,"https://github.com/huaban/erlzk.git",
        {ref,"aa7190ee2343ac1341cea3edc9b9eea36c591708"}},
   0},
- {<<"jiffy">>,{pkg,<<"jiffy">>,<<"0.15.1">>},0},
+ {<<"jsx">>,{pkg,<<"jsx">>,<<"2.10.0">>},0},
  {<<"poolboy">>,
   {git,"https://github.com/devinus/poolboy.git",
        {ref,"3bb48a893ff5598f7c73731ac17545206d259fac"}},
@@ -14,5 +14,5 @@
   0}]}.
 [
 {pkg_hash,[
- {<<"jiffy">>, <<"BE83B09388DA1A6C7E798207C9D6A1C4D71BB95FCC387D37D35861788F49AB97">>}]}
+ {<<"jsx">>, <<"77760560D6AC2B8C51FD4C980E9E19B784016AA70BE354CE746472C33BEB0B1C">>}]}
 ].
diff --git a/src/dubbo_serializa_json.erl b/src/dubbo_serializa_json.erl
index b18197a..d6825e1 100644
--- a/src/dubbo_serializa_json.erl
+++ b/src/dubbo_serializa_json.erl
@@ -48,12 +48,12 @@ encode_request_data(dubbo_rpc_invocation, _Request, Data, State) ->
         ?LINE_SEPERATOR
     ],
     {ArgsBin, _} = encode_arguments(Data, State),
-    AttachBinay = jiffy:encode({Data#dubbo_rpc_invocation.attachments}, []),
+    AttachBinay = jsx:encode(Data#dubbo_rpc_invocation.attachments),
     RequestData = erlang:iolist_to_binary(RequestList ++ [ArgsBin, AttachBinay, ?LINE_SEPERATOR]),
     {ok, RequestData};
 encode_request_data(dubbo_event, _Request, Data, _State) ->
     %% @todo 确认该数据类型
-    Bin = jiffy:encode(Data),
+    Bin = jsx:encode(Data),
     {ok, Bin}.
 
 
@@ -74,7 +74,7 @@ encode_response_data(Response) ->
     {ok, Bin}.
 
 encode_response_data(dubbo_event, _Response, Data, State) ->
-    Bin = jiffy:encode(Data, []),
+    Bin = jsx:encode(Data),
     {ok, Bin};
 encode_response_data(dubbo_rpc_invocation, _Response, Data, State) ->
     Result = case Data of
@@ -156,19 +156,19 @@ decode_response(dubbo_rpc_invocation, Res, Data) ->
     DataList = binary:split(Data, <<"\n">>, [global]),
     [TypeBin | DataList1] = DataList,
 %%    {Rest,Type,State} = cotton_hessian:decode(Data,cotton_hessian:init()),
-    Type = jiffy:decode(TypeBin),
+    Type = jsx:decode(TypeBin),
 
     case Type of
         ?RESPONSE_VALUE ->
 %%            {_,Object,DecodeState} = cotton_hessian:decode(Rest,State),
             [Value | _] = DataList1,
-            Object = jiffy:decode(Value, [return_maps]),
+            Object = jsx:decode(Value, [return_maps]),
             {ok, Res#dubbo_response{data = Object}};
         ?RESPONSE_NULL_VALUE ->
             {ok, Res#dubbo_response{data = null}};
         ?RESPONSE_WITH_EXCEPTION ->
             [ExceptionValue | _] = DataList1,
-            ExceptionObject = jiffy:decode(ExceptionValue),
+            ExceptionObject = jsx:decode(ExceptionValue),
             {ok, Res#dubbo_response{data = ExceptionObject}};
         Other ->
             logger:error("server response unkonw info ~p", [Other]),
@@ -196,10 +196,8 @@ decode_request(dubbo_rpc_invocation, Req, Data) ->
     {ok, Req2};
 
 decode_request(dubbo_event, Req, Data) ->
-%%    DataList = binary:split(Data,<<"\n">>),
     logger:debug("dubbo_event datalist ~w", [Data]),
-    Result = jiffy:decode(Data, []),
-%%    {_Rest,undefined,_NewState} = cotton_hessian:decode(Data,cotton_hessian:init()),
+    Result = jsx:decode(Data),
     {ok, Req#dubbo_request{data = Result}}.
 
 decode_request_body(Data, State, List) ->
@@ -217,13 +215,11 @@ decode_request_body(Data, State, List) ->
 
 decode_request_body([ParseType | List], [DataItem | Data], State, ResultList)
     when ParseType == dubbo;ParseType == path;ParseType == version;ParseType == method_name ->
-    DecodeData = jiffy:decode(DataItem, [return_maps]),
+    DecodeData = jsx:decode(DataItem, [return_maps]),
     decode_request_body(List, Data, State, [DecodeData] ++ ResultList);
 
 decode_request_body([desc_and_args | List], [DescBin | Data], State, ResultList) ->
-    ParameterDesc = jiffy:decode(DescBin, []),
-
-%%    {Rest,ParameterDesc,State1 } = cotton_hessian:decode(Data,State),
+    ParameterDesc = jsx:decode(DescBin),
     if
         size(ParameterDesc) == 0 ->
             decode_request_body(List, Data, State, [[], []] ++ ResultList);
@@ -233,7 +229,7 @@ decode_request_body([desc_and_args | List], [DescBin | Data], State, ResultList)
             decode_request_body(List, RestData, NewState, [ArgsObjList, ParameterDesc] ++ ResultList)
     end;
 decode_request_body([attachments | List], [DataItem | Data], State, ResultList) ->
-    Attachments = jiffy:decode(DataItem, [return_maps]),
+    Attachments = jsx:decode(DataItem, [return_maps]),
 %%    AttachmentsList = dict:to_list(Attachments#map.dict),
     decode_request_body(List, Data, State, [Attachments] ++ ResultList);
 decode_request_body([_Type1 | List], Data, State, ResultList) ->
@@ -250,7 +246,7 @@ decode_request_body_args([ArgsType | RestList], Data, State, ArgsObjList) when A
     decode_request_body_args(RestList, Data, State, ArgsObjList);
 
 decode_request_body_args([ArgsType | RestList], [DataItem | Data], State, ArgsObjList) ->
-    ArgObj = jiffy:decode(DataItem, [return_maps]),
+    ArgObj = jsx:decode(DataItem, [return_maps]),
 %%    {Rest,ArgObj,NewState } = cotton_hessian:decode(Data,State),
     ArgObj2 = dubbo_type_transfer:jsonobj_to_native(ArgsType, ArgObj, State),
     decode_request_body_args(RestList, Data, State, ArgsObjList ++ [ArgObj2]).
@@ -270,8 +266,8 @@ string_encode(Data) when is_tuple(Data) ->
                 fun({I, E}, Acc) ->
                     Acc#{E => element(I, Data)}
                 end, #{}, lists:zip(lists:seq(2, length(Fields) + 1), Fields)),
-            jiffy:encode(MapValue)
+            jsx:encode(MapValue)
     end;
 
 string_encode(Data) ->
-    jiffy:encode(Data).
+    jsx:encode(Data).