lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb in ably-rest-0.8.2 vs lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb in ably-rest-0.8.3
- old
+ new
@@ -25,20 +25,21 @@
# @!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
- # @return [Message] A {ProtocolMessage} with a `:message` action contains one or more messages belonging to a channel
+ # @return [Array<Message>] A {ProtocolMessage} with a `:message` action contains one or more messages belonging to the channel
# @!attribute [r] presence
- # @return [PresenceMessage] A {ProtocolMessage} with a `:presence` action contains one or more presence updates belonging to a channel
+ # @return [Array<PresenceMessage>] A {ProtocolMessage} with a `:presence` action contains one or more presence updates belonging to the channel
# @!attribute [r] flags
# @return [Integer] Flags indicating special ProtocolMessage states
# @!attribute [r] hash
# @return [Hash] Access the protocol message Hash object ruby'fied to use symbolized keys
#
class ProtocolMessage
include Ably::Modules::ModelCommon
+ include Ably::Modules::Encodeable
include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime)
extend Ably::Modules::Enum
# Actions which are sent by the Ably Realtime API
#
@@ -201,10 +202,21 @@
hash_object['presence'] = presence.map(&:as_json) unless presence.empty?
end.as_json
end
def to_s
- to_json
+ json_hash = as_json
+
+ # Decode any binary data to before converting to a JSON string representation
+ %w(messages presence).each do |message_type|
+ if json_hash[message_type] && !json_hash[message_type].empty?
+ json_hash[message_type].each do |message|
+ decode_binary_data_before_to_json message
+ end
+ end
+ end
+
+ json_hash.to_json
end
# True if the ProtocolMessage appears to be invalid, however this is not a guarantee
# @return [Boolean]
# @api private