Skip to content

Commit 4def65a

Browse files
authored
Merge pull request #121 from ccuser44/patch-2
2 parents 8113e62 + d75d764 commit 4def65a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/prometheus/util.lua

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
local logger = require("logger");
77
local bit32 = require("prometheus.bit").bit32;
88

9+
local MAX_UNPACK_COUNT = 195;
10+
911
local function lookupify(tb)
1012
local tb2 = {};
1113
for _, v in ipairs(tb) do
@@ -222,11 +224,20 @@ local function readU32(arr)
222224
end
223225

224226
local function bytesToString(arr)
227+
local lenght = arr.n or #arr;
228+
229+
if lenght < MAX_UNPACK_COUNT then
230+
return string.char(table.unpack(arr))
231+
end
232+
225233
local str = "";
226-
for i = 1, #arr do
227-
str = str .. string.char(arr[i]);
234+
local overflow = lenght % MAX_UNPACK_COUNT;
235+
236+
for i = 1, (#arr - overflow) / MAX_UNPACK_COUNT do
237+
str = str .. string.char(table.unpack(arr, (i - 1) * MAX_UNPACK_COUNT + 1, i * MAX_UNPACK_COUNT));
228238
end
229-
return str;
239+
240+
return str..(overflow > 0 and string.char(table.unpack(arr, lenght - overflow + 1, lenght)) or "");
230241
end
231242

232243
local function isNaN(n)

0 commit comments

Comments
 (0)