THRIFT-248. ruby: Factor BinaryProtocolAccelerated into separate protocol and struct components

This patch replaces the "binaryprotocolaccelerated" c extension with the "thrift_native" c extension. This new extension creates native implementations for the struct.rb #write and #read methods, Thrift::BinaryProtocol, and Thrift::MemoryBuffer, but keeps ruby-level interfaces, allowing all protocols to benefit from the struct code and the memory buffer. There is however an additional cost associated with going through this ruby layer, but the increased interoperability seems to be well worth it.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@739895 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/spec/serializer_spec.rb b/lib/rb/spec/serializer_spec.rb
index fe5a86a..78a11ab 100644
--- a/lib/rb/spec/serializer_spec.rb
+++ b/lib/rb/spec/serializer_spec.rb
@@ -8,15 +8,17 @@
 
   describe Serializer do
     it "should serialize structs to binary by default" do
-      serializer = Serializer.new
+      serializer = Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
       data = serializer.serialize(Hello.new(:greeting => "'Ello guv'nor!"))
       data.should == "\x0B\x00\x01\x00\x00\x00\x0E'Ello guv'nor!\x00"
     end
 
     it "should serialize structs to the given protocol" do
-      protocol = mock("Protocol")
+      protocol = Protocol.new(mock("transport"))
       protocol.should_receive(:write_struct_begin).with("SpecNamespace::Hello")
-      protocol.should_receive(:write_field).with("greeting", Types::STRING, 1, "Good day")
+      protocol.should_receive(:write_field_begin).with("greeting", Types::STRING, 1)
+      protocol.should_receive(:write_string).with("Good day")
+      protocol.should_receive(:write_field_end)
       protocol.should_receive(:write_field_stop)
       protocol.should_receive(:write_struct_end)
       protocolFactory = mock("ProtocolFactory")
@@ -34,11 +36,11 @@
     end
 
     it "should deserialize structs from the given protocol" do
-      protocol = mock("Protocol")
+      protocol = Protocol.new(mock("transport"))
       protocol.should_receive(:read_struct_begin).and_return("SpecNamespace::Hello")
       protocol.should_receive(:read_field_begin).and_return(["greeting", Types::STRING, 1],
                                                             [nil, Types::STOP, 0])
-      protocol.should_receive(:read_type).with(Types::STRING).and_return("Good day")
+      protocol.should_receive(:read_string).and_return("Good day")
       protocol.should_receive(:read_field_end)
       protocol.should_receive(:read_struct_end)
       protocolFactory = mock("ProtocolFactory")