lib/mqtt/packet.rb in mqtt-0.3.1 vs lib/mqtt/packet.rb in mqtt-0.4.0
- old
+ new
@@ -366,11 +366,11 @@
if @topic.nil? or @topic.to_s.empty?
raise "Invalid topic name when serialising packet"
end
body += encode_string(@topic)
body += encode_short(@id) unless qos == 0
- body += payload.to_s.force_encoding('ASCII-8BIT')
+ body += payload.to_s.dup.force_encoding('ASCII-8BIT')
return body
end
# Parse the body (variable header and payload) of a Publish packet
def parse_body(buffer)
@@ -778,13 +778,13 @@
super(ATTR_DEFAULTS.merge(args))
end
# Set one or more topic filters for the Subscribe packet
# The topics parameter should be one of the following:
- # * String: subscribe to one topic with QOS 0
- # * Array: subscribe to multiple topics with QOS 0
- # * Hash: subscribe to multiple topics where the key is the topic and the value is the QOS level
+ # * String: subscribe to one topic with QoS 0
+ # * Array: subscribe to multiple topics with QoS 0
+ # * Hash: subscribe to multiple topics where the key is the topic and the value is the QoS level
#
# For example:
# packet.topics = 'a/b'
# packet.topics = ['a/b', 'c/d']
# packet.topics = [['a/b',0], ['c/d',1]]
@@ -875,11 +875,11 @@
# Create a new Subscribe Acknowledgment packet
def initialize(args={})
super(ATTR_DEFAULTS.merge(args))
end
- # Set the granted QOS value for each of the topics that were subscribed to
+ # Set the granted QoS value for each of the topics that were subscribed to
# Can either be an integer or an array or integers.
def return_codes=(value)
if value.is_a?(Array)
@return_codes = value
elsif value.is_a?(Integer)
@@ -890,10 +890,10 @@
end
# Get serialisation of packet's body
def encode_body
if @return_codes.empty?
- raise "no granted QOS given when serialising packet"
+ raise "no granted QoS given when serialising packet"
end
body = encode_short(@id)
return_codes.each { |qos| body += encode_bytes(qos) }
return body
end