Class: Ably::Models::MessageEncoders::Base64

Inherits:
Base
  • Object
show all
Defined in:
lib/ably/models/message_encoders/base64.rb

Overview

Base64 binary Encoder and Decoder Uses encoding identifier 'base64'

Constant Summary collapse

ENCODING_ID =
'base64'

Instance Attribute Summary

Attributes inherited from Base

#client, #options

Instance Method Summary collapse

Methods inherited from Base

#add_encoding_to_message, #current_encoding_part, #initialize, #is_empty?, #strip_current_encoding_part

Constructor Details

This class inherits a constructor from Ably::Models::MessageEncoders::Base

Instance Method Details

#decode(message, channel_options) ⇒ Object


20
21
22
23
24
25
# File 'lib/ably/models/message_encoders/base64.rb', line 20

def decode(message, channel_options)
  if is_base64_encoded?(message)
    message[:data] = ::Base64.decode64(message[:data])
    strip_current_encoding_part message
  end
end

#encode(message, channel_options) ⇒ Object


11
12
13
14
15
16
17
18
# File 'lib/ably/models/message_encoders/base64.rb', line 11

def encode(message, channel_options)
  return if is_empty?(message)

  if is_binary?(message) && transport_protocol_text?
    message[:data] = ::Base64.encode64(message[:data])
    add_encoding_to_message ENCODING_ID, message
  end
end