lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb in ably-rest-1.2.4 vs lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb in ably-rest-1.2.6
- old
+ new
@@ -18,12 +18,10 @@
# @return [String] Channel name for messages
# @!attribute [r] channel_serial
# @return [String] Contains a serial number for a message on the current channel
# @!attribute [r] connection_id
# @return [String] Contains a string private connection key used to recover this connection
- # @!attribute [r] connection_serial
- # @return [Bignum] Contains a serial number for a message sent from the server to the client
# @!attribute [r] message_serial
# @return [Bignum] Contains a serial number for a message sent from the client to the server
# @!attribute [r] timestamp
# @return [Time] An optional timestamp, applied by the service in messages sent to the client, to indicate the system time at which the message was sent (milliseconds past epoch)
# @!attribute [r] messages
@@ -127,16 +125,10 @@
Integer(attributes[:msg_serial])
rescue TypeError
raise TypeError, "msg_serial '#{attributes[:msg_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage"
end
- def connection_serial
- Integer(attributes[:connection_serial])
- rescue TypeError
- raise TypeError, "connection_serial '#{attributes[:connection_serial]}' is invalid, a positive Integer is expected for a ProtocolMessage"
- end
-
def count
[1, attributes[:count].to_i].max
end
# @api private
@@ -144,30 +136,16 @@
message_serial && true
rescue TypeError
false
end
- # @api private
- def has_connection_serial?
- connection_serial && true
+ def has_channel_serial?
+ channel_serial && true
rescue TypeError
false
end
- def serial
- if has_connection_serial?
- connection_serial
- else
- message_serial
- end
- end
-
- # @api private
- def has_serial?
- has_connection_serial? || has_message_serial?
- end
-
def messages
@messages ||=
Array(attributes[:messages]).map do |message|
Ably::Models.Message(message, protocol_message: self)
end
@@ -269,11 +247,11 @@
end
# Return a JSON ready object from the underlying #attributes using Ably naming conventions for keys
def as_json(*args)
raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action
- raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial?
+ raise TypeError, ':msg_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_message_serial?
attributes.dup.tap do |hash_object|
hash_object['action'] = action.to_i
hash_object['messages'] = messages.map(&:as_json) unless messages.empty?
hash_object['presence'] = presence.map(&:as_json) unless presence.empty?
@@ -294,14 +272,15 @@
json_hash.to_json
end
# True if the ProtocolMessage appears to be invalid, however this is not a guarantee
+ # Used for validating incoming protocol messages, so no need to add unnecessary checks
# @return [Boolean]
# @api private
def invalid?
action_enum = action rescue nil
- !action_enum || (ack_required? && !has_serial?)
+ !action_enum
end
# @!attribute [r] logger
# @api private
attr_reader :logger