fix codec
This commit is contained in:
parent
2a138da787
commit
8004046136
@ -136,7 +136,7 @@ do_post(Path, Params) when is_list(Path), is_map(Params) ->
|
|||||||
case hackney:request(post, Url, Headers, Body, [{pool, false}]) of
|
case hackney:request(post, Url, Headers, Body, [{pool, false}]) of
|
||||||
{ok, 200, _, ClientRef} ->
|
{ok, 200, _, ClientRef} ->
|
||||||
{ok, RespBody} = hackney:body(ClientRef),
|
{ok, RespBody} = hackney:body(ClientRef),
|
||||||
lager:debug("[iot_api] request url: ~p, send body: ~p, get error is: ~p", [Url, Body, RespBody]),
|
lager:debug("[iot_api] request url: ~p, send body: ~p, get response is: ~p", [Url, Body, RespBody]),
|
||||||
hackney:close(ClientRef),
|
hackney:close(ClientRef),
|
||||||
case catch jiffy:decode(RespBody, [return_maps]) of
|
case catch jiffy:decode(RespBody, [return_maps]) of
|
||||||
#{<<"result">> := Result} ->
|
#{<<"result">> := Result} ->
|
||||||
|
|||||||
@ -35,10 +35,14 @@ encode0(#auth_reply{code = Code, payload = Payload}) ->
|
|||||||
]);
|
]);
|
||||||
encode0(#jsonrpc_reply{result = Result, error = undefined}) ->
|
encode0(#jsonrpc_reply{result = Result, error = undefined}) ->
|
||||||
ResultBin = erlang:term_to_binary(#{<<"result">> => Result}),
|
ResultBin = erlang:term_to_binary(#{<<"result">> => Result}),
|
||||||
iolist_to_binary([marshal(?Bytes, ResultBin)]);
|
iolist_to_binary([
|
||||||
|
marshal(?Bytes, ResultBin)
|
||||||
|
]);
|
||||||
encode0(#jsonrpc_reply{result = undefined, error = Error}) ->
|
encode0(#jsonrpc_reply{result = undefined, error = Error}) ->
|
||||||
ResultBin = erlang:term_to_binary(#{<<"error">> => Error}),
|
ResultBin = erlang:term_to_binary(#{<<"error">> => Error}),
|
||||||
iolist_to_binary([marshal(?Bytes, ResultBin)]);
|
iolist_to_binary([
|
||||||
|
marshal(?Bytes, ResultBin)
|
||||||
|
]);
|
||||||
encode0(#pub{topic = Topic, content = Content}) ->
|
encode0(#pub{topic = Topic, content = Content}) ->
|
||||||
iolist_to_binary([
|
iolist_to_binary([
|
||||||
marshal(?Bytes, Topic),
|
marshal(?Bytes, Topic),
|
||||||
@ -52,7 +56,9 @@ encode0(#command{command_type = CommandType, command = Command}) ->
|
|||||||
|
|
||||||
encode0(#jsonrpc_request{method = Method, params = Params}) ->
|
encode0(#jsonrpc_request{method = Method, params = Params}) ->
|
||||||
ReqBody = erlang:term_to_binary(#{<<"method">> => Method, <<"params">> => Params}),
|
ReqBody = erlang:term_to_binary(#{<<"method">> => Method, <<"params">> => Params}),
|
||||||
marshal(?Bytes, ReqBody);
|
iolist_to_binary([
|
||||||
|
marshal(?Bytes, ReqBody)
|
||||||
|
]);
|
||||||
encode0(#data{service_id = ServiceId, device_uuid = DeviceUUID, route_key = RouteKey, metric = Metric}) ->
|
encode0(#data{service_id = ServiceId, device_uuid = DeviceUUID, route_key = RouteKey, metric = Metric}) ->
|
||||||
iolist_to_binary([
|
iolist_to_binary([
|
||||||
marshal(?Bytes, ServiceId),
|
marshal(?Bytes, ServiceId),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user