Thrift::Union
Constructors
new
union are to be initialized with key-word arg to initialize a union
class MyUnion
include ::Thrift::Union
union_property x : Int32
union_property y : String
end
a_union = MyUnion.new(x: 32532)
a_union.x # => 32532
other_union = MyUnion.new(y: "hello")
other_union.y # => "hello
Instance methods
<=>(other : self)
Sourcewrite(to oprot : Thrift::Protocol::BaseProtocol)
method that will write a Thrift Union to a Transport encoding in the Given Protocol
require "thrift"
class MyUnion
include ::Thrift::Union
@[::Thrift::Type::SerialOpts(fid: 0)]
union_property prop_int : Int32
@[::Thrift::Type::SerialOpts(fid: 1)]
union_property prop_str : String
end
transport = Thrift::Transport::MemoryBufferTransport.new
protocol = Thrift::Protocol::BinaryProtocol.new(transport)
my_union = MyUnion.new(prop_int: 12)
my_union.write to: protocol
transport.peek # => Bytes[8, 0, 0, 0, 0, 0, 12, 0]
Macros
union_property(name)
inherited macro to define a property for a union
union_property x : Int32
is equivalent to
@[UnionVar]
def x : Int32
@storage_internal.as(Int32)
end
def x=(@storage_internal : Int32)
end