Skip to content

Commit

Permalink
bugfix issue #185
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Oct 22, 2014
1 parent 9bdc365 commit fc89832
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lualib-src/lua-seri.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,60 +120,60 @@ rb_read(struct read_block *rb, void *buffer, int sz) {

static inline void
wb_nil(struct write_block *wb) {
int n = TYPE_NIL;
uint8_t n = TYPE_NIL;
wb_push(wb, &n, 1);
}

static inline void
wb_boolean(struct write_block *wb, int boolean) {
int n = COMBINE_TYPE(TYPE_BOOLEAN , boolean ? 1 : 0);
uint8_t n = COMBINE_TYPE(TYPE_BOOLEAN , boolean ? 1 : 0);
wb_push(wb, &n, 1);
}

static inline void
wb_integer(struct write_block *wb, int v, int type) {
if (v == 0) {
int n = COMBINE_TYPE(type , 0);
uint8_t n = COMBINE_TYPE(type , 0);
wb_push(wb, &n, 1);
} else if (v<0) {
int n = COMBINE_TYPE(type , 4);
uint8_t n = COMBINE_TYPE(type , 4);
wb_push(wb, &n, 1);
wb_push(wb, &v, 4);
} else if (v<0x100) {
int n = COMBINE_TYPE(type , 1);
uint8_t n = COMBINE_TYPE(type , 1);
wb_push(wb, &n, 1);
uint8_t byte = (uint8_t)v;
wb_push(wb, &byte, 1);
} else if (v<0x10000) {
int n = COMBINE_TYPE(type , 2);
uint8_t n = COMBINE_TYPE(type , 2);
wb_push(wb, &n, 1);
uint16_t word = (uint16_t)v;
wb_push(wb, &word, 2);
} else {
int n = COMBINE_TYPE(type , 4);
uint8_t n = COMBINE_TYPE(type , 4);
wb_push(wb, &n, 1);
wb_push(wb, &v, 4);
}
}

static inline void
wb_number(struct write_block *wb, double v) {
int n = COMBINE_TYPE(TYPE_NUMBER , 8);
uint8_t n = COMBINE_TYPE(TYPE_NUMBER , 8);
wb_push(wb, &n, 1);
wb_push(wb, &v, 8);
}

static inline void
wb_pointer(struct write_block *wb, void *v) {
int n = TYPE_USERDATA;
uint8_t n = TYPE_USERDATA;
wb_push(wb, &n, 1);
wb_push(wb, &v, sizeof(v));
}

static inline void
wb_string(struct write_block *wb, const char *str, int len) {
if (len < MAX_COOKIE) {
int n = COMBINE_TYPE(TYPE_SHORT_STRING, len);
uint8_t n = COMBINE_TYPE(TYPE_SHORT_STRING, len);
wb_push(wb, &n, 1);
if (len > 0) {
wb_push(wb, str, len);
Expand Down Expand Up @@ -201,11 +201,11 @@ static int
wb_table_array(lua_State *L, struct write_block * wb, int index, int depth) {
int array_size = lua_rawlen(L,index);
if (array_size >= MAX_COOKIE-1) {
int n = COMBINE_TYPE(TYPE_TABLE, MAX_COOKIE-1);
uint8_t n = COMBINE_TYPE(TYPE_TABLE, MAX_COOKIE-1);
wb_push(wb, &n, 1);
wb_integer(wb, array_size,TYPE_NUMBER);
} else {
int n = COMBINE_TYPE(TYPE_TABLE, array_size);
uint8_t n = COMBINE_TYPE(TYPE_TABLE, array_size);
wb_push(wb, &n, 1);
}

Expand Down

0 comments on commit fc89832

Please sign in to comment.