Merge pull request #8677 from JimMoen/fix-mqtt-bridge-message-sizer

fix: count all msg size of `event_message` for mqtt bridge
This commit is contained in:
Xinyu Liu 2022-08-12 09:38:11 +08:00 committed by GitHub
commit 62c5f902d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -142,11 +142,14 @@ from_binary(Bin) -> binary_to_term(Bin).
%% @doc Estimate the size of a message.
%% Count only the topic length + payload size
%% There is no topic and payload for event message. So count all `Msg` term
-spec estimate_size(msg()) -> integer().
estimate_size(#message{topic = Topic, payload = Payload}) ->
size(Topic) + size(Payload);
estimate_size(#{topic := Topic, payload := Payload}) ->
size(Topic) + size(Payload).
size(Topic) + size(Payload);
estimate_size(Term) ->
erlang:external_size(Term).
set_headers(undefined, Msg) ->
Msg;