class Aws::RpcV2::Builder

Public Class Methods

new(rules, _options = {}) click to toggle source
# File lib/aws-sdk-core/rpc_v2/builder.rb, line 10
def initialize(rules, _options = {})
  @rules = rules
end

Public Instance Methods

serialize(params) click to toggle source
# File lib/aws-sdk-core/rpc_v2/builder.rb, line 14
def serialize(params)
  # If the input shape is empty, do not set a body. This is
  # different than if the input shape is a structure with no members.
  return nil if @rules.shape.struct_class == EmptyStructure

  RpcV2.encode(format(@rules, params))
end

Private Instance Methods

blob(value) click to toggle source
# File lib/aws-sdk-core/rpc_v2/builder.rb, line 47
def blob(value)
  (String === value ? value : value.read).force_encoding(Encoding::BINARY)
end
format(ref, value) click to toggle source
# File lib/aws-sdk-core/rpc_v2/builder.rb, line 51
def format(ref, value)
  case ref.shape
  when StructureShape then structure(ref, value)
  when ListShape      then list(ref, value)
  when MapShape       then map(ref, value)
  when BlobShape      then blob(value)
  else value
  end
end
list(ref, values) click to toggle source
# File lib/aws-sdk-core/rpc_v2/builder.rb, line 35
def list(ref, values)
  member_ref = ref.shape.member
  values.collect { |value| format(member_ref, value) }
end
map(ref, values) click to toggle source
# File lib/aws-sdk-core/rpc_v2/builder.rb, line 40
def map(ref, values)
  value_ref = ref.shape.value
  values.each.with_object({}) do |(key, value), data|
    data[key] = format(value_ref, value)
  end
end
structure(ref, values) click to toggle source
# File lib/aws-sdk-core/rpc_v2/builder.rb, line 24
def structure(ref, values)
  shape = ref.shape
  values.each_pair.with_object({}) do |(key, value), data|
    if shape.member?(key) && !value.nil?
      member_ref = shape.member(key)
      member_name = member_ref.location_name || key
      data[member_name] = format(member_ref, value)
    end
  end
end