class BareTypes::Array

Public Class Methods

new(type) click to toggle source
# File lib/types.rb, line 509
def initialize(type)
  raise VoidUsedOutsideTaggedSet.new("Void types may only be used as members of the set of types in a tagged union.") if type.class == BareTypes::Void
  @type = type
end

Public Instance Methods

==(otherType) click to toggle source
# File lib/types.rb, line 491
def ==(otherType)
  return otherType.class == BareTypes::Array && otherType.type == self.type
end
decode(msg) click to toggle source
# File lib/types.rb, line 522
def decode(msg)
  arr = []
  arrayLen, rest = Uint.new.decode(msg)
  lastSize = msg.size + 1 # Make sure msg size monotonically decreasing
  (arrayLen - 1).downto(0) do
    arrVal, rest = @type.decode(rest)
    arr << arrVal
    break if rest.nil? || rest.size == 0 || lastSize <= rest.size
    lastSize = rest.size
  end
  return arr, rest
end
encode(msg) click to toggle source
# File lib/types.rb, line 514
def encode(msg)
  bytes = Uint.new.encode(msg.size)
  msg.each do |item|
    bytes << @type.encode(item)
  end
  return bytes
end
finalize_references(schema) click to toggle source
# File lib/types.rb, line 499
def finalize_references(schema)
  return if @finalized
  @finalized = true
  if @type.is_a?(Symbol)
    @type = schema[@type]
  else
    @type.finalize_references(schema)
  end
end
type() click to toggle source
# File lib/types.rb, line 495
def type
  return @type
end