| Kevin Clark | 916f353 | 2009-03-20 04:21:39 +0000 | [diff] [blame] | 1 | /** | 
 | 2 |  * Licensed to the Apache Software Foundation (ASF) under one | 
 | 3 |  * or more contributor license agreements. See the NOTICE file | 
 | 4 |  * distributed with this work for additional information | 
 | 5 |  * regarding copyright ownership. The ASF licenses this file | 
 | 6 |  * to you under the Apache License, Version 2.0 (the | 
 | 7 |  * "License"); you may not use this file except in compliance | 
 | 8 |  * with the License. You may obtain a copy of the License at | 
 | 9 |  * | 
 | 10 |  *   http://www.apache.org/licenses/LICENSE-2.0 | 
 | 11 |  * | 
 | 12 |  * Unless required by applicable law or agreed to in writing, | 
 | 13 |  * software distributed under the License is distributed on an | 
 | 14 |  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
 | 15 |  * KIND, either express or implied. See the License for the | 
 | 16 |  * specific language governing permissions and limitations | 
 | 17 |  * under the License. | 
 | 18 |  */ | 
 | 19 |  | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 20 | #include <ruby.h> | 
 | 21 | #include <stdbool.h> | 
| Bryan Duxbury | 1e80d44 | 2009-02-03 18:16:54 +0000 | [diff] [blame] | 22 | #include <stdint.h> | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 23 | #include <constants.h> | 
 | 24 | #include <struct.h> | 
| Bryan Duxbury | d815c21 | 2009-03-19 18:57:43 +0000 | [diff] [blame] | 25 | #include "macros.h" | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 26 |  | 
 | 27 | VALUE rb_thrift_binary_proto_native_qmark(VALUE self) { | 
 | 28 |   return Qtrue; | 
 | 29 | } | 
 | 30 |  | 
 | 31 |  | 
 | 32 |  | 
 | 33 | static int VERSION_1; | 
 | 34 | static int VERSION_MASK; | 
| Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame] | 35 | static int TYPE_MASK; | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 36 | static int BAD_VERSION; | 
| Bryan Duxbury | ad0ad82 | 2011-06-28 18:46:03 +0000 | [diff] [blame] | 37 | static ID rbuf_ivar_id; | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 38 |  | 
 | 39 | static void write_byte_direct(VALUE trans, int8_t b) { | 
 | 40 |   WRITE(trans, (char*)&b, 1); | 
 | 41 | } | 
 | 42 |  | 
 | 43 | static void write_i16_direct(VALUE trans, int16_t value) { | 
 | 44 |   char data[2]; | 
 | 45 |    | 
 | 46 |   data[1] = value; | 
 | 47 |   data[0] = (value >> 8); | 
 | 48 |  | 
 | 49 |   WRITE(trans, data, 2); | 
 | 50 | } | 
 | 51 |  | 
 | 52 | static void write_i32_direct(VALUE trans, int32_t value) { | 
 | 53 |   char data[4]; | 
 | 54 |  | 
 | 55 |   data[3] = value; | 
 | 56 |   data[2] = (value >> 8); | 
 | 57 |   data[1] = (value >> 16); | 
 | 58 |   data[0] = (value >> 24); | 
 | 59 |  | 
 | 60 |   WRITE(trans, data, 4); | 
 | 61 | } | 
 | 62 |  | 
 | 63 |  | 
 | 64 | static void write_i64_direct(VALUE trans, int64_t value) { | 
 | 65 |   char data[8]; | 
 | 66 |  | 
 | 67 |   data[7] = value; | 
 | 68 |   data[6] = (value >> 8); | 
 | 69 |   data[5] = (value >> 16); | 
 | 70 |   data[4] = (value >> 24); | 
 | 71 |   data[3] = (value >> 32); | 
 | 72 |   data[2] = (value >> 40); | 
 | 73 |   data[1] = (value >> 48); | 
 | 74 |   data[0] = (value >> 56); | 
 | 75 |  | 
 | 76 |   WRITE(trans, data, 8); | 
 | 77 | } | 
 | 78 |  | 
 | 79 | static void write_string_direct(VALUE trans, VALUE str) { | 
| Bryan Duxbury | 3647fc6 | 2009-09-02 20:05:07 +0000 | [diff] [blame] | 80 |   if (TYPE(str) != T_STRING) { | 
 | 81 |     rb_raise(rb_eStandardError, "Value should be a string");     | 
 | 82 |   } | 
| Bryan Duxbury | e3ab50d | 2009-03-25 21:06:53 +0000 | [diff] [blame] | 83 |   write_i32_direct(trans, RSTRING_LEN(str)); | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 84 |   rb_funcall(trans, write_method_id, 1, str); | 
 | 85 | } | 
 | 86 |  | 
 | 87 | //-------------------------------- | 
 | 88 | // interface writing methods | 
 | 89 | //-------------------------------- | 
 | 90 |  | 
 | 91 | VALUE rb_thrift_binary_proto_write_message_end(VALUE self) { | 
 | 92 |   return Qnil; | 
 | 93 | } | 
 | 94 |  | 
 | 95 | VALUE rb_thrift_binary_proto_write_struct_begin(VALUE self, VALUE name) { | 
 | 96 |   return Qnil; | 
 | 97 | } | 
 | 98 |  | 
 | 99 | VALUE rb_thrift_binary_proto_write_struct_end(VALUE self) { | 
 | 100 |   return Qnil; | 
 | 101 | } | 
 | 102 |  | 
 | 103 | VALUE rb_thrift_binary_proto_write_field_end(VALUE self) { | 
 | 104 |   return Qnil; | 
 | 105 | } | 
 | 106 |  | 
 | 107 | VALUE rb_thrift_binary_proto_write_map_end(VALUE self) { | 
 | 108 |   return Qnil; | 
 | 109 | } | 
 | 110 |  | 
 | 111 | VALUE rb_thrift_binary_proto_write_list_end(VALUE self) { | 
 | 112 |   return Qnil; | 
 | 113 | } | 
 | 114 |  | 
 | 115 | VALUE rb_thrift_binary_proto_write_set_end(VALUE self) { | 
 | 116 |   return Qnil; | 
 | 117 | } | 
 | 118 |  | 
 | 119 | VALUE rb_thrift_binary_proto_write_message_begin(VALUE self, VALUE name, VALUE type, VALUE seqid) { | 
 | 120 |   VALUE trans = GET_TRANSPORT(self); | 
| Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame] | 121 |   VALUE strict_write = GET_STRICT_WRITE(self); | 
 | 122 |  | 
 | 123 |   if (strict_write == Qtrue) { | 
 | 124 |     write_i32_direct(trans, VERSION_1 | FIX2INT(type)); | 
 | 125 |     write_string_direct(trans, name); | 
 | 126 |     write_i32_direct(trans, FIX2INT(seqid)); | 
 | 127 |   } else { | 
 | 128 |     write_string_direct(trans, name); | 
| Bryan Duxbury | d40731e | 2009-03-20 02:21:05 +0000 | [diff] [blame] | 129 |     write_byte_direct(trans, FIX2INT(type)); | 
| Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame] | 130 |     write_i32_direct(trans, FIX2INT(seqid)); | 
 | 131 |   } | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 132 |    | 
 | 133 |   return Qnil; | 
 | 134 | } | 
 | 135 |  | 
 | 136 | VALUE rb_thrift_binary_proto_write_field_begin(VALUE self, VALUE name, VALUE type, VALUE id) { | 
 | 137 |   VALUE trans = GET_TRANSPORT(self); | 
 | 138 |   write_byte_direct(trans, FIX2INT(type)); | 
 | 139 |   write_i16_direct(trans, FIX2INT(id)); | 
 | 140 |    | 
 | 141 |   return Qnil; | 
 | 142 | } | 
 | 143 |  | 
 | 144 | VALUE rb_thrift_binary_proto_write_field_stop(VALUE self) { | 
 | 145 |   write_byte_direct(GET_TRANSPORT(self), TTYPE_STOP); | 
 | 146 |   return Qnil; | 
 | 147 | } | 
 | 148 |  | 
 | 149 | VALUE rb_thrift_binary_proto_write_map_begin(VALUE self, VALUE ktype, VALUE vtype, VALUE size) { | 
 | 150 |   VALUE trans = GET_TRANSPORT(self); | 
 | 151 |   write_byte_direct(trans, FIX2INT(ktype)); | 
 | 152 |   write_byte_direct(trans, FIX2INT(vtype)); | 
 | 153 |   write_i32_direct(trans, FIX2INT(size)); | 
 | 154 |    | 
 | 155 |   return Qnil; | 
 | 156 | } | 
 | 157 |  | 
 | 158 | VALUE rb_thrift_binary_proto_write_list_begin(VALUE self, VALUE etype, VALUE size) { | 
 | 159 |   VALUE trans = GET_TRANSPORT(self); | 
 | 160 |   write_byte_direct(trans, FIX2INT(etype)); | 
 | 161 |   write_i32_direct(trans, FIX2INT(size)); | 
 | 162 |    | 
 | 163 |   return Qnil; | 
 | 164 | } | 
 | 165 |  | 
 | 166 | VALUE rb_thrift_binary_proto_write_set_begin(VALUE self, VALUE etype, VALUE size) { | 
 | 167 |   rb_thrift_binary_proto_write_list_begin(self, etype, size); | 
 | 168 |   return Qnil; | 
 | 169 | } | 
 | 170 |  | 
 | 171 | VALUE rb_thrift_binary_proto_write_bool(VALUE self, VALUE b) { | 
 | 172 |   write_byte_direct(GET_TRANSPORT(self), RTEST(b) ? 1 : 0); | 
 | 173 |   return Qnil; | 
 | 174 | } | 
 | 175 |  | 
 | 176 | VALUE rb_thrift_binary_proto_write_byte(VALUE self, VALUE byte) { | 
 | 177 |   CHECK_NIL(byte); | 
 | 178 |   write_byte_direct(GET_TRANSPORT(self), NUM2INT(byte)); | 
 | 179 |   return Qnil; | 
 | 180 | } | 
 | 181 |  | 
 | 182 | VALUE rb_thrift_binary_proto_write_i16(VALUE self, VALUE i16) { | 
 | 183 |   CHECK_NIL(i16); | 
 | 184 |   write_i16_direct(GET_TRANSPORT(self), FIX2INT(i16)); | 
 | 185 |   return Qnil; | 
 | 186 | } | 
 | 187 |  | 
 | 188 | VALUE rb_thrift_binary_proto_write_i32(VALUE self, VALUE i32) { | 
 | 189 |   CHECK_NIL(i32); | 
 | 190 |   write_i32_direct(GET_TRANSPORT(self), NUM2INT(i32)); | 
 | 191 |   return Qnil; | 
 | 192 | } | 
 | 193 |  | 
 | 194 | VALUE rb_thrift_binary_proto_write_i64(VALUE self, VALUE i64) { | 
 | 195 |   CHECK_NIL(i64); | 
 | 196 |   write_i64_direct(GET_TRANSPORT(self), NUM2LL(i64)); | 
 | 197 |   return Qnil; | 
 | 198 | } | 
 | 199 |  | 
 | 200 | VALUE rb_thrift_binary_proto_write_double(VALUE self, VALUE dub) { | 
 | 201 |   CHECK_NIL(dub); | 
 | 202 |   // Unfortunately, bitwise_cast doesn't work in C.  Bad C! | 
 | 203 |   union { | 
 | 204 |     double f; | 
 | 205 |     int64_t t; | 
 | 206 |   } transfer; | 
| Bryan Duxbury | e3ab50d | 2009-03-25 21:06:53 +0000 | [diff] [blame] | 207 |   transfer.f = RFLOAT_VALUE(rb_Float(dub)); | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 208 |   write_i64_direct(GET_TRANSPORT(self), transfer.t); | 
 | 209 |  | 
 | 210 |   return Qnil; | 
 | 211 | } | 
 | 212 |  | 
 | 213 | VALUE rb_thrift_binary_proto_write_string(VALUE self, VALUE str) { | 
 | 214 |   CHECK_NIL(str); | 
 | 215 |   VALUE trans = GET_TRANSPORT(self); | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 216 |   write_string_direct(trans, str); | 
 | 217 |   return Qnil; | 
 | 218 | } | 
 | 219 |  | 
 | 220 | //--------------------------------------- | 
 | 221 | // interface reading methods | 
 | 222 | //--------------------------------------- | 
 | 223 |  | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 224 | VALUE rb_thrift_binary_proto_read_string(VALUE self); | 
 | 225 | VALUE rb_thrift_binary_proto_read_byte(VALUE self); | 
 | 226 | VALUE rb_thrift_binary_proto_read_i32(VALUE self); | 
 | 227 | VALUE rb_thrift_binary_proto_read_i16(VALUE self); | 
 | 228 |  | 
 | 229 | static char read_byte_direct(VALUE self) { | 
| Bryan Duxbury | ad0ad82 | 2011-06-28 18:46:03 +0000 | [diff] [blame] | 230 |   VALUE byte = rb_funcall(GET_TRANSPORT(self), read_byte_method_id, 0); | 
 | 231 |   return (char)(FIX2INT(byte)); | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 232 | } | 
 | 233 |  | 
 | 234 | static int16_t read_i16_direct(VALUE self) { | 
| Bryan Duxbury | ad0ad82 | 2011-06-28 18:46:03 +0000 | [diff] [blame] | 235 |   VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id); | 
 | 236 |   rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(2)); | 
 | 237 |   return (int16_t)(((uint8_t)(RSTRING_PTR(rbuf)[1])) | ((uint16_t)((RSTRING_PTR(rbuf)[0]) << 8))); | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 238 | } | 
 | 239 |  | 
 | 240 | static int32_t read_i32_direct(VALUE self) { | 
| Bryan Duxbury | ad0ad82 | 2011-06-28 18:46:03 +0000 | [diff] [blame] | 241 |   VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id); | 
 | 242 |   rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(4)); | 
 | 243 |   return ((uint8_t)(RSTRING_PTR(rbuf)[3])) | | 
 | 244 |     (((uint8_t)(RSTRING_PTR(rbuf)[2])) << 8) | | 
 | 245 |     (((uint8_t)(RSTRING_PTR(rbuf)[1])) << 16) | | 
 | 246 |     (((uint8_t)(RSTRING_PTR(rbuf)[0])) << 24); | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 247 | } | 
 | 248 |  | 
 | 249 | static int64_t read_i64_direct(VALUE self) { | 
| Bryan Duxbury | ad0ad82 | 2011-06-28 18:46:03 +0000 | [diff] [blame] | 250 |   VALUE rbuf = rb_ivar_get(self, rbuf_ivar_id); | 
 | 251 |   rb_funcall(GET_TRANSPORT(self), read_into_buffer_method_id, 2, rbuf, INT2FIX(8)); | 
 | 252 |   uint64_t hi = ((uint8_t)(RSTRING_PTR(rbuf)[3])) | | 
 | 253 |     (((uint8_t)(RSTRING_PTR(rbuf)[2])) << 8) | | 
 | 254 |     (((uint8_t)(RSTRING_PTR(rbuf)[1])) << 16) | | 
 | 255 |     (((uint8_t)(RSTRING_PTR(rbuf)[0])) << 24); | 
 | 256 |   uint32_t lo = ((uint8_t)(RSTRING_PTR(rbuf)[7])) | | 
 | 257 |     (((uint8_t)(RSTRING_PTR(rbuf)[6])) << 8) | | 
 | 258 |     (((uint8_t)(RSTRING_PTR(rbuf)[5])) << 16) | | 
 | 259 |     (((uint8_t)(RSTRING_PTR(rbuf)[4])) << 24); | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 260 |   return (hi << 32) | lo; | 
 | 261 | } | 
 | 262 |  | 
 | 263 | static VALUE get_protocol_exception(VALUE code, VALUE message) { | 
 | 264 |   VALUE args[2]; | 
 | 265 |   args[0] = code; | 
 | 266 |   args[1] = message; | 
 | 267 |   return rb_class_new_instance(2, (VALUE*)&args, protocol_exception_class); | 
 | 268 | } | 
 | 269 |  | 
 | 270 | VALUE rb_thrift_binary_proto_read_message_end(VALUE self) { | 
 | 271 |   return Qnil; | 
 | 272 | } | 
 | 273 |  | 
 | 274 | VALUE rb_thift_binary_proto_read_struct_begin(VALUE self) { | 
 | 275 |   return Qnil; | 
 | 276 | } | 
 | 277 |  | 
 | 278 | VALUE rb_thift_binary_proto_read_struct_end(VALUE self) { | 
 | 279 |   return Qnil; | 
 | 280 | } | 
 | 281 |  | 
 | 282 | VALUE rb_thift_binary_proto_read_field_end(VALUE self) { | 
 | 283 |   return Qnil; | 
 | 284 | } | 
 | 285 |  | 
 | 286 | VALUE rb_thift_binary_proto_read_map_end(VALUE self) { | 
 | 287 |   return Qnil; | 
 | 288 | } | 
 | 289 |  | 
 | 290 | VALUE rb_thift_binary_proto_read_list_end(VALUE self) { | 
 | 291 |   return Qnil; | 
 | 292 | } | 
 | 293 |  | 
 | 294 | VALUE rb_thift_binary_proto_read_set_end(VALUE self) { | 
 | 295 |   return Qnil; | 
 | 296 | } | 
 | 297 |  | 
 | 298 | VALUE rb_thrift_binary_proto_read_message_begin(VALUE self) { | 
| Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame] | 299 |   VALUE strict_read = GET_STRICT_READ(self); | 
 | 300 |   VALUE name, seqid; | 
 | 301 |   int type; | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 302 |    | 
| Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame] | 303 |   int version = read_i32_direct(self); | 
 | 304 |    | 
 | 305 |   if (version < 0) { | 
 | 306 |     if ((version & VERSION_MASK) != VERSION_1) { | 
 | 307 |       rb_exc_raise(get_protocol_exception(INT2FIX(BAD_VERSION), rb_str_new2("Missing version identifier"))); | 
 | 308 |     } | 
 | 309 |     type = version & TYPE_MASK; | 
 | 310 |     name = rb_thrift_binary_proto_read_string(self); | 
 | 311 |     seqid = rb_thrift_binary_proto_read_i32(self); | 
 | 312 |   } else { | 
 | 313 |     if (strict_read == Qtrue) { | 
 | 314 |       rb_exc_raise(get_protocol_exception(INT2FIX(BAD_VERSION), rb_str_new2("No version identifier, old protocol client?"))); | 
 | 315 |     } | 
 | 316 |     name = READ(self, version); | 
| Bryan Duxbury | ac002d3 | 2009-03-31 23:48:36 +0000 | [diff] [blame] | 317 |     type = read_byte_direct(self); | 
| Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame] | 318 |     seqid = rb_thrift_binary_proto_read_i32(self); | 
 | 319 |   } | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 320 |    | 
 | 321 |   return rb_ary_new3(3, name, INT2FIX(type), seqid); | 
 | 322 | } | 
 | 323 |  | 
 | 324 | VALUE rb_thrift_binary_proto_read_field_begin(VALUE self) { | 
 | 325 |   int type = read_byte_direct(self); | 
 | 326 |   if (type == TTYPE_STOP) { | 
 | 327 |     return rb_ary_new3(3, Qnil, INT2FIX(type), INT2FIX(0)); | 
 | 328 |   } else { | 
 | 329 |     VALUE id = rb_thrift_binary_proto_read_i16(self); | 
 | 330 |     return rb_ary_new3(3, Qnil, INT2FIX(type), id); | 
 | 331 |   } | 
 | 332 | } | 
 | 333 |  | 
 | 334 | VALUE rb_thrift_binary_proto_read_map_begin(VALUE self) { | 
 | 335 |   VALUE ktype = rb_thrift_binary_proto_read_byte(self); | 
 | 336 |   VALUE vtype = rb_thrift_binary_proto_read_byte(self); | 
 | 337 |   VALUE size = rb_thrift_binary_proto_read_i32(self); | 
 | 338 |   return rb_ary_new3(3, ktype, vtype, size); | 
 | 339 | } | 
 | 340 |  | 
 | 341 | VALUE rb_thrift_binary_proto_read_list_begin(VALUE self) { | 
 | 342 |   VALUE etype = rb_thrift_binary_proto_read_byte(self); | 
 | 343 |   VALUE size = rb_thrift_binary_proto_read_i32(self); | 
 | 344 |   return rb_ary_new3(2, etype, size); | 
 | 345 | } | 
 | 346 |  | 
 | 347 | VALUE rb_thrift_binary_proto_read_set_begin(VALUE self) { | 
 | 348 |   return rb_thrift_binary_proto_read_list_begin(self); | 
 | 349 | } | 
 | 350 |  | 
 | 351 | VALUE rb_thrift_binary_proto_read_bool(VALUE self) { | 
 | 352 |   char byte = read_byte_direct(self); | 
| Bryan Duxbury | 5b8b484 | 2009-04-01 20:10:15 +0000 | [diff] [blame] | 353 |   return byte != 0 ? Qtrue : Qfalse; | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 354 | } | 
 | 355 |  | 
 | 356 | VALUE rb_thrift_binary_proto_read_byte(VALUE self) { | 
 | 357 |   return INT2FIX(read_byte_direct(self)); | 
 | 358 | } | 
 | 359 |  | 
 | 360 | VALUE rb_thrift_binary_proto_read_i16(VALUE self) { | 
 | 361 |   return INT2FIX(read_i16_direct(self)); | 
 | 362 | } | 
 | 363 |  | 
 | 364 | VALUE rb_thrift_binary_proto_read_i32(VALUE self) { | 
 | 365 |   return INT2NUM(read_i32_direct(self)); | 
 | 366 | } | 
 | 367 |  | 
 | 368 | VALUE rb_thrift_binary_proto_read_i64(VALUE self) { | 
 | 369 |   return LL2NUM(read_i64_direct(self)); | 
 | 370 | } | 
 | 371 |  | 
 | 372 | VALUE rb_thrift_binary_proto_read_double(VALUE self) { | 
 | 373 |   union { | 
 | 374 |     double f; | 
 | 375 |     int64_t t; | 
 | 376 |   } transfer; | 
 | 377 |   transfer.t = read_i64_direct(self); | 
 | 378 |   return rb_float_new(transfer.f); | 
 | 379 | } | 
 | 380 |  | 
 | 381 | VALUE rb_thrift_binary_proto_read_string(VALUE self) { | 
 | 382 |   int size = read_i32_direct(self); | 
 | 383 |   return READ(self, size); | 
 | 384 | } | 
 | 385 |  | 
 | 386 | void Init_binary_protocol_accelerated() { | 
 | 387 |   VALUE thrift_binary_protocol_class = rb_const_get(thrift_module, rb_intern("BinaryProtocol")); | 
| Bryan Duxbury | d2cc5bb | 2010-07-28 21:00:06 +0000 | [diff] [blame] | 388 |  | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 389 |   VERSION_1 = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_1"))); | 
 | 390 |   VERSION_MASK = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("VERSION_MASK"))); | 
| Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame] | 391 |   TYPE_MASK = rb_num2ll(rb_const_get(thrift_binary_protocol_class, rb_intern("TYPE_MASK"))); | 
| Bryan Duxbury | d2cc5bb | 2010-07-28 21:00:06 +0000 | [diff] [blame] | 392 |  | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 393 |   VALUE bpa_class = rb_define_class_under(thrift_module, "BinaryProtocolAccelerated", thrift_binary_protocol_class); | 
| Bryan Duxbury | d2cc5bb | 2010-07-28 21:00:06 +0000 | [diff] [blame] | 394 |  | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 395 |   rb_define_method(bpa_class, "native?", rb_thrift_binary_proto_native_qmark, 0); | 
| Bryan Duxbury | d2cc5bb | 2010-07-28 21:00:06 +0000 | [diff] [blame] | 396 |  | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 397 |   rb_define_method(bpa_class, "write_message_begin", rb_thrift_binary_proto_write_message_begin, 3); | 
 | 398 |   rb_define_method(bpa_class, "write_field_begin",   rb_thrift_binary_proto_write_field_begin, 3); | 
 | 399 |   rb_define_method(bpa_class, "write_field_stop",    rb_thrift_binary_proto_write_field_stop, 0); | 
 | 400 |   rb_define_method(bpa_class, "write_map_begin",     rb_thrift_binary_proto_write_map_begin, 3); | 
 | 401 |   rb_define_method(bpa_class, "write_list_begin",    rb_thrift_binary_proto_write_list_begin, 2); | 
 | 402 |   rb_define_method(bpa_class, "write_set_begin",     rb_thrift_binary_proto_write_set_begin, 2); | 
 | 403 |   rb_define_method(bpa_class, "write_byte",          rb_thrift_binary_proto_write_byte, 1); | 
 | 404 |   rb_define_method(bpa_class, "write_bool",          rb_thrift_binary_proto_write_bool, 1); | 
 | 405 |   rb_define_method(bpa_class, "write_i16",           rb_thrift_binary_proto_write_i16, 1); | 
 | 406 |   rb_define_method(bpa_class, "write_i32",           rb_thrift_binary_proto_write_i32, 1); | 
 | 407 |   rb_define_method(bpa_class, "write_i64",           rb_thrift_binary_proto_write_i64, 1); | 
 | 408 |   rb_define_method(bpa_class, "write_double",        rb_thrift_binary_proto_write_double, 1); | 
 | 409 |   rb_define_method(bpa_class, "write_string",        rb_thrift_binary_proto_write_string, 1); | 
 | 410 |   // unused methods | 
 | 411 |   rb_define_method(bpa_class, "write_message_end", rb_thrift_binary_proto_write_message_end, 0); | 
 | 412 |   rb_define_method(bpa_class, "write_struct_begin", rb_thrift_binary_proto_write_struct_begin, 1); | 
 | 413 |   rb_define_method(bpa_class, "write_struct_end", rb_thrift_binary_proto_write_struct_end, 0); | 
 | 414 |   rb_define_method(bpa_class, "write_field_end", rb_thrift_binary_proto_write_field_end, 0); | 
 | 415 |   rb_define_method(bpa_class, "write_map_end", rb_thrift_binary_proto_write_map_end, 0); | 
 | 416 |   rb_define_method(bpa_class, "write_list_end", rb_thrift_binary_proto_write_list_end, 0); | 
 | 417 |   rb_define_method(bpa_class, "write_set_end", rb_thrift_binary_proto_write_set_end, 0); | 
| Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 418 |  | 
 | 419 |   rb_define_method(bpa_class, "read_message_begin",  rb_thrift_binary_proto_read_message_begin, 0); | 
 | 420 |   rb_define_method(bpa_class, "read_field_begin",    rb_thrift_binary_proto_read_field_begin, 0); | 
 | 421 |   rb_define_method(bpa_class, "read_map_begin",      rb_thrift_binary_proto_read_map_begin, 0); | 
 | 422 |   rb_define_method(bpa_class, "read_list_begin",     rb_thrift_binary_proto_read_list_begin, 0); | 
 | 423 |   rb_define_method(bpa_class, "read_set_begin",      rb_thrift_binary_proto_read_set_begin, 0); | 
 | 424 |   rb_define_method(bpa_class, "read_byte",           rb_thrift_binary_proto_read_byte, 0); | 
 | 425 |   rb_define_method(bpa_class, "read_bool",           rb_thrift_binary_proto_read_bool, 0); | 
 | 426 |   rb_define_method(bpa_class, "read_i16",            rb_thrift_binary_proto_read_i16, 0); | 
 | 427 |   rb_define_method(bpa_class, "read_i32",            rb_thrift_binary_proto_read_i32, 0); | 
 | 428 |   rb_define_method(bpa_class, "read_i64",            rb_thrift_binary_proto_read_i64, 0); | 
 | 429 |   rb_define_method(bpa_class, "read_double",         rb_thrift_binary_proto_read_double, 0); | 
 | 430 |   rb_define_method(bpa_class, "read_string",         rb_thrift_binary_proto_read_string, 0); | 
 | 431 |   // unused methods | 
 | 432 |   rb_define_method(bpa_class, "read_message_end", rb_thrift_binary_proto_read_message_end, 0); | 
 | 433 |   rb_define_method(bpa_class, "read_struct_begin", rb_thift_binary_proto_read_struct_begin, 0); | 
 | 434 |   rb_define_method(bpa_class, "read_struct_end", rb_thift_binary_proto_read_struct_end, 0); | 
 | 435 |   rb_define_method(bpa_class, "read_field_end", rb_thift_binary_proto_read_field_end, 0); | 
 | 436 |   rb_define_method(bpa_class, "read_map_end", rb_thift_binary_proto_read_map_end, 0); | 
 | 437 |   rb_define_method(bpa_class, "read_list_end", rb_thift_binary_proto_read_list_end, 0); | 
 | 438 |   rb_define_method(bpa_class, "read_set_end", rb_thift_binary_proto_read_set_end, 0); | 
| Bryan Duxbury | ad0ad82 | 2011-06-28 18:46:03 +0000 | [diff] [blame] | 439 |  | 
 | 440 |   rbuf_ivar_id = rb_intern("@rbuf"); | 
| Bryan Duxbury | 1e80d44 | 2009-02-03 18:16:54 +0000 | [diff] [blame] | 441 | } |