You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by Apache Wiki <wi...@apache.org> on 2008/07/15 17:21:58 UTC

[Thrift Wiki] Update of "ThriftUsageRuby" by StuartSierra

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Thrift Wiki" for change notification.

The following page has been changed by StuartSierra:
http://wiki.apache.org/thrift/ThriftUsageRuby

The comment on the change is:
Created page with some examples

New page:
= ThriftUsageRuby =

''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"
$:.push("/path/to/tutorial/gen-rb")
require "tutorial_constants"
}}}

== Creating Objects, Using Constants ==

{{{
work = Work.new
work.num1 = 7
work.num2 = 9
work.op = Operation::ADD 
}}}

== Serializing to/from a Binary String ==

{{{
require "thrift/serializer"
serializer = Thrift::Serializer.new
deserializer = Thrift::Deserializer.new

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(Work.new, binary_string)
# => #<Work:0xb7aa16c8 @op=1, @num2=9, @num1=7>
}}}