Sha256: a991951c2a1c3060cb08483da25764ba81f46ff3eea9f2e332663ca43c60c1b9

Contents?: true

Size: 1.39 KB

Versions: 21

Compression:

Stored size: 1.39 KB

Contents

require 'json'
require 'msgpack'

module Datadog
  # Encoding module that encodes data for the AgentTransport
  module Encoding
    # Encoder interface that provides the logic to encode traces and service
    module Encoder
      def content_type
        raise NotImplementedError
      end

      # Concatenates a list of elements previously encoded by +#encode+.
      def join(encoded_elements)
        raise NotImplementedError
      end

      # Serializes a single trace into a String suitable for network transmission.
      def encode(_)
        raise NotImplementedError
      end
    end

    # Encoder for the JSON format
    module JSONEncoder
      extend Encoder

      CONTENT_TYPE = 'application/json'.freeze

      module_function

      def content_type
        CONTENT_TYPE
      end

      def encode(obj)
        JSON.dump(obj)
      end

      def join(encoded_data)
        "[#{encoded_data.join(',')}]"
      end
    end

    # Encoder for the Msgpack format
    module MsgpackEncoder
      extend Encoder

      module_function

      CONTENT_TYPE = 'application/msgpack'.freeze

      def content_type
        CONTENT_TYPE
      end

      def encode(obj)
        MessagePack.pack(obj)
      end

      def join(encoded_data)
        packer = MessagePack::Packer.new
        packer.write_array_header(encoded_data.size)

        (packer.buffer.to_a + encoded_data).join
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
ddtrace-0.51.1 lib/ddtrace/encoding.rb
ddtrace-0.51.0 lib/ddtrace/encoding.rb
ddtrace-0.50.0 lib/ddtrace/encoding.rb
ddtrace-0.49.0 lib/ddtrace/encoding.rb
ddtrace-0.48.0 lib/ddtrace/encoding.rb
ddtrace-0.47.0 lib/ddtrace/encoding.rb
ddtrace-0.46.0 lib/ddtrace/encoding.rb
ddtrace-0.45.0 lib/ddtrace/encoding.rb
ddtrace-0.44.0 lib/ddtrace/encoding.rb
ddtrace-0.43.0 lib/ddtrace/encoding.rb
ddtrace-0.42.0 lib/ddtrace/encoding.rb
ddtrace-0.41.0 lib/ddtrace/encoding.rb
ls-trace-0.2.0 lib/ddtrace/encoding.rb
ddtrace-0.40.0 lib/ddtrace/encoding.rb
ddtrace-0.39.0 lib/ddtrace/encoding.rb
ddtrace-0.38.0 lib/ddtrace/encoding.rb
ddtrace-0.37.0 lib/ddtrace/encoding.rb
ddtrace-0.36.0 lib/ddtrace/encoding.rb
ddtrace-0.35.2 lib/ddtrace/encoding.rb
ddtrace-0.35.1 lib/ddtrace/encoding.rb