From 44485b195c28ddf15baec967b1e9e71b3df4b753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E7=86=8F?= Date: Mon, 3 Aug 2020 22:54:04 +0800 Subject: [PATCH] update sproto double array (#1227) Co-authored-by: zixun --- lualib-src/sproto/lsproto.c | 6 +++--- lualib-src/sproto/sproto.c | 6 ++++-- lualib-src/sproto/sproto.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lualib-src/sproto/lsproto.c b/lualib-src/sproto/lsproto.c index 16d36554..214ec8df 100644 --- a/lualib-src/sproto/lsproto.c +++ b/lualib-src/sproto/lsproto.c @@ -242,7 +242,7 @@ encode(const struct sproto_arg *args) { return 8; } } - case SPROTO_DOUBLE: { + case SPROTO_TDOUBLE: { lua_Number v = lua_tonumber(L, -1); *(double*)args->value = (double)v; return 8; @@ -407,7 +407,7 @@ decode(const struct sproto_arg *args) { } break; } - case SPROTO_DOUBLE: { + case SPROTO_TDOUBLE: { double v = *(double*)args->value; lua_pushnumber(L, v); break; @@ -688,7 +688,7 @@ push_default(const struct sproto_arg *args, int array) { else lua_pushinteger(L, 0); break; - case SPROTO_DOUBLE: + case SPROTO_TDOUBLE: lua_pushnumber(L, 0.0); break; case SPROTO_TBOOLEAN: diff --git a/lualib-src/sproto/sproto.c b/lualib-src/sproto/sproto.c index 4d38d51c..62c336e9 100644 --- a/lualib-src/sproto/sproto.c +++ b/lualib-src/sproto/sproto.c @@ -849,6 +849,7 @@ encode_array(sproto_callback cb, struct sproto_arg *args, uint8_t *data, int siz size -= SIZEOF_LENGTH; buffer = data + SIZEOF_LENGTH; switch (args->type) { + case SPROTO_TDOUBLE: case SPROTO_TINTEGER: { int noarray; buffer = encode_integer_array(cb,args,buffer,size, &noarray); @@ -944,7 +945,7 @@ sproto_encode(const struct sproto_type *st, void * buffer, int size, sproto_call args.type = type; args.index = 0; switch(type) { - case SPROTO_DOUBLE: + case SPROTO_TDOUBLE: case SPROTO_TINTEGER: case SPROTO_TBOOLEAN: { union { @@ -1067,6 +1068,7 @@ decode_array(sproto_callback cb, struct sproto_arg *args, uint8_t * stream) { } stream += SIZEOF_LENGTH; switch (type) { + case SPROTO_TDOUBLE: case SPROTO_TINTEGER: { int len = *stream; ++stream; @@ -1178,7 +1180,7 @@ sproto_decode(const struct sproto_type *st, const void * data, int size, sproto_ } } else { switch (f->type) { - case SPROTO_DOUBLE: + case SPROTO_TDOUBLE: case SPROTO_TINTEGER: { uint32_t sz = todword(currentdata); if (sz == SIZEOF_INT32) { diff --git a/lualib-src/sproto/sproto.h b/lualib-src/sproto/sproto.h index 1fb9252e..0ee5255b 100644 --- a/lualib-src/sproto/sproto.h +++ b/lualib-src/sproto/sproto.h @@ -13,7 +13,7 @@ struct sproto_type; #define SPROTO_TINTEGER 0 #define SPROTO_TBOOLEAN 1 #define SPROTO_TSTRING 2 -#define SPROTO_DOUBLE 3 +#define SPROTO_TDOUBLE 3 #define SPROTO_TSTRUCT 4 // sub type of string (sproto_arg.extra)