mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-19 03:26:59 +00:00
29 lines
603 B
Ruby
29 lines
603 B
Ruby
${protocol_imports}
|
|
|
|
|
|
class ProtocolManager
|
|
@@protocols = Array.new(32767)
|
|
@@protocolIdMap = Hash.new()
|
|
|
|
def self.initProtocol()
|
|
${protocol_manager_registrations}
|
|
end
|
|
|
|
def self.getProtocol(protocolId)
|
|
return @@protocols[protocolId]
|
|
end
|
|
|
|
def self.write(buffer, packet)
|
|
protocolId = @@protocolIdMap[packet.class]
|
|
buffer.writeShort(protocolId)
|
|
protocol = @@protocols[protocolId]
|
|
protocol.write(buffer, packet)
|
|
end
|
|
|
|
def self.read(buffer)
|
|
protocolId = buffer.readShort()
|
|
protocol = @@protocols[protocolId]
|
|
packet = protocol.read(buffer)
|
|
return packet
|
|
end
|
|
end |