From 2bd2fb5600ecd01d2827e46ca6266a98d9d993ea Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Fri, 11 Aug 2023 11:25:51 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20lua=E5=BA=8F=E5=88=97=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/lua/ByteArray.lua | 56 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/test/lua/ByteArray.lua b/test/lua/ByteArray.lua index 5985d72..b86a003 100644 --- a/test/lua/ByteArray.lua +++ b/test/lua/ByteArray.lua @@ -1,10 +1,7 @@ function ByteArray() - local mBuf = {} -- 二进制字节流 + local mBuf = {} -- 二进制字节流 local mPos = 1 -- 读写位置 - ---------------------------------------------------------------------- - -- public method - ---------------------------------------------------------------------- local ba = {} -- 设置字节流 解码先设置从tcp获取得来的字节数据 ba.setBytes = function(buf) @@ -77,7 +74,6 @@ function ByteArray() mPos = mPos + 1 end - ---------------------------------------------------------------------- -- 读16位整型 ba.read_int16 = function() local value, tPos = string.unpack(">i2", mBuf, mPos) @@ -251,32 +247,32 @@ function ByteArray() elseif tag == 65 then return read_double() end + end - -- 写数字 - ba.write_integer = function(value) - local valueType = math.type(value) - if valueType == 'integer' then - if value >= -128 and value <= 127 then - write_int8(8) - write_int8(value) - elseif value >= -32768 and value <= 32767 then - write_int8(16) - write_int16(value) - elseif value >= -2147483648 and value <= 2147483647 then - write_int8(32) - write_int32(value) - elseif value >= -9223372036854775808 and value <= 9223372036854775807 then - write_int8(64) - write_int64(value) - end - elseif valueType == 'float' then - if value >= 1.175494351e-38 and value <= 3.402823466e+38 then - write_int8(33) - write_float(value) - elseif value >= 2.2250738585072014e-308 and value <= 1.7976931348623158e+308 then - write_int8(65) - write_float(value) - end + -- 写数字 + ba.write_integer = function(value) + local valueType = math.type(value) + if valueType == 'integer' then + if value >= -128 and value <= 127 then + write_int8(8) + write_int8(value) + elseif value >= -32768 and value <= 32767 then + write_int8(16) + write_int16(value) + elseif value >= -2147483648 and value <= 2147483647 then + write_int8(32) + write_int32(value) + elseif value >= -9223372036854775808 and value <= 9223372036854775807 then + write_int8(64) + write_int64(value) + end + elseif valueType == 'float' then + if value >= 1.175494351e-38 and value <= 3.402823466e+38 then + write_int8(33) + write_float(value) + elseif value >= 2.2250738585072014e-308 and value <= 1.7976931348623158e+308 then + write_int8(65) + write_float(value) end end end