lua-resty-zeromq icon indicating copy to clipboard operation
lua-resty-zeromq copied to clipboard

[bug]打包参数长度刚好是256报错

Open bamboolight opened this issue 2 years ago • 0 comments

要发送的消息长度刚好是256时,打包长度参数时报错。

具体:当msg_size ==256时,114行的char(msg_size) ,会报错。因为char的有效范围0-255。

方法一: 把113行的msg_size/base > 1 改为msg_size/base >= 1

方法二:

--打包msg_size的方法:

local bit = require "bit" local rshift = bit.rshift local band = bit.band

local len = {0, 0, 0, 0, 0, 0, 0, 0} for index = 8, 1, -1 do if msg_size <= 0 then break end len[index] = band(msg_size, 0xff) msg_size = rshift(msg_size, 8) end

size = string.char(table.unpack(len))

方法三: local size = string.pack(">I8", msg_size)

bamboolight avatar Nov 16 '22 09:11 bamboolight