fix 'undefined' msgid
This commit is contained in:
parent
6d5ce1f584
commit
2b45dbf09f
|
@ -28,27 +28,19 @@
|
|||
|
||||
-export([format/1]).
|
||||
|
||||
%% @doc Make a message
|
||||
-spec(make(From, Topic, Payload) -> mqtt_message() when
|
||||
From :: atom() | binary(),
|
||||
Topic :: binary(),
|
||||
Payload :: binary()).
|
||||
make(From, Topic, Payload) ->
|
||||
#mqtt_message{topic = Topic,
|
||||
from = From,
|
||||
payload = Payload,
|
||||
timestamp = os:timestamp()}.
|
||||
-type(msg_from() :: atom() | {binary(), undefined | binary()}).
|
||||
|
||||
-spec(make(From, Qos, Topic, Payload) -> mqtt_message() when
|
||||
From :: atom() | binary(),
|
||||
Qos :: mqtt_qos() | mqtt_qos_name(),
|
||||
Topic :: binary(),
|
||||
Payload :: binary()).
|
||||
%% @doc Make a message
|
||||
-spec(make(msg_from(), binary(), binary()) -> mqtt_message()).
|
||||
make(From, Topic, Payload) ->
|
||||
make(From, ?QOS_0, Topic, Payload).
|
||||
|
||||
-spec(make(msg_from(), mqtt_qos(), binary(), binary()) -> mqtt_message()).
|
||||
make(From, Qos, Topic, Payload) ->
|
||||
#mqtt_message{msgid = msgid(?QOS_I(Qos)),
|
||||
topic = Topic,
|
||||
#mqtt_message{msgid = msgid(),
|
||||
from = From,
|
||||
qos = ?QOS_I(Qos),
|
||||
topic = Topic,
|
||||
payload = Payload,
|
||||
timestamp = os:timestamp()}.
|
||||
|
||||
|
@ -61,7 +53,7 @@ from_packet(#mqtt_packet{header = #mqtt_packet_header{type = ?PUBLISH,
|
|||
variable = #mqtt_packet_publish{topic_name = Topic,
|
||||
packet_id = PacketId},
|
||||
payload = Payload}) ->
|
||||
#mqtt_message{msgid = msgid(Qos),
|
||||
#mqtt_message{msgid = msgid(),
|
||||
pktid = PacketId,
|
||||
qos = Qos,
|
||||
retain = Retain,
|
||||
|
@ -79,7 +71,7 @@ from_packet(#mqtt_packet_connect{client_id = ClientId,
|
|||
will_qos = Qos,
|
||||
will_topic = Topic,
|
||||
will_msg = Msg}) ->
|
||||
#mqtt_message{msgid = msgid(Qos),
|
||||
#mqtt_message{msgid = msgid(),
|
||||
topic = Topic,
|
||||
from = {ClientId, Username},
|
||||
retain = Retain,
|
||||
|
@ -96,10 +88,7 @@ from_packet(Username, ClientId, Packet) ->
|
|||
Msg = from_packet(Packet),
|
||||
Msg#mqtt_message{from = {ClientId, Username}}.
|
||||
|
||||
msgid(?QOS_0) ->
|
||||
undefined;
|
||||
msgid(Qos) when Qos =:= ?QOS_1 orelse Qos =:= ?QOS_2 ->
|
||||
emqttd_guid:gen().
|
||||
msgid() -> emqttd_guid:gen().
|
||||
|
||||
%% @doc Message to packet
|
||||
-spec(to_packet(mqtt_message()) -> mqtt_packet()).
|
||||
|
|
Loading…
Reference in New Issue