class Array

Attributes

proton_array_header[RW]

Used to declare an array as an AMQP array.

The value, if defined, is an instance of Qpid::Proton::ArrayHeader

Private Class Methods

proton_get(data) click to toggle source

Gets the elements of an array or list out of the specified Qpid::Proton::Data object.

# File lib/qpid_proton/array.rb, line 114
def proton_get(data)
  raise TypeError, "can't convert nil into Qpid::Proton::Data" if data.nil?

  type = data.type

  if type == Qpid::Proton::LIST
    result = proton_get_list(data)
  elsif type == Qpid::Proton::ARRAY
    result = proton_get_array(data)
  else
    raise TypeError, "element is not a list and not an array"
  end
end
proton_get_array(data) click to toggle source
# File lib/qpid_proton/array.rb, line 144
def proton_get_array(data)
  count, described, type = data.array

  raise TypeError, "not an array" unless data.enter
  elements = []

  descriptor = nil

  if described
    data.next
    descriptor = data.symbol
  end

  elements.proton_array_header = Qpid::Proton::ArrayHeader.new(type, descriptor)
  (0...count).each do |which|
    if data.next
      etype = data.type
      raise TypeError, "missing next element in array" unless etype
      raise TypeError, "invalid array element: #{etype}" unless etype == type
      elements << type.get(data)
    end
  end
  data.exit
  return elements
end
proton_get_list(data) click to toggle source
# File lib/qpid_proton/array.rb, line 130
def proton_get_list(data)
  size = data.list
  raise TypeError, "not a list" unless data.enter
  elements = []
  (0...size).each do
    data.next
    type = data.type
    raise TypeError, "missing next element in list" unless type
    elements << type.get(data)
  end
  data.exit
  return elements
end

Public Instance Methods

proton_described?() click to toggle source

Returns true if the array is the a Proton described type.

# File lib/qpid_proton/array.rb, line 65
def proton_described?
  !@proton_array_header.nil? && @proton_array_header.described?
end
proton_put(data) click to toggle source

Puts the elements of the array into the specified Qpid::Proton::Data object.

# File lib/qpid_proton/array.rb, line 70
def proton_put(data)
  raise TypeError, "data object cannot be nil" if data.nil?

  if @proton_array_header.nil?
    proton_put_list(data)
  else
    proton_put_array(data)
  end
end

Private Instance Methods

proton_put_array(data) click to toggle source
# File lib/qpid_proton/array.rb, line 96
def proton_put_array(data)
  data.put_array(@proton_array_header.described?, @proton_array_header.type)
  data.enter
  if @proton_array_header.described?
    data.symbol = @proton_array_header.descriptor
  end

  each do |element|
    @proton_array_header.type.put(data, element)
  end

  data.exit
end
proton_put_list(data) click to toggle source
# File lib/qpid_proton/array.rb, line 82
def proton_put_list(data)
  # create a list, then enter it and add each element
  data.put_list
  data.enter
  each do |element|
    # get the proton type for the element
    mapping = Qpid::Proton::Mapping.for_class(element.class)
    # add the element
    mapping.put(data, element)
  end
  # exit the list
  data.exit
end