Sha256: d2aa63435fd5cea74827cec3d6e8eac3e605c180ec0a9eb0a848f2053d7dd742

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require 'new_relic/agent/new_relic_service/marshaller'

module NewRelic
  module Agent
    class NewRelicService
      # Marshal collector protocol with JSON when available
      class JsonMarshaller < Marshaller
        def initialize
          ::NewRelic::Agent.logger.debug "Using JSON marshaller (#{NewRelic::JSONWrapper.backend_name})"
          unless self.class.is_supported?
            ::NewRelic::Agent.logger.warn "The JSON marshaller in use (#{NewRelic::JSONWrapper.backend_name}) is not recommended. Ensure the 'json' gem is available in your application for better performance."
          end
        end

        def dump(ruby, opts={})
          prepared = prepare(ruby, opts)

          if opts[:skip_normalization]
            normalize_encodings = false
          else
            normalize_encodings = Agent.config[:normalize_json_string_encodings]
          end

          NewRelic::JSONWrapper.dump(prepared, :normalize => normalize_encodings)
        end

        def load(data)
          return_value(NewRelic::JSONWrapper.load(data)) if data && data != ''
        rescue => e
          ::NewRelic::Agent.logger.debug "#{e.class.name} : #{e.message} encountered loading collector response: #{data}"
          raise
        end

        def default_encoder
          Encoders::Base64CompressedJSON
        end

        def format
          'json'
        end

        def self.is_supported?
          NewRelic::JSONWrapper.usable_for_collector_serialization?
        end

        def self.human_readable?
          true # for some definitions of 'human'
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
newrelic_rpm-3.9.5.251 lib/new_relic/agent/new_relic_service/json_marshaller.rb
newrelic_rpm-3.9.4.245 lib/new_relic/agent/new_relic_service/json_marshaller.rb