perf[protocol]: ruby code style

This commit is contained in:
godotg
2024-07-24 17:29:47 +08:00
parent 7f67827a3f
commit beebb39842
19 changed files with 1134 additions and 1130 deletions
File diff suppressed because it is too large Load Diff
@@ -1,7 +1,7 @@
${protocol_note}
class ${protocol_name}
${protocol_field_accessor}
def initialize()
${protocol_field_definition}
end
${protocol_field_accessor}
def initialize()
${protocol_field_definition}
end
end
@@ -2,28 +2,28 @@ ${protocol_imports}
class ProtocolManager
@@protocols = Array.new(32767)
@@protocolIdMap = Hash.new()
@@protocols = Array.new(32767)
@@protocolIdMap = Hash.new()
def self.initProtocol()
${protocol_manager_registrations}
end
def self.initProtocol()
${protocol_manager_registrations}
end
def self.getProtocol(protocolId)
return @@protocols[protocolId]
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.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
def self.read(buffer)
protocolId = buffer.readShort()
protocol = @@protocols[protocolId]
packet = protocol.read(buffer)
return packet
end
end
@@ -1,27 +1,27 @@
class ${protocol_name}Registration
def protocolId()
return ${protocol_id}
end
def protocolId()
return ${protocol_id}
end
def write(buffer, packet)
if packet.nil?
buffer.writeInt(0)
return
end
${protocol_write_serialization}
def write(buffer, packet)
if packet.nil?
buffer.writeInt(0)
return
end
${protocol_write_serialization}
end
def read(buffer)
length = buffer.readInt()
if length == 0
return nil
end
beforeReadIndex = buffer.getReadOffset()
packet = ${protocol_name}.new()
${protocol_read_deserialization}
if length > 0
buffer.setReadOffset(beforeReadIndex + length)
end
return packet
def read(buffer)
length = buffer.readInt()
if length == 0
return nil
end
beforeReadIndex = buffer.getReadOffset()
packet = ${protocol_name}.new()
${protocol_read_deserialization}
if length > 0
buffer.setReadOffset(beforeReadIndex + length)
end
return packet
end
end