mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-10 02:17:57 +00:00
perf[protocol]: ruby code style
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user