ruby.ProtocolManagerTemplate.rb Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protocol Show documentation
Show all versions of protocol Show documentation
zfoo protocol is binary serialization framework for Java/C++/js/ts/C#/Go/Lua/GDScript/Python
The newest version!
${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