THRIFT-1699 Native Union#read has extra read_field_end call
Patch: Kevin Radloff
diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c
index 5a9a679..8fbadbe 100644
--- a/lib/rb/ext/struct.c
+++ b/lib/rb/ext/struct.c
@@ -627,9 +627,6 @@
rb_raise(rb_eRuntimeError, "too many fields in union!");
}
- // read field end
- default_read_field_end(protocol);
-
// read struct end
default_read_struct_end(protocol);
diff --git a/lib/rb/spec/union_spec.rb b/lib/rb/spec/union_spec.rb
index db08cab..dd84906 100644
--- a/lib/rb/spec/union_spec.rb
+++ b/lib/rb/spec/union_spec.rb
@@ -93,7 +93,7 @@
lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
end
- it "should serialize correctly" do
+ it "should serialize to binary correctly" do
trans = Thrift::MemoryBufferTransport.new
proto = Thrift::BinaryProtocol.new(trans)
@@ -105,6 +105,18 @@
other_union.should == union
end
+ it "should serialize to json correctly" do
+ trans = Thrift::MemoryBufferTransport.new
+ proto = Thrift::JsonProtocol.new(trans)
+
+ union = SpecNamespace::My_union.new(:integer32, 25)
+ union.write(proto)
+
+ other_union = SpecNamespace::My_union.new(:integer32, 25)
+ other_union.read(proto)
+ other_union.should == union
+ end
+
it "should raise when validating unset union" do
union = SpecNamespace::My_union.new
lambda { union.validate }.should raise_error(StandardError, "Union fields are not set.")