|
⇤ ← Revision 1 as of 2008-07-15 15:21:57
Size: 873
Comment: Created page with some examples
|
← Revision 2 as of 2009-09-20 23:47:15 ⇥
Size: 873
Comment: converted to 1.6 markup
|
| No differences found! | |
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>