@@ -27,14 +27,9 @@ static VALUE rb_mBERT;
2727static VALUE rb_cDecode ;
2828static VALUE rb_cTuple ;
2929
30- typedef struct bert_buf bert_buf ;
31-
32- typedef VALUE (* bert_ptr )(struct bert_buf * buf );
33-
3430struct bert_buf {
3531 const uint8_t * data ;
3632 const uint8_t * end ;
37- bert_ptr * callbacks ;
3833};
3934
4035static VALUE bert_read_invalid (struct bert_buf * buf );
@@ -51,10 +46,10 @@ static VALUE bert_read_list(struct bert_buf *buf);
5146static VALUE bert_read_bin (struct bert_buf * buf );
5247static VALUE bert_read_enc_string (struct bert_buf * buf );
5348static VALUE bert_read_unicode_string (struct bert_buf * buf );
54- static VALUE bert_read_unicode_string (struct bert_buf * buf );
5549static VALUE bert_read_sbignum (struct bert_buf * buf );
5650static VALUE bert_read_lbignum (struct bert_buf * buf );
5751
52+ typedef VALUE (* bert_ptr )(struct bert_buf * buf );
5853static bert_ptr bert_callbacks [] = {
5954 & bert_read_sint ,
6055 & bert_read_int ,
@@ -118,7 +113,7 @@ static VALUE bert_read(struct bert_buf *buf)
118113 if (!BERT_VALID_TYPE (type ))
119114 rb_raise (rb_eRuntimeError , "Invalid tag '%d' for term" , type );
120115
121- return buf -> callbacks [type - BERT_TYPE_OFFSET ](buf );
116+ return bert_callbacks [type - BERT_TYPE_OFFSET ](buf );
122117}
123118
124119static VALUE bert_read_dict (struct bert_buf * buf )
@@ -517,17 +512,11 @@ static VALUE rb_bert_decode(VALUE klass, VALUE rb_string)
517512 bert_buf_ensure (& buf , 1 );
518513
519514 proto_version = bert_buf_read8 (& buf );
520- switch (proto_version ) {
521- case ERL_VERSION :
522- buf .callbacks = bert_callbacks ;
523- break ;
524- case ERL_VERSION2 :
525- buf .callbacks = bert_callbacks ;
526- break ;
527- default :
528- rb_raise (rb_eTypeError , "Invalid magic value for BERT string" );
515+ if (proto_version == ERL_VERSION || proto_version == ERL_VERSION2 ) {
516+ return bert_read (& buf );
517+ } else {
518+ rb_raise (rb_eTypeError , "Invalid magic value for BERT string" );
529519 }
530- return bert_read (& buf );
531520}
532521
533522static VALUE rb_bert_impl (VALUE klass )
0 commit comments