pull/2/head
jaysunxiao 2022-05-22 21:21:25 +08:00
parent d422c6bdab
commit b2a01aaa91
3 changed files with 22 additions and 6 deletions

View File

@ -10,8 +10,8 @@ static func getProtocol(protocolId: int):
return protocols[protocolId]
static func newInstance(protocolId: int):
var protocol = protocols[protocolId]
return protocol.new()
var protocol = protocols[protocolId]
return protocol.new()
static func write(buffer, packet):
var protocolId: int = packet.PROTOCOL_ID
@ -20,10 +20,10 @@ static func write(buffer, packet):
protocol.write(buffer, packet)
static func read(buffer):
var protocolId = buffer.readShort();
var protocol = protocols[protocolId]
var packet = protocol.read(buffer);
return packet;
var protocolId = buffer.readShort();
var protocol = protocols[protocolId]
var packet = protocol.read(buffer);
return packet;
static func initProtocol():
protocols[100] = ComplexObject

View File

@ -31,6 +31,9 @@ func setReadOffset(readIndex: int) -> void:
func getReadOffset() -> int:
return readOffset
func isReadable() -> bool:
return writeOffset > readOffset
# -------------------------------------------------write/read-------------------------------------------------
func writePoolByteArray(value: PoolByteArray):
var length = value.size()

View File

@ -59,6 +59,9 @@ var ss # java.util.Set<java.util.Set<java.util.List<java.lang.Integer>>>
var sss # java.util.Set<java.util.Set<com.zfoo.protocol.packet.ObjectA>>
var ssss # java.util.Set<java.lang.String>
var sssss # java.util.Set<java.util.Map<java.lang.Integer, java.lang.String>>
# 如果要修改协议并且兼容老协议需要加上Compatible注解按照增加的顺序添加order
var myCompatible # int
var myObject # com.zfoo.protocol.packet.ObjectA
const PROTOCOL_ID = 100
@ -202,6 +205,8 @@ static func write(buffer, packet):
buffer.writeInt(packet.sssss.size())
for element18 in packet.sssss:
buffer.writeIntStringMap(element18)
buffer.writeInt(packet.myCompatible)
buffer.writePacket(packet.myObject, 102)
static func read(buffer):
@ -393,4 +398,12 @@ static func read(buffer):
var map120 = buffer.readIntStringMap()
result117.append(map120)
packet.sssss = result117
if (!buffer.isReadable()):
return packet
var result121 = buffer.readInt()
packet.myCompatible = result121
if (!buffer.isReadable()):
return packet
var result122 = buffer.readPacket(102)
packet.myObject = result122
return packet