lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb in ably-rest-1.2.2 vs lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb in ably-rest-1.2.3
- old
+ new
@@ -30,10 +30,11 @@
# The message contains properties :name, :data, :encoding, :timestamp, and optionally :id and :client_id.
# This #encode method should modify the message Hash if any encoding action is to be taken
# @param [Hash] channel_options the options used to initialize the channel that this message was received on
#
# @return [void]
+ #
def encode(message, channel_options)
raise "Not yet implemented"
end
# #decode is called once for every encoding step
@@ -46,10 +47,11 @@
# The message contains properties :name, :data, :encoding, :timestamp, and optionally :id and :client_id.
# This #encode method should modify the message Hash if any decoding action is to be taken
# @param [Hash] channel_options the options used to initialize the channel that this message was received on
#
# @return [void]
+ #
def decode(message, channel_options)
raise "Not yet implemented"
end
# Add encoding to the message Hash.
@@ -57,18 +59,20 @@
#
# @param [Hash] message the message as a Hash object received directly from Ably.
# @param [String] encoding encoding to add to the current encoding
#
# @return [void]
+ #
def add_encoding_to_message(encoding, message)
message[:encoding] = [message[:encoding], encoding].compact.join('/')
end
# Returns the right most encoding form a meessage encoding, and nil if none exists
# i.e. current_encoding_part('utf-8/cipher+aes-128-cbc/base64') => 'base64'
#
# @return [String,nil]
+ #
def current_encoding_part(message)
if message[:encoding]
message[:encoding].split('/')[-1]
end
end
@@ -79,10 +83,11 @@
# :encoding to 'utf-8/cipher+aes-128-cbc'
#
# @param [Hash] message the message as a Hash object received directly from Ably.
#
# @return [void]
+ #
def strip_current_encoding_part(message)
raise "Cannot strip encoding when there is no encoding for this message" unless message[:encoding]
message[:encoding] = message[:encoding].split('/')[0...-1].join('/')
message[:encoding] = nil if message[:encoding].empty?
end
@@ -90,9 +95,10 @@
# True of the message data payload is empty
#
# @param [Hash] message the message as a Hash object received directly from Ably.
#
# @return [Boolean]
+ #
def is_empty?(message)
message[:data].nil? || message[:data] == ''
end
end