Skip to content

Commit

Permalink
Add a "copy constructor" ish
Browse files Browse the repository at this point in the history
  • Loading branch information
spuun committed Oct 29, 2024
1 parent 5f8ae55 commit 633c1c6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/mqtt/protocol/packets/publish.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module MQTT
getter topic, payload, qos, packet_id, remaining_length
getter? dup, retain

def initialize(pub : Publish, topic = pub.topic, qos = pub.qos, payload = pub.payload, packet_id = pub.packet_id, dup = pub.dup?, retain = pub.retain?)
initialize(topic, payload, packet_id, dup, qos, retain)
end

def initialize(@topic : String, @payload : Payload, @packet_id : UInt16?, @dup : Bool, @qos : UInt8, @retain : Bool)
raise ArgumentError.new("QoS must be 0, 1 or 2") if @qos > 2
raise ArgumentError.new("Topic cannot contain wildcard") if @topic.matches?(/[#+]/)
Expand Down

0 comments on commit 633c1c6

Please sign in to comment.