Sha256: 9418171e9d3d2bd9ed3b117d6f21c90e2519b01e17156bc60ac8ea8450eb63ea

Contents?: true

Size: 1.55 KB

Versions: 24

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require 'aws-eventstream'

module Aws
  module Binary
    # @api private
    class EventStreamEncoder

      # @param [String] protocol
      # @param [ShapeRef] rules ShapeRef of the eventstream member
      # @param [ShapeRef] input_ref ShapeRef of the input shape
      # @param [Aws::Sigv4::Signer] signer
      def initialize(protocol, rules, input_ref, signer)
        @encoder = Aws::EventStream::Encoder.new
        @event_builder = EventBuilder.new(serializer_class(protocol), rules)
        @input_ref = input_ref
        @rules = rules
        @signer = signer
        @prior_signature = nil
      end

      attr_reader :rules

      attr_accessor :prior_signature

      def encode(event_type, params)
        if event_type == :end_stream
          payload = ''
        else
          payload = @encoder.encode(@event_builder.apply(event_type, params))
        end
        headers, signature = @signer.sign_event(@prior_signature, payload, @encoder)
        @prior_signature = signature
        message = Aws::EventStream::Message.new(
          headers: headers,
          payload: StringIO.new(payload)
        )
        @encoder.encode(message)
      end

      private

      def serializer_class(protocol)
        case protocol
        when 'rest-xml' then Aws::Xml::Builder
        when 'rest-json' then Aws::Json::Builder
        when 'json' then Aws::Json::Builder
        when 'smithy-rpc-v2-cbor' then Aws::RpcV2::Builder
        else raise "unsupported protocol #{protocol} for event stream"
        end
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.213.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.212.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.211.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.210.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.208.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.207.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.206.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.205.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.204.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.203.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.202.2 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.202.1 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.202.0 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.201.5 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.201.4 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.201.3 lib/aws-sdk-core/binary/event_stream_encoder.rb
aws-sdk-core-3.201.2 lib/aws-sdk-core/binary/event_stream_encoder.rb