Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tortoise311.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defmodule Tortoise311 do
it is really easy to hit the maximum byte limit. Solving this is
easy, just add a `:` before the client id such as `:Example`.
"""
@type client_id() :: atom() | String.t()
@type client_id() :: atom() | String.t() | {String.t(), atom()}

@typedoc """
A 16-bit number identifying a message in a message exchange.
Expand Down
6 changes: 6 additions & 0 deletions lib/tortoise311/package/connect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Tortoise311.Package.Connect do
clean_session: boolean(),
keep_alive: non_neg_integer(),
client_id: Tortoise311.client_id(),
discriminator: atom(),
will: Package.Publish.t() | nil
}

Expand All @@ -26,6 +27,7 @@ defmodule Tortoise311.Package.Connect do
clean_session: true,
keep_alive: 60,
client_id: nil,
discriminator: nil,
will: nil

@spec decode(binary()) :: t
Expand Down Expand Up @@ -102,6 +104,10 @@ defmodule Tortoise311.Package.Connect do
encode(%Package.Connect{t | client_id: Atom.to_string(client_id)})
end

def encode(%Package.Connect{client_id: {client_id, _discriminator}} = t) do
encode(%Package.Connect{t | client_id: client_id})
end

defp protocol_header(%{protocol: protocol, protocol_version: version}) do
[Package.length_encode(protocol), version]
end
Expand Down