Sha256: 4421a3189622b1d83041f817b09c959a7bb0a33f95387cd48e1928db81c24cc2
Contents?: true
Size: 1 KB
Versions: 35
Compression:
Stored size: 1 KB
Contents
require 'base64' require 'ably/models/message_encoders/base' module Ably::Models::MessageEncoders # Base64 binary Encoder and Decoder # Uses encoding identifier 'base64' # class Base64 < Base ENCODING_ID = 'base64' 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 def decode(message, channel_options) if is_base64_encoded?(message) message[:data] = ::Base64.decode64(message[:data]) strip_current_encoding_part message end end private def is_binary?(message) message[:data].kind_of?(String) && message[:data].encoding == Encoding::ASCII_8BIT end def is_base64_encoded?(message) current_encoding_part(message).to_s.match(/^#{ENCODING_ID}$/i) end def transport_protocol_text? !client.protocol_binary? end end end
Version data entries
35 entries across 35 versions & 2 rubygems