Author: bryanduxbury
Date: Thu Feb 18 22:00:45 2010
New Revision: 911610
URL: http://svn.apache.org/viewvc?rev=911610&view=rev
Log:
THRIFT-712. rb: Inspect should print binary fields as hex instead of escaped
string
Modified:
incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc
incubator/thrift/trunk/lib/rb/Rakefile
incubator/thrift/trunk/lib/rb/lib/thrift/struct_union.rb
incubator/thrift/trunk/lib/rb/lib/thrift/union.rb
incubator/thrift/trunk/lib/rb/spec/ThriftSpec.thrift
incubator/thrift/trunk/lib/rb/spec/struct_spec.rb
incubator/thrift/trunk/lib/rb/spec/union_spec.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=911610&r1=911609&r2=911610&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 Thu Feb
18 22:00:45 2010
@@ -651,6 +651,10 @@
out << ", :element => ";
generate_field_data(out, ((t_set*)field_type)->get_elem_type());
}
+ } else {
+ if (((t_base_type*)field_type)->is_binary()) {
+ out << ", :binary => true" << endl;
+ }
}
if(optional) {
Modified: incubator/thrift/trunk/lib/rb/Rakefile
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/Rakefile?rev=911610&r1=911609&r2=911610&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/Rakefile (original)
+++ incubator/thrift/trunk/lib/rb/Rakefile Thu Feb 18 22:00:45 2010
@@ -82,7 +82,7 @@
p.summary = "Ruby libraries for Thrift (a language-agnostic RPC system)"
p.url = "http://incubator.apache.org/thrift/"
p.include_rakefile = true
- p.version = "0.2.3"
+ p.version = "0.2.4"
p.rubygems_version = ">= 1.2.0"
end
Modified: incubator/thrift/trunk/lib/rb/lib/thrift/struct_union.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/struct_union.rb?rev=911610&r1=911609&r2=911610&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/struct_union.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/struct_union.rb Thu Feb 18
22:00:45 2010
@@ -141,6 +141,8 @@
inspect_collection(value, field_info)
elsif value.is_a? Set
inspect_collection(value, field_info)
+ elsif value.is_a?(String) && field_info[:binary]
+ value.unpack("H*").first
else
value.inspect
end
Modified: incubator/thrift/trunk/lib/rb/lib/thrift/union.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/union.rb?rev=911610&r1=911609&r2=911610&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/union.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/union.rb Thu Feb 18 22:00:45 2010
@@ -29,6 +29,10 @@
name, value = name.keys.first, name.values.first
end
+ if Thrift.type_checking
+ raise Exception, "#{self.class} does not contain a field named
#{name}!" unless name_to_id(name.to_s)
+ end
+
if value.nil?
raise Exception, "Union #{self.class} cannot be instantiated with
setfield and nil value!"
end
Modified: incubator/thrift/trunk/lib/rb/spec/ThriftSpec.thrift
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/ThriftSpec.thrift?rev=911610&r1=911609&r2=911610&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/ThriftSpec.thrift (original)
+++ incubator/thrift/trunk/lib/rb/spec/ThriftSpec.thrift Thu Feb 18 22:00:45
2010
@@ -59,6 +59,7 @@
2: i32 i32_field;
3: i32 other_i32_field;
4: SomeEnum enum_field;
+ 5: binary binary_field;
}
struct Foo {
@@ -72,6 +73,10 @@
8: bool my_bool
}
+struct Foo2 {
+ 1: binary my_binary
+}
+
struct BoolStruct {
1: bool yesno = 1
}
Modified: incubator/thrift/trunk/lib/rb/spec/struct_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/struct_spec.rb?rev=911610&r1=911609&r2=911610&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/struct_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/struct_spec.rb Thu Feb 18 22:00:45 2010
@@ -68,6 +68,10 @@
StructWithEnumMap.new(:my_map => {SomeEnum::ONE =>
[SomeEnum::TWO]}).inspect.should == "<SpecNamespace::StructWithEnumMap
my_map:{ONE (0): [TWO (1)]}>"
end
+ it "should pretty print binary fields" do
+ Foo2.new(:my_binary => "\001\002\003").inspect.should ==
"<SpecNamespace::Foo2 my_binary:010203>"
+ end
+
it "should offer field? methods" do
Foo.new.opt_string?.should be_false
Foo.new(:simple => 52).simple?.should be_true
Modified: incubator/thrift/trunk/lib/rb/spec/union_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/union_spec.rb?rev=911610&r1=911609&r2=911610&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/union_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/union_spec.rb Thu Feb 18 22:00:45 2010
@@ -160,5 +160,9 @@
My_union.new(:im_true => false).im_true?.should be_true
My_union.new(:im_true => true).im_true?.should be_true
end
+
+ it "should pretty print binary fields" do
+ TestUnion.new(:binary_field => "\001\002\003").inspect.should ==
"<SpecNamespace::TestUnion binary_field: 010203>"
+ end
end
end