class Ably::Models::MessageEncoders::Json

JSON Encoder and Decoder Uses encoding identifier ‘json’ and encodes all objects that are not strings or byte arrays

Constants

ENCODING_ID

Public Instance Methods

decode(message, channel_options) click to toggle source
# File lib/submodules/ably-ruby/lib/ably/models/message_encoders/json.rb, line 18
def decode(message, channel_options)
  if is_json_encoded?(message)
    message[:data] = ::JSON.parse(message[:data])
    strip_current_encoding_part message
  end
end
encode(message, channel_options) click to toggle source
# File lib/submodules/ably-ruby/lib/ably/models/message_encoders/json.rb, line 11
def encode(message, channel_options)
  if needs_json_encoding?(message)
    message[:data] = ::JSON.dump(message[:data])
    add_encoding_to_message ENCODING_ID, message
  end
end

Private Instance Methods

is_json_encoded?(message) click to toggle source
# File lib/submodules/ably-ruby/lib/ably/models/message_encoders/json.rb, line 30
def is_json_encoded?(message)
  current_encoding_part(message).to_s.match(/^#{ENCODING_ID}$/i)
end
needs_json_encoding?(message) click to toggle source
# File lib/submodules/ably-ruby/lib/ably/models/message_encoders/json.rb, line 26
def needs_json_encoding?(message)
  !message[:data].kind_of?(String) && !message[:data].nil?
end