You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by kc...@apache.org on 2008/06/18 03:09:15 UTC
svn commit: r668959 - in /incubator/thrift/trunk:
compiler/cpp/src/generate/t_rb_generator.cc lib/rb/lib/thrift/protocol.rb
lib/rb/lib/thrift/struct.rb
Author: kclark
Date: Tue Jun 17 18:09:15 2008
New Revision: 668959
URL: http://svn.apache.org/viewvc?rev=668959&view=rev
Log:
Convert fields of type Thrift::Types::SET to use the Set library.
Also teach Thrift::Struct how to compare itself with ==
Modified:
incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc
incubator/thrift/trunk/lib/rb/lib/thrift/protocol.rb
incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb
Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc?rev=668959&r1=668958&r2=668959&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc Tue Jun 17 18:09:15 2008
@@ -397,7 +397,7 @@
etype = ((t_set*)type)->get_elem_type();
}
if (type->is_set()) {
- out << "{";
+ out << "Set.new([";
} else {
out << "[" << endl;
}
@@ -407,14 +407,11 @@
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
out << indent();
out << render_const_value(etype, *v_iter);
- if (type->is_set()) {
- out << " => true";
- }
out << "," << endl;
}
indent_down();
if (type->is_set()) {
- indent(out) << "}";
+ indent(out) << "])";
} else {
indent(out) << "]";
}
Modified: incubator/thrift/trunk/lib/rb/lib/thrift/protocol.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/protocol.rb?rev=668959&r1=668958&r2=668959&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/protocol.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/protocol.rb Tue Jun 17 18:09:15 2008
@@ -8,6 +8,9 @@
# Author: Mark Slee <mc...@facebook.com>
#
+# this require is to make generated struct definitions happy
+require 'set'
+
module Thrift
class ProtocolException < Exception
Modified: incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb?rev=668959&r1=668958&r2=668959&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb Tue Jun 17 18:09:15 2008
@@ -44,6 +44,14 @@
oprot.write_struct_end()
end
+ def ==(other)
+ return false unless other.is_a?(self.class)
+ each_field do |fid, type, name, default|
+ return false unless self.instance_variable_get("@#{name}") == other.instance_variable_get("@#{name}")
+ end
+ true
+ end
+
protected
def handle_message(iprot, fid, ftype)
@@ -77,10 +85,10 @@
iprot.read_list_end
elsif field[:type] == Types::SET
e_type, size = iprot.read_set_begin
- value = {}
+ value = Set.new
size.times do
element = read_field(iprot, field_info(field[:element]))
- value[element] = true
+ value << element
end
iprot.read_set_end
else