misc fix
This commit is contained in:
parent
aab6dcf8d1
commit
6907d4feed
|
@ -1,7 +1,7 @@
|
|||
{application, emqtt,
|
||||
[
|
||||
{description, "Erlang MQTT Common Library"},
|
||||
{vsn, "0.6.0"},
|
||||
{description, "Erlang Common MQTT Library"},
|
||||
{vsn, "0.6.1"},
|
||||
{modules, []},
|
||||
{registered, []},
|
||||
{applications, [
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
%%% SOFTWARE.
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%% @doc
|
||||
%%% MQTT Message.
|
||||
%%% MQTT Message Functions
|
||||
%%%
|
||||
%%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
-module(emqtt_message).
|
||||
|
||||
-author('feng@emqtt.io').
|
||||
-author("Feng Lee <feng@emqtt.io>").
|
||||
|
||||
-include("emqtt.hrl").
|
||||
|
||||
|
@ -39,9 +39,7 @@
|
|||
-export([format/1]).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Message from Packet.
|
||||
%%
|
||||
%% @doc Message from Packet
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec from_packet(mqtt_packet()) -> mqtt_message().
|
||||
|
@ -73,9 +71,7 @@ from_packet(#mqtt_packet_connect{will_retain = Retain,
|
|||
payload = Msg}.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Message to packet
|
||||
%%
|
||||
%% @doc Message to packet
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec to_packet(mqtt_message()) -> mqtt_packet().
|
||||
|
@ -100,9 +96,7 @@ to_packet(#mqtt_message{msgid = MsgId,
|
|||
payload = Payload}.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% set dup, retain flag
|
||||
%%
|
||||
%% @doc set dup, retain flag
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec set_flag(mqtt_message()) -> mqtt_message().
|
||||
|
@ -118,9 +112,7 @@ set_flag(Flag, Msg) when Flag =:= dup orelse Flag =:= retain -> Msg.
|
|||
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Unset dup, retain flag
|
||||
%%
|
||||
%% @doc Unset dup, retain flag
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec unset_flag(mqtt_message()) -> mqtt_message().
|
||||
|
@ -135,9 +127,7 @@ unset_flag(retain, Msg = #mqtt_message{retain = true}) ->
|
|||
unset_flag(Flag, Msg) when Flag =:= dup orelse Flag =:= retain -> Msg.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Format MQTT Message.
|
||||
%%
|
||||
%% @doc Format MQTT Message
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
format(#mqtt_message{msgid=MsgId, qos=Qos, retain=Retain, dup=Dup, topic=Topic}) ->
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
%%% SOFTWARE.
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%% @doc
|
||||
%%% MQTT packet utility functions.
|
||||
%%% MQTT Packet Functions
|
||||
%%%
|
||||
%%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
-module(emqtt_packet).
|
||||
|
||||
-author("feng@emqtt.io").
|
||||
-author("Feng Lee <feng@emqtt.io>").
|
||||
|
||||
-include("emqtt.hrl").
|
||||
|
||||
|
@ -38,21 +38,15 @@
|
|||
-export([format/1]).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Protocol name of version.
|
||||
%%
|
||||
%% @doc Protocol name of version
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec protocol_name(Ver) -> Name when
|
||||
Ver :: mqtt_vsn(),
|
||||
Name :: binary().
|
||||
-spec protocol_name(mqtt_vsn()) -> binary().
|
||||
protocol_name(Ver) when Ver =:= ?MQTT_PROTO_V31; Ver =:= ?MQTT_PROTO_V311->
|
||||
proplists:get_value(Ver, ?PROTOCOL_NAMES).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Name of MQTT packet type.
|
||||
%%
|
||||
%% @doc Name of MQTT packet type
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec type_name(mqtt_packet_type()) -> atom().
|
||||
|
@ -60,9 +54,7 @@ type_name(Type) when Type > ?RESERVED andalso Type =< ?DISCONNECT ->
|
|||
lists:nth(Type, ?TYPE_NAMES).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Connack Name.
|
||||
%%
|
||||
%% @doc Connack Name
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec connack_name(mqtt_connack()) -> atom().
|
||||
|
@ -74,9 +66,7 @@ connack_name(?CONNACK_CREDENTIALS) -> 'CONNACK_CREDENTIALS';
|
|||
connack_name(?CONNACK_AUTH) -> 'CONNACK_AUTH'.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Format packet.
|
||||
%%
|
||||
%% @doc Format packet
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec format(mqtt_packet()) -> iolist().
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
%%% SOFTWARE.
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%% @doc
|
||||
%%% emqtt packet parser.
|
||||
%%% MQTT Packet Parser.
|
||||
%%%
|
||||
%%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
-module(emqtt_parser).
|
||||
|
||||
-author("feng@emqtt.io").
|
||||
-author("Feng Lee <feng@emqtt.io>").
|
||||
|
||||
-include("emqtt.hrl").
|
||||
|
||||
|
@ -39,24 +39,20 @@
|
|||
|
||||
-type option() :: {atom(), any()}.
|
||||
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Initialize a parser.
|
||||
%%
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc Initialize a parser
|
||||
%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec init(Opts :: [option()]) -> {none, #mqtt_packet_limit{}}.
|
||||
init(Opts) -> {none, limit(Opts)}.
|
||||
|
||||
limit(Opts) ->
|
||||
#mqtt_packet_limit{max_packet_size = proplists:get_value(max_packet_size, Opts, ?MAX_LEN)}.
|
||||
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Parse MQTT Packet.
|
||||
%%
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc Parse MQTT Packet
|
||||
%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec parse(binary(), {none, [option()]} | fun()) -> {ok, mqtt_packet()} | {error, any()} | {more, fun()}.
|
||||
parse(<<>>, {none, Limit}) ->
|
||||
{more, fun(Bin) -> parse(Bin, {none, Limit}) end};
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
%%% SOFTWARE.
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%% @doc
|
||||
%%% emqtt packet serialiser.
|
||||
%%% MQTT Packet Serialiser.
|
||||
%%%
|
||||
%%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
-module(emqtt_serialiser).
|
||||
|
||||
-author("feng@emqtt.io").
|
||||
-author("Feng Lee <feng@emqtt.io>").
|
||||
|
||||
-include("emqtt.hrl").
|
||||
|
||||
|
@ -36,9 +36,7 @@
|
|||
-export([serialise/1]).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Serialise MQTT Packet.
|
||||
%%
|
||||
%% @doc Serialise MQTT Packet
|
||||
%% @end
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec serialise(mqtt_packet()) -> binary().
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
%%% SOFTWARE.
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%% @doc
|
||||
%%% emqtt topic.
|
||||
%%% MQTT Topic
|
||||
%%%
|
||||
%%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
-module(emqtt_topic).
|
||||
|
||||
-author('feng@emqtt.io').
|
||||
-author("Feng Lee <feng@emqtt.io>").
|
||||
|
||||
-import(lists, [reverse/1]).
|
||||
|
||||
|
@ -42,12 +42,10 @@
|
|||
|
||||
-export_type([word/0, triple/0]).
|
||||
|
||||
-define(MAX_TOPIC_LEN, 65535).
|
||||
-define(MAX_TOPIC_LEN, 4096).
|
||||
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Is wildcard topic?
|
||||
%%
|
||||
%% @doc Is wildcard topic?
|
||||
%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
-spec wildcard(binary()) -> true | false.
|
||||
|
@ -62,12 +60,10 @@ wildcard(['+'|_]) ->
|
|||
wildcard([_H|T]) ->
|
||||
wildcard(T).
|
||||
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Match Topic name with filter.
|
||||
%%
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc Match Topic name with filter
|
||||
%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec match(Name, Filter) -> boolean() when
|
||||
Name :: binary() | words(),
|
||||
Filter :: binary() | words().
|
||||
|
@ -92,12 +88,10 @@ match([_H1|_], []) ->
|
|||
match([], [_H|_T2]) ->
|
||||
false.
|
||||
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Validate Topic
|
||||
%%
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc Validate Topic
|
||||
%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec validate({name | filter, binary()}) -> boolean().
|
||||
validate({_, <<>>}) ->
|
||||
false;
|
||||
|
@ -133,9 +127,7 @@ validate3(<<_/utf8, Rest/binary>>) ->
|
|||
validate3(Rest).
|
||||
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Topic to Triples.
|
||||
%%
|
||||
%% @doc Topic to Triples
|
||||
%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
-spec triples(binary()) -> list(triple()).
|
||||
|
@ -159,12 +151,10 @@ bin('+') -> <<"+">>;
|
|||
bin('#') -> <<"#">>;
|
||||
bin(B) when is_binary(B) -> B.
|
||||
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%% @doc
|
||||
%% Split Topic to Words.
|
||||
%%
|
||||
%%------------------------------------------------------------------------------
|
||||
%% @doc Split Topic Path to Words
|
||||
%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%------------------------------------------------------------------------------
|
||||
-spec words(binary()) -> words().
|
||||
words(Topic) when is_binary(Topic) ->
|
||||
[word(W) || W <- binary:split(Topic, <<"/">>, [global])].
|
||||
|
|
Loading…
Reference in New Issue