perf(net): compact data sent to the network

This commit is contained in:
Guillaume ARM 2024-05-22 19:32:54 +02:00
parent 24ffcce68d
commit baba577b62

View File

@ -2,6 +2,10 @@ local DEFAULT_TIMEOUT = 2
local QUERY_PROTO = 'trap/query'
local QUERY_RESPONSE_PROTO = 'trap/query:response'
local serializeOpts = {
compact = true
}
local net = {}
local function assertRednetIsOpened()
@ -34,7 +38,7 @@ net.listenQuery = function(hostname, processQueryMessage)
while serverRunning do
local computerId, message = rednet.receive(QUERY_PROTO)
local responseMessage = processQueryMessage(textutils.unserialize(message), computerId, stopServer)
rednet.send(computerId, textutils.serialize(responseMessage), QUERY_RESPONSE_PROTO)
rednet.send(computerId, textutils.serialize(responseMessage, serializeOpts), QUERY_RESPONSE_PROTO)
end
rednet.unhost(QUERY_PROTO)
@ -50,7 +54,7 @@ net.sendQuery = function(hostname, message, timeout)
return nil, 'hostname lookup error'
end
local sendOk = rednet.send(serverId, textutils.serialize(message), QUERY_PROTO)
local sendOk = rednet.send(serverId, textutils.serialize(message, serializeOpts), QUERY_PROTO)
if not sendOk then
return nil, 'rednet error'