class BareTypes::ArrayFixedLen

Public Class Methods

new(type, size) click to toggle source
# File lib/types.rb, line 551
def initialize(type, size)
  @type = type
  @size = size
  raise VoidUsedOutsideTaggedSet.new("Void type may not be used as type of fixed length array.") if type.class == BareTypes::Void
  raise MinimumSizeError.new("FixedLenArray size must be > 0") if size < 1
end

Public Instance Methods

==(otherType) click to toggle source
# File lib/types.rb, line 537
def ==(otherType)
  return otherType.class == BareTypes::ArrayFixedLen && otherType.type == @type && otherType.size == @size
end
decode(rest) click to toggle source
# File lib/types.rb, line 575
def decode(rest)
  array = []
  @size.times do
    arrVal, rest = @type.decode(rest)
    array << arrVal
  end
  return array, rest
end
encode(arr) click to toggle source
# File lib/types.rb, line 566
def encode(arr)
  raise SchemaMismatch.new("This FixLenArray is of length #{@size.to_s} but you passed an array of length #{arr.size}") if arr.size != @size
  bytes = ""
  arr.each do |item|
    bytes << @type.encode(item)
  end
  return bytes
end
finalize_references(schema) click to toggle source
# File lib/types.rb, line 541
def finalize_references(schema)
  return if @finalized
  @finalized = true
  if @type.is_a?(Symbol)
    @type = schema[@type]
  else
    @type.finalize_references(schema)
  end
end
size() click to toggle source
# File lib/types.rb, line 562
def size
  @size
end
type() click to toggle source
# File lib/types.rb, line 558
def type
  @type
end