Module: Ably::Models::MessageEncoders

Extended by:
Ably::Modules::Conversions
Defined in:
lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb,
lib/submodules/ably-ruby/lib/ably/models/message_encoders/json.rb,
lib/submodules/ably-ruby/lib/ably/models/message_encoders/utf8.rb,
lib/submodules/ably-ruby/lib/ably/models/message_encoders/base64.rb,
lib/submodules/ably-ruby/lib/ably/models/message_encoders/cipher.rb

Overview

MessageEncoders are registered with the Ably client library and are responsible for encoding & decoding messages.

For example, if a message body is detected as JSON, it is encoded as a String and the encoding attribute of the message is defined as ‘json’. Encrypted messages are encoded & decoded by the Cipher encoder.

Defined Under Namespace

Classes: Base, Base64, Cipher, Json, Utf8

Class Method Summary collapse

Class Method Details

.encoder_from(encoder, options) ⇒ Object

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.



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 108

def self.encoder_from(encoder, options)
  encoder_klass = if encoder.kind_of?(String)
    encoder.split('::').inject(Kernel) do |base, klass_name|
      base.public_send(:const_get, klass_name)
    end
  else
    encoder
  end

  raise "Encoder must inherit from `Ably::Models::MessageEncoders::Base`" unless encoder_klass.ancestors.include?(Ably::Models::MessageEncoders::Base)
  encoder_klass.new(self, options)
end

.register_default_encoders(client, options = {}) ⇒ Object

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.



99
100
101
102
103
104
105
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 99

def self.register_default_encoders(client, options = {})
  binary_protocol = !!options[:binary_protocol]
  client.register_encoder Ably::Models::MessageEncoders::Utf8
  client.register_encoder Ably::Models::MessageEncoders::Json
  client.register_encoder Ably::Models::MessageEncoders::Cipher
  client.register_encoder Ably::Models::MessageEncoders::Base64, binary_protocol: binary_protocol
end