local skynet = require "skynet" require "skynet.manager" local c = require "snowflake.core" local skynet_retpack = skynet.retpack local prefix = nil local MAX_WORKID_VAL = 1024 local CMD = {} function CMD.start() local work_id = assert(option.sid) if work_id < 1 or work_id > 65535 then assert(false, "Work id is in range of 1 - 65535.") end prefix = string.format("%02d-", work_id>>10) work_id = work_id % MAX_WORKID_VAL c.init(work_id) end function CMD.prefix() return prefix end skynet.init(function() skynet.register(".snowflake") end) skynet.start(function() skynet.dispatch("lua", function(session, _, cmd, ...) local f = assert(CMD[cmd]) if session == 0 then f(...) else skynet_retpack(f(...)) end end) end)