Note: There are bugs in the Ruby generator in Thrift release 20080411p1. These examples are based on SVN rev. 675053

Assuming you're using the definitions in "tutorial.thrift":

Loading the Libraries

require "thrift"
require "tutorial_constants"

Creating Objects, Using Constants

work =
work.num1 = 7
work.num2 = 9
work.op = Operation::ADD 

Serializing to/from a Binary String

require "thrift/serializer"
serializer =
deserializer =

binary_string = serializer.serialize(work)
# => "\b\000\001\000\000\000\a\b\000\002\000\000\000\t\b\000\003\000\000\000\001\000"

work2 = deserializer.deserialize(, binary_string)
# => #<Work:0xb7aa16c8 @op=1, @num2=9, @num1=7>
  • No labels