Module: Ably::Modules::Encodeable

Included in:
Ably::Models::Message, Ably::Models::PresenceMessage, Ably::Models::ProtocolMessage
Defined in:
lib/submodules/ably-ruby/lib/ably/modules/encodeable.rb

Overview

Provides methods to allow this model's `data` property to be encoded and decoded based on the `encoding` property.

This module expects the following:

  • A #attributes method that returns the underlying hash object

  • A #set_attributes_object(attributes) method that updates the underlying hash object

  • A #raw_hash_object attribute that returns the original hash object used to create this object

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
# File 'lib/submodules/ably-ruby/lib/ably/modules/encodeable.rb', line 13

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#decode(encoders, channel_options, &error_block) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Decode a message using the channel options and registered encoders for the client

Parameters:

  • encoders (Array<Ably::Models::MessageEncoders::Base>)

    List of encoders to apply to the message

  • channel_options (Hash)

    Channel options, currently reserved for Encryption options



65
66
67
# File 'lib/submodules/ably-ruby/lib/ably/modules/encodeable.rb', line 65

def decode(encoders, channel_options, &error_block)
  apply_encoders :decode, encoders, channel_options, &error_block
end

#encode(encoders, channel_options, &error_block) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Encode a message using the channel options and register encoders for the client

Parameters:

  • encoders (Array<Ably::Models::MessageEncoders::Base>)

    List of encoders to apply to the message

  • channel_options (Hash)

    Channel options, currently reserved for Encryption options



56
57
58
# File 'lib/submodules/ably-ruby/lib/ably/modules/encodeable.rb', line 56

def encode(encoders, channel_options, &error_block)
  apply_encoders :encode, encoders, channel_options, &error_block
end

#original_encodingString?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The original encoding of this message when it was received as a raw message from the Ably service

Returns:

  • (String, nil)


72
73
74
# File 'lib/submodules/ably-ruby/lib/ably/modules/encodeable.rb', line 72

def original_encoding
  raw_hash_object['encoding']
end