fix message codec
This commit is contained in:
parent
5d7530b756
commit
894cba6c02
@ -74,18 +74,10 @@
|
|||||||
}).
|
}).
|
||||||
|
|
||||||
-record(data, {
|
-record(data, {
|
||||||
service_id :: binary(),
|
|
||||||
device_uuid :: binary(),
|
|
||||||
route_key :: binary(),
|
route_key :: binary(),
|
||||||
metric :: binary()
|
metric :: binary()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-record(event, {
|
|
||||||
service_id :: binary(),
|
|
||||||
event_type :: integer(),
|
|
||||||
params :: binary()
|
|
||||||
}).
|
|
||||||
|
|
||||||
-record(task_event_stream, {
|
-record(task_event_stream, {
|
||||||
task_id :: integer(),
|
task_id :: integer(),
|
||||||
type :: binary(),
|
type :: binary(),
|
||||||
|
|||||||
@ -59,19 +59,11 @@ encode0(#jsonrpc_request{method = Method, params = Params}) ->
|
|||||||
iolist_to_binary([
|
iolist_to_binary([
|
||||||
marshal(?Bytes, ReqBody)
|
marshal(?Bytes, ReqBody)
|
||||||
]);
|
]);
|
||||||
encode0(#data{service_id = ServiceId, device_uuid = DeviceUUID, route_key = RouteKey, metric = Metric}) ->
|
encode0(#data{route_key = RouteKey, metric = Metric}) ->
|
||||||
iolist_to_binary([
|
iolist_to_binary([
|
||||||
marshal(?Bytes, ServiceId),
|
|
||||||
marshal(?Bytes, DeviceUUID),
|
|
||||||
marshal(?Bytes, RouteKey),
|
marshal(?Bytes, RouteKey),
|
||||||
marshal(?Bytes, Metric)
|
marshal(?Bytes, Metric)
|
||||||
]);
|
]);
|
||||||
encode0(#event{service_id = ServiceId, event_type = EventType, params = Params}) ->
|
|
||||||
iolist_to_binary([
|
|
||||||
marshal(?Bytes, ServiceId),
|
|
||||||
marshal(?I32, EventType),
|
|
||||||
marshal(?Bytes, Params)
|
|
||||||
]);
|
|
||||||
encode0(#task_event_stream{task_id = TaskId, type = Type, stream = Stream}) ->
|
encode0(#task_event_stream{task_id = TaskId, type = Type, stream = Stream}) ->
|
||||||
iolist_to_binary([
|
iolist_to_binary([
|
||||||
marshal(?I32, TaskId),
|
marshal(?I32, TaskId),
|
||||||
@ -107,10 +99,8 @@ decode0(?MESSAGE_AUTH_REPLY, [Code, Payload]) ->
|
|||||||
decode0(?MESSAGE_JSONRPC_REQUEST, [ReqBody]) ->
|
decode0(?MESSAGE_JSONRPC_REQUEST, [ReqBody]) ->
|
||||||
#{<<"method">> := Method, <<"params">> := Params} = erlang:binary_to_term(ReqBody),
|
#{<<"method">> := Method, <<"params">> := Params} = erlang:binary_to_term(ReqBody),
|
||||||
{ok, #jsonrpc_request{method = Method, params = Params}};
|
{ok, #jsonrpc_request{method = Method, params = Params}};
|
||||||
decode0(?MESSAGE_DATA, [ServiceId, DeviceUUID, RouteKey, Metric]) ->
|
decode0(?MESSAGE_DATA, [RouteKey, Metric]) ->
|
||||||
{ok, #data{service_id = ServiceId, device_uuid = DeviceUUID, route_key = RouteKey, metric = Metric}};
|
{ok, #data{route_key = RouteKey, metric = Metric}};
|
||||||
decode0(?MESSAGE_EVENT, [ServiceId, EventType, Params]) ->
|
|
||||||
{ok, #event{service_id = ServiceId, event_type = EventType, params = Params}};
|
|
||||||
decode0(?MESSAGE_EVENT_STREAM, [TaskId, Type, Stream]) ->
|
decode0(?MESSAGE_EVENT_STREAM, [TaskId, Type, Stream]) ->
|
||||||
{ok, #task_event_stream{task_id = TaskId, type = Type, stream = Stream}};
|
{ok, #task_event_stream{task_id = TaskId, type = Type, stream = Stream}};
|
||||||
decode0(_, _) ->
|
decode0(_, _) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user