local HttpService = game:GetService("HttpService")
local function getDataSize(data)
return #HttpService:JSONEncode(data)
end
This function is according to MessagingService not correct.
local t = {}
for i = 1, 71 do
table.insert(t, 1111111111111)
end
print(getDataSize(t)) --prints under 1000, 1kB is 1024
game:GetService("MessagingService"):PublishAsync("Test", t)
MessagingService says that the data exceeded 1kb.
Any help is appreciated!
The # operator gets the size of the table in terms of how many elements it has, not how much memory it takes up.
Although I suppose you could create a function to get the sizeof a table in memory, though you would have to count for a lot of cases. Though here is how you do it if you only had an array of numbers as in your second example
-- Lua uses 64 bit integers and 64 bit double precision floats
function sizeof(t)
return #t * 64
end
I’m trying to make a packet switching system where data gets split into packets when it’s bigger than 1kB.
Is the “size of message” limit of 1kB maybe calculated including the Data/Sent fields?
This would explain why 976B is the maximum size:
MessagingService:PublishAsync("Test", string.rep("a", 974)) --has a size of 976
MessagingService:PublishAsync("Test", string.rep("a", 975)) --too large