class BareTypes::Optional

Public Class Methods

new(optionalType) click to toggle source
# File lib/types.rb, line 112
def initialize(optionalType)
  raise VoidUsedOutsideTaggedSet() if optionalType.class == BareTypes::Void
  @optionalType = optionalType
end

Public Instance Methods

==(otherType) click to toggle source
# File lib/types.rb, line 94
def ==(otherType)
  return otherType.class == BareTypes::Optional && otherType.optionalType == @optionalType
end
decode(msg) click to toggle source
# File lib/types.rb, line 127
def decode(msg)
  if msg.unpack("C")[0] == 0
    return nil, msg[1..msg.size]
  else
    return @optionalType.decode(msg[1..msg.size])
  end
end
encode(msg) click to toggle source
# File lib/types.rb, line 117
def encode(msg)
  if msg.nil?
    return "\x00".b
  else
    bytes = "\x01".b
    bytes << @optionalType.encode(msg)
    return bytes
  end
end
finalize_references(schema) click to toggle source
# File lib/types.rb, line 98
def finalize_references(schema)
  return if @finalized
  @finalized = true
  if @optionalType.is_a?(Symbol)
    @optionalType = schema[@optionalType]
  else
    @optionalType.finalize_references(schema)
  end
end
optionalType() click to toggle source
# File lib/types.rb, line 108
def optionalType
  @optionalType
end