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/ext/struct.h b/lib/rb/ext/struct.h
new file mode 100644
index 0000000..bf2350d
--- /dev/null
+++ b/lib/rb/ext/struct.h
@@ -0,0 +1,48 @@
+#include <stdbool.h>
+#include <ruby.h>
+
+typedef struct native_proto_method_table {
+ VALUE (*write_bool)(VALUE, VALUE);
+ VALUE (*write_byte)(VALUE, VALUE);
+ VALUE (*write_i16)(VALUE, VALUE);
+ VALUE (*write_i32)(VALUE, VALUE);
+ VALUE (*write_i64)(VALUE, VALUE);
+ VALUE (*write_double)(VALUE, VALUE);
+ VALUE (*write_string)(VALUE, VALUE);
+ VALUE (*write_list_begin)(VALUE, VALUE, VALUE);
+ VALUE (*write_list_end)(VALUE);
+ VALUE (*write_set_begin)(VALUE, VALUE, VALUE);
+ VALUE (*write_set_end)(VALUE);
+ VALUE (*write_map_begin)(VALUE, VALUE, VALUE, VALUE);
+ VALUE (*write_map_end)(VALUE);
+ VALUE (*write_struct_begin)(VALUE, VALUE);
+ VALUE (*write_struct_end)(VALUE);
+ VALUE (*write_field_begin)(VALUE, VALUE, VALUE, VALUE);
+ VALUE (*write_field_end)(VALUE);
+ VALUE (*write_field_stop)(VALUE);
+ VALUE (*write_message_begin)(VALUE, VALUE, VALUE, VALUE);
+ VALUE (*write_message_end)(VALUE);
+
+ VALUE (*read_message_begin)(VALUE);
+ VALUE (*read_message_end)(VALUE);
+ VALUE (*read_field_begin)(VALUE);
+ VALUE (*read_field_end)(VALUE);
+ VALUE (*read_map_begin)(VALUE);
+ VALUE (*read_map_end)(VALUE);
+ VALUE (*read_list_begin)(VALUE);
+ VALUE (*read_list_end)(VALUE);
+ VALUE (*read_set_begin)(VALUE);
+ VALUE (*read_set_end)(VALUE);
+ VALUE (*read_byte)(VALUE);
+ VALUE (*read_bool)(VALUE);
+ VALUE (*read_i16)(VALUE);
+ VALUE (*read_i32)(VALUE);
+ VALUE (*read_i64)(VALUE);
+ VALUE (*read_double)(VALUE);
+ VALUE (*read_string)(VALUE);
+ VALUE (*read_struct_begin)(VALUE);
+ VALUE (*read_struct_end)(VALUE);
+
+} native_proto_method_table;
+
+void Init_struct();
\ No newline at end of file