Skip to content

Commit 594797f

Browse files
committed
make local for struct.X, math.X
1 parent 76f398d commit 594797f

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/websocket/frame.lua

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ local schar = string.char
1212
local tinsert = table.insert
1313
local tconcat = table.concat
1414
local mmin = math.min
15+
local strpack = struct.pack
16+
local strunpack = struct.unpack
17+
local mfloor = math.floor
18+
local mrandom = math.random
1519

1620
local bits = function(...)
1721
local n = 0
@@ -57,26 +61,29 @@ local encode = function(data,opcode,masked,fin)
5761
local len = #data
5862
if len < 126 then
5963
payload = bor(payload,len)
60-
encoded = struct.pack('bb',header,payload)
64+
encoded = strpack('bb',header,payload)
6165
elseif len < 0xffff then
6266
payload = bor(payload,126)
63-
encoded = struct.pack('bb>H',header,payload,len)
67+
encoded = strpack('bb>H',header,payload,len)
6468
elseif len < 2^53 then
65-
local high = math.floor(len/2^32)
69+
local high = mfloor(len/2^32)
6670
local low = len - high*2^32
6771
payload = bor(payload,127)
68-
encoded = struct.pack('bb>I>I',header,payload,high,low)
72+
encoded = strpack('bb>I>I',header,payload,high,low)
6973
end
7074
if not masked then
7175
encoded = encoded..data
7276
else
73-
local m1 = math.random(0,0xff)
74-
local m2 = math.random(0,0xff)
75-
local m3 = math.random(0,0xff)
76-
local m4 = math.random(0,0xff)
77+
local m1 = mrandom(0,0xff)
78+
local m2 = mrandom(0,0xff)
79+
local m3 = mrandom(0,0xff)
80+
local m4 = mrandom(0,0xff)
7781
local mask = {m1,m2,m3,m4}
78-
encoded = encoded..struct.pack('bbbb',m1,m2,m3,m4)
79-
encoded = encoded..xor_mask(data,mask,#data)
82+
encoded = tconcat({
83+
encoded,
84+
strpack('bbbb',m1,m2,m3,m4),
85+
xor_mask(data,mask,#data)
86+
})
8087
end
8188
return encoded
8289
end

0 commit comments

Comments
 (0)