lib/submodules/ably-ruby/lib/ably/models/message.rb in ably-rest-1.1.6 vs lib/submodules/ably-ruby/lib/ably/models/message.rb in ably-rest-1.1.7

- old
+ new

@@ -103,9 +103,23 @@ as_json(*args).tap do |message| decode_binary_data_before_to_json message end.to_json end + # The size is the sum over name, data, clientId, and extras in bytes (TO3l8a) + # + def size + %w(name data client_id extras).map do |attr| + if (value = attributes[attr.to_sym]).is_a?(String) + value.bytesize + elsif value.nil? + 0 + else + value.to_json.bytesize + end + end.sum + end + # Assign this message to a ProtocolMessage before delivery to the Ably system # @api private def assign_to_protocol_message(protocol_message) @protocol_message = protocol_message end