Move serialization import into network implementation
The (default) network implementation is the only place where `serialization` is used. Thus, move the import into its constructor so we don't unnecessarily load the module unconditionally.
This commit is contained in:
parent
4a5349be96
commit
67cbb5badc
1 changed files with 5 additions and 5 deletions
10
bc.lua
10
bc.lua
|
|
@ -1,4 +1,3 @@
|
|||
local serialization = require("serialization")
|
||||
local uuid = require("uuid")
|
||||
local computer = require("computer")
|
||||
local bit32 = require("bit32")
|
||||
|
|
@ -46,6 +45,7 @@ function Network:new(modem, port)
|
|||
modem = modem or require("component").modem,
|
||||
port = port or Network.default_port,
|
||||
event = require("event"),
|
||||
serialization = require("serialization"),
|
||||
}
|
||||
setmetatable(self, {__index=Network})
|
||||
|
||||
|
|
@ -59,17 +59,17 @@ function Network:start(callback)
|
|||
-- Filter everything we don't care about
|
||||
if addr_lo ~= self.modem.address then return end
|
||||
if port ~= self.port then return end
|
||||
callback(addr_remote, serialization.unserialize(msg))
|
||||
callback(addr_remote, self.serialization.unserialize(msg))
|
||||
end
|
||||
self.event.listen("modem_message", self.listener)
|
||||
end
|
||||
|
||||
function Network:send(addr, msg)
|
||||
self.modem.send(addr, self.port, serialization.serialize(msg))
|
||||
self.modem.send(addr, self.port, self.serialization.serialize(msg))
|
||||
end
|
||||
|
||||
function Network:broadcast(msg)
|
||||
self.modem.broadcast(self.port, serialization.serialize(msg))
|
||||
self.modem.broadcast(self.port, self.serialization.serialize(msg))
|
||||
end
|
||||
|
||||
function Network:pull(filter, timeout)
|
||||
|
|
@ -78,7 +78,7 @@ function Network:pull(filter, timeout)
|
|||
if ev ~= "modem_message" then return false end
|
||||
if addr_lo ~= self.modem.address then return false end
|
||||
if port ~= self.port then return false end
|
||||
last_msg = serialization.unserialize(msg)
|
||||
last_msg = self.serialization.unserialize(msg)
|
||||
return filter(addr_remote, last_msg)
|
||||
end)
|
||||
if ev ~= nil then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue