module

Thrift::Struct

mixing module that will define a class level read, protected instance level read and an instance level write method macro struct_propety is included that MUST be used when defining SerialOpts on a thrift generated class

Instance methods

<=>(other : self)
Source

writes thrift struct to transport encoding with protocol

require "thrift"

class MyStruct
  include Thrift::Struct

  @[Thrift::Type::SerialOpts(fid: 0, requirement: :required)]
  struct_property prop_int : Int32
  @[Thrift::Type::SerialOpts(fid: 1, requirement: :required)]
  struct_property prop_str : String

  def initialize(@prop_int, @prop_str)
  end
end

transport = Thrift::Transport::MemoryBufferTransport.new
protocol = Thrift::Protocol::BinaryProtocol.new(transport)

my_struct = MyStruct.new(12, "hello")
my_struct.write to: protocol

transport.peek # => Bytes[8, 0, 0, 0, 0, 0, 12, 11, 0, 1, 0, 0, 0, 5, 104, 101, 108, 108, 111, 0]
Source

Macros

struct_property(name)

struct_property defines a thrift compatible property of a struct

struct_property x : Int32

will generate

def x : Int32
  @x
end

@x : Int32

def x=(x : Int32)
  # NOTE: this will generate code based on requirement of this property
  @x = x
end
Source

Nested types