update sproto for big-endian

This commit is contained in:
Cloud Wu
2014-11-26 21:18:49 +08:00
parent 84cb4bb4c1
commit 2b13eb250d
2 changed files with 15 additions and 15 deletions

View File

@@ -87,7 +87,7 @@ struct encode_ud {
int deep; int deep;
}; };
static int static int
encode(void *ud, const char *tagname, int type, int index, struct sproto_type *st, void *value, int length) { encode(void *ud, const char *tagname, int type, int index, struct sproto_type *st, void *value, int length) {
struct encode_ud *self = ud; struct encode_ud *self = ud;
lua_State *L = self->L; lua_State *L = self->L;
@@ -189,7 +189,7 @@ expand_buffer(lua_State *L, int osz, int nsz) {
lightuserdata sproto_type lightuserdata sproto_type
table source table source
return string return string
*/ */
static int static int
lencode(lua_State *L) { lencode(lua_State *L) {
@@ -229,7 +229,7 @@ struct decode_ud {
int deep; int deep;
}; };
static int static int
decode(void *ud, const char *tagname, int type, int index, struct sproto_type *st, void *value, int length) { decode(void *ud, const char *tagname, int type, int index, struct sproto_type *st, void *value, int length) {
struct decode_ud * self = ud; struct decode_ud * self = ud;
lua_State *L = self->L; lua_State *L = self->L;
@@ -252,12 +252,12 @@ decode(void *ud, const char *tagname, int type, int index, struct sproto_type *s
switch (type) { switch (type) {
case SPROTO_TINTEGER: { case SPROTO_TINTEGER: {
// notice: in lua 5.2, 52bit integer support (not 64) // notice: in lua 5.2, 52bit integer support (not 64)
lua_Integer v = *(lua_Integer *)value; lua_Integer v = *(uint64_t*)value;
lua_pushinteger(L, v); lua_pushinteger(L, v);
break; break;
} }
case SPROTO_TBOOLEAN: { case SPROTO_TBOOLEAN: {
int v = *(lua_Integer*)value; int v = *(uint64_t*)value;
lua_pushboolean(L,v); lua_pushboolean(L,v);
break; break;
} }

View File

@@ -500,7 +500,7 @@ sproto_dump(struct sproto *s) {
} }
// query // query
int int
sproto_prototag(struct sproto *sp, const char * name) { sproto_prototag(struct sproto *sp, const char * name) {
int i; int i;
for (i=0;i<sp->protocol_n;i++) { for (i=0;i<sp->protocol_n;i++) {
@@ -529,7 +529,7 @@ query_proto(struct sproto *sp, int tag) {
return NULL; return NULL;
} }
struct sproto_type * struct sproto_type *
sproto_protoquery(struct sproto *sp, int proto, int what) { sproto_protoquery(struct sproto *sp, int proto, int what) {
struct protocol * p; struct protocol * p;
if (what <0 || what >1) { if (what <0 || what >1) {
@@ -542,7 +542,7 @@ sproto_protoquery(struct sproto *sp, int proto, int what) {
return NULL; return NULL;
} }
const char * const char *
sproto_protoname(struct sproto *sp, int proto) { sproto_protoname(struct sproto *sp, int proto) {
struct protocol * p = query_proto(sp, proto); struct protocol * p = query_proto(sp, proto);
if (p) { if (p) {
@@ -551,7 +551,7 @@ sproto_protoname(struct sproto *sp, int proto) {
return NULL; return NULL;
} }
struct sproto_type * struct sproto_type *
sproto_type(struct sproto *sp, const char * type_name) { sproto_type(struct sproto *sp, const char * type_name) {
int i; int i;
for (i=0;i<sp->type_n;i++) { for (i=0;i<sp->type_n;i++) {
@@ -806,7 +806,7 @@ encode_array(sproto_callback cb, void *ud, struct field *f, uint8_t *data, int s
return fill_size(data, sz); return fill_size(data, sz);
} }
int int
sproto_encode(struct sproto_type *st, void * buffer, int size, sproto_callback cb, void *ud) { sproto_encode(struct sproto_type *st, void * buffer, int size, sproto_callback cb, void *ud) {
uint8_t * header = buffer; uint8_t * header = buffer;
uint8_t * data; uint8_t * data;
@@ -830,7 +830,7 @@ sproto_encode(struct sproto_type *st, void * buffer, int size, sproto_callback c
sz = encode_array(cb,ud, f, data, size); sz = encode_array(cb,ud, f, data, size);
} else { } else {
switch(type) { switch(type) {
case SPROTO_TINTEGER: case SPROTO_TINTEGER:
case SPROTO_TBOOLEAN: { case SPROTO_TBOOLEAN: {
union { union {
uint64_t u64; uint64_t u64;
@@ -971,7 +971,7 @@ decode_array(sproto_callback cb, void *ud, struct field *f, uint8_t * stream) {
} }
case SPROTO_TBOOLEAN: case SPROTO_TBOOLEAN:
for (i=0;i<sz;i++) { for (i=0;i<sz;i++) {
int value = stream[i]; uint64_t value = stream[i];
cb(ud, f->name, SPROTO_TBOOLEAN, i+1, NULL, &value, sizeof(value)); cb(ud, f->name, SPROTO_TBOOLEAN, i+1, NULL, &value, sizeof(value));
} }
break; break;
@@ -1050,7 +1050,7 @@ sproto_decode(struct sproto_type *st, const void * data, int size, sproto_callba
} }
break; break;
} }
case SPROTO_TSTRING: case SPROTO_TSTRING:
case SPROTO_TSTRUCT: { case SPROTO_TSTRUCT: {
uint32_t sz = todword(currentdata); uint32_t sz = todword(currentdata);
if (cb(ud, f->name, f->type, 0, f->st, currentdata+SIZEOF_LENGTH, sz)) if (cb(ud, f->name, f->type, 0, f->st, currentdata+SIZEOF_LENGTH, sz))
@@ -1124,7 +1124,7 @@ write_ff(const uint8_t * src, uint8_t * des, int n) {
} }
} }
int int
sproto_pack(const void * srcv, int srcsz, void * bufferv, int bufsz) { sproto_pack(const void * srcv, int srcsz, void * bufferv, int bufsz) {
uint8_t tmp[8]; uint8_t tmp[8];
int i; int i;
@@ -1181,7 +1181,7 @@ sproto_pack(const void * srcv, int srcsz, void * bufferv, int bufsz) {
return size; return size;
} }
int int
sproto_unpack(const void * srcv, int srcsz, void * bufferv, int bufsz) { sproto_unpack(const void * srcv, int srcsz, void * bufferv, int bufsz) {
const uint8_t * src = srcv; const uint8_t * src = srcv;
uint8_t * buffer = bufferv; uint8_t * buffer = bufferv;