Class: Ably::Models::MessageEncoders::Json

Inherits:
Base
  • Object
show all
Defined in:
lib/submodules/ably-ruby/lib/ably/models/message_encoders/json.rb

Overview

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

Constant Summary collapse

ENCODING_ID =
'json'

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



18
19
20
21
22
23
# 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) ⇒ Object



11
12
13
14
15
16
# 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