rb: Teach BinaryProtocolAccelerated to encode strings with NULs [THRIFT-97]
This patch adds a spec and fixes the behavior to properly treat strings as binary
blobs of data instead of as C strings when writing to the transport.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@679899 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/binaryprotocolaccelerated_spec.rb b/lib/rb/spec/binaryprotocolaccelerated_spec.rb
index c816369..86101f8 100644
--- a/lib/rb/spec/binaryprotocolaccelerated_spec.rb
+++ b/lib/rb/spec/binaryprotocolaccelerated_spec.rb
@@ -70,6 +70,16 @@
\000\005words\f\000\003\v\000\001\000\000\000\rhello, world!\000\000")
@prot.decode_binary(SpecNamespace::Foo.new, trans).should == SpecNamespace::Foo.new
end
+
+ it "should encode a string with null bytes in it" do
+ foo = SpecNamespace::Hello.new(:greeting => "Hello\000World!")
+ @prot.encode_binary(foo).should == "\v\000\001\000\000\000\fHello\000World!\000"
+ end
+
+ it "should decode a string with null bytes in it" do
+ trans = Thrift::MemoryBuffer.new("\v\000\001\000\000\000\fHello\000World!\000")
+ @prot.decode_binary(SpecNamespace::Hello.new, trans).should == SpecNamespace::Hello.new(:greeting => "Hello\000World!")
+ end
end
describe BinaryProtocolAcceleratedFactory do