diff --git a/protocol/src/test/python/ProtocolTest.py b/protocol/src/test/python/ProtocolTest.py index 5dbf753d3..4e9756c6b 100644 --- a/protocol/src/test/python/ProtocolTest.py +++ b/protocol/src/test/python/ProtocolTest.py @@ -93,8 +93,3 @@ def test_buffer(self): byteBuffer.writeString(str) self.assertEqual(byteBuffer.readString(), str) - charStr = "A" - byteBuffer.writeChar(charStr) - self.assertEqual(byteBuffer.readChar(), charStr) - print("----------------------------------------------------------------") - print_bytearray(byteBuffer.buffer) diff --git a/protocol/src/test/python/zfoopy/ProtocolManager.py b/protocol/src/test/python/zfoopy/ProtocolManager.py index 689ed6aeb..1366a15ce 100644 --- a/protocol/src/test/python/zfoopy/ProtocolManager.py +++ b/protocol/src/test/python/zfoopy/ProtocolManager.py @@ -7,20 +7,28 @@ from .packet import SimpleObject protocols = {} +protocolIdMap = {} -protocols[0] = EmptyObject.EmptyObject -protocols[1] = VeryBigObject.VeryBigObject -protocols[100] = ComplexObject.ComplexObject -protocols[101] = NormalObject.NormalObject -protocols[102] = ObjectA.ObjectA -protocols[103] = ObjectB.ObjectB -protocols[104] = SimpleObject.SimpleObject +protocols[0] = EmptyObject.EmptyObjectRegistration +protocolIdMap[EmptyObject.EmptyObject] = 0 +protocols[1] = VeryBigObject.VeryBigObjectRegistration +protocolIdMap[VeryBigObject.VeryBigObject] = 1 +protocols[100] = ComplexObject.ComplexObjectRegistration +protocolIdMap[ComplexObject.ComplexObject] = 100 +protocols[101] = NormalObject.NormalObjectRegistration +protocolIdMap[NormalObject.NormalObject] = 101 +protocols[102] = ObjectA.ObjectARegistration +protocolIdMap[ObjectA.ObjectA] = 102 +protocols[103] = ObjectB.ObjectBRegistration +protocolIdMap[ObjectB.ObjectB] = 103 +protocols[104] = SimpleObject.SimpleObjectRegistration +protocolIdMap[SimpleObject.SimpleObject] = 104 def getProtocol(protocolId): return protocols[protocolId] def write(buffer, packet): - protocolId = packet.protocolId() + protocolId = protocolIdMap[type(packet)] buffer.writeShort(protocolId) protocol = protocols[protocolId] protocol.write(buffer, packet) diff --git a/protocol/src/test/python/zfoopy/packet/ComplexObject.py b/protocol/src/test/python/zfoopy/packet/ComplexObject.py index b0bcd4017..bf477794b 100644 --- a/protocol/src/test/python/zfoopy/packet/ComplexObject.py +++ b/protocol/src/test/python/zfoopy/packet/ComplexObject.py @@ -53,8 +53,11 @@ class ComplexObject: # 如果要修改协议并且兼容老协议,需要加上Compatible注解,保持Compatible注解的value自增 myCompatible = 0 # int myObject = None # ObjectA + pass - def protocolId(self): +class ComplexObjectRegistration: + @classmethod + def protocolId(cls, self): return 100 @classmethod diff --git a/protocol/src/test/python/zfoopy/packet/EmptyObject.py b/protocol/src/test/python/zfoopy/packet/EmptyObject.py index 2cdbebf6c..633fdefc7 100644 --- a/protocol/src/test/python/zfoopy/packet/EmptyObject.py +++ b/protocol/src/test/python/zfoopy/packet/EmptyObject.py @@ -1,8 +1,11 @@ class EmptyObject: + pass - def protocolId(self): +class EmptyObjectRegistration: + @classmethod + def protocolId(cls, self): return 0 @classmethod diff --git a/protocol/src/test/python/zfoopy/packet/NormalObject.py b/protocol/src/test/python/zfoopy/packet/NormalObject.py index 0ebbe5ab3..46f6c7833 100644 --- a/protocol/src/test/python/zfoopy/packet/NormalObject.py +++ b/protocol/src/test/python/zfoopy/packet/NormalObject.py @@ -1,8 +1,9 @@ - +# 常规的对象,取所有语言语法的交集,基本上所有语言都支持下面的语法 class NormalObject: a = 0 # byte aaa = [] # byte[] b = 0 # short + # 整数类型 c = 0 # int d = 0 # long e = 0.0 # float @@ -20,8 +21,11 @@ class NormalObject: ssss = {} # HashSet outCompatibleValue = 0 # int outCompatibleValue2 = 0 # int + pass - def protocolId(self): +class NormalObjectRegistration: + @classmethod + def protocolId(cls, self): return 101 @classmethod diff --git a/protocol/src/test/python/zfoopy/packet/ObjectA.py b/protocol/src/test/python/zfoopy/packet/ObjectA.py index c6808dafa..bd449601c 100644 --- a/protocol/src/test/python/zfoopy/packet/ObjectA.py +++ b/protocol/src/test/python/zfoopy/packet/ObjectA.py @@ -4,8 +4,11 @@ class ObjectA: m = {} # Dictionary objectB = None # ObjectB innerCompatibleValue = 0 # int + pass - def protocolId(self): +class ObjectARegistration: + @classmethod + def protocolId(cls, self): return 102 @classmethod diff --git a/protocol/src/test/python/zfoopy/packet/ObjectB.py b/protocol/src/test/python/zfoopy/packet/ObjectB.py index 12bc9100c..05e1e15c6 100644 --- a/protocol/src/test/python/zfoopy/packet/ObjectB.py +++ b/protocol/src/test/python/zfoopy/packet/ObjectB.py @@ -2,8 +2,11 @@ class ObjectB: flag = False # bool innerCompatibleValue = 0 # int + pass - def protocolId(self): +class ObjectBRegistration: + @classmethod + def protocolId(cls, self): return 103 @classmethod diff --git a/protocol/src/test/python/zfoopy/packet/SimpleObject.py b/protocol/src/test/python/zfoopy/packet/SimpleObject.py index ea781cc87..da837fe6d 100644 --- a/protocol/src/test/python/zfoopy/packet/SimpleObject.py +++ b/protocol/src/test/python/zfoopy/packet/SimpleObject.py @@ -2,8 +2,11 @@ class SimpleObject: c = 0 # int g = False # bool + pass - def protocolId(self): +class SimpleObjectRegistration: + @classmethod + def protocolId(cls, self): return 104 @classmethod diff --git a/protocol/src/test/python/zfoopy/packet/VeryBigObject.py b/protocol/src/test/python/zfoopy/packet/VeryBigObject.py index 04a792330..6394e3a5c 100644 --- a/protocol/src/test/python/zfoopy/packet/VeryBigObject.py +++ b/protocol/src/test/python/zfoopy/packet/VeryBigObject.py @@ -3344,8 +3344,11 @@ class VeryBigObject: mm88 = {} # Dictionary s88 = {} # HashSet ssss88 = {} # HashSet + pass - def protocolId(self): +class VeryBigObjectRegistration: + @classmethod + def protocolId(cls, self): return 1 @classmethod