From 80040461362f8a9dd5fbcce216e36b54f6c47344 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Thu, 13 Nov 2025 18:07:56 +0800 Subject: [PATCH] fix codec --- apps/iot/src/iot_api.erl | 2 +- apps/iot/src/message/message_codec.erl | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/iot/src/iot_api.erl b/apps/iot/src/iot_api.erl index 20969ab..a986f7a 100644 --- a/apps/iot/src/iot_api.erl +++ b/apps/iot/src/iot_api.erl @@ -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 {ok, 200, _, 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), case catch jiffy:decode(RespBody, [return_maps]) of #{<<"result">> := Result} -> diff --git a/apps/iot/src/message/message_codec.erl b/apps/iot/src/message/message_codec.erl index 085d63e..643242c 100644 --- a/apps/iot/src/message/message_codec.erl +++ b/apps/iot/src/message/message_codec.erl @@ -35,10 +35,14 @@ encode0(#auth_reply{code = Code, payload = Payload}) -> ]); encode0(#jsonrpc_reply{result = Result, error = undefined}) -> 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}) -> 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}) -> iolist_to_binary([ marshal(?Bytes, Topic), @@ -52,7 +56,9 @@ encode0(#command{command_type = CommandType, command = Command}) -> encode0(#jsonrpc_request{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}) -> iolist_to_binary([ marshal(?Bytes, ServiceId),