Skip to content

Commit

Permalink
reduce diff
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Apr 14, 2016
1 parent aa084e7 commit 132b21b
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions ext/bert/c/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@ static VALUE rb_mBERT;
static VALUE rb_cDecode;
static VALUE rb_cTuple;

typedef struct bert_buf bert_buf;

typedef VALUE (*bert_ptr)(struct bert_buf *buf);

struct bert_buf {
const uint8_t *data;
const uint8_t *end;
bert_ptr *callbacks;
};

static VALUE bert_read_invalid(struct bert_buf *buf);
Expand All @@ -51,10 +46,10 @@ static VALUE bert_read_list(struct bert_buf *buf);
static VALUE bert_read_bin(struct bert_buf *buf);
static VALUE bert_read_enc_string(struct bert_buf *buf);
static VALUE bert_read_unicode_string(struct bert_buf *buf);
static VALUE bert_read_unicode_string(struct bert_buf *buf);
static VALUE bert_read_sbignum(struct bert_buf *buf);
static VALUE bert_read_lbignum(struct bert_buf *buf);

typedef VALUE (*bert_ptr)(struct bert_buf *buf);
static bert_ptr bert_callbacks[] = {
&bert_read_sint,
&bert_read_int,
Expand Down Expand Up @@ -118,7 +113,7 @@ static VALUE bert_read(struct bert_buf *buf)
if (!BERT_VALID_TYPE(type))
rb_raise(rb_eRuntimeError, "Invalid tag '%d' for term", type);

return buf->callbacks[type - BERT_TYPE_OFFSET](buf);
return bert_callbacks[type - BERT_TYPE_OFFSET](buf);
}

static VALUE bert_read_dict(struct bert_buf *buf)
Expand Down Expand Up @@ -517,17 +512,11 @@ static VALUE rb_bert_decode(VALUE klass, VALUE rb_string)
bert_buf_ensure(&buf, 1);

proto_version = bert_buf_read8(&buf);
switch(proto_version) {
case ERL_VERSION:
buf.callbacks = bert_callbacks;
break;
case ERL_VERSION2:
buf.callbacks = bert_callbacks;
break;
default:
rb_raise(rb_eTypeError, "Invalid magic value for BERT string");
if (proto_version == ERL_VERSION || proto_version == ERL_VERSION2) {
return bert_read(&buf);
} else {
rb_raise(rb_eTypeError, "Invalid magic value for BERT string");
}
return bert_read(&buf);
}

static VALUE rb_bert_impl(VALUE klass)
Expand Down

0 comments on commit 132b21b

Please sign in to comment.