doc[protocol]: update doc

This commit is contained in:
godotg committed 2023-10-15 13:31:29 +08:00
1 parent b646d286e6
commit 08f198ef4f
2 files changed
+30 -1

No files matched your search

+15 -1
View File
@@ -141,7 +141,6 @@ your protocol number a little more compactly, so that your protocol number will
} }
``` ```
- The second use: Register the agreement through Protocol Manager.initProtocolAuto() without writing the protocol - The second use: Register the agreement through Protocol Manager.initProtocolAuto() without writing the protocol
number number
``` ```
@@ -154,6 +153,21 @@ your protocol number a little more compactly, so that your protocol number will
} }
``` ```
- The third use: Register the protocol through ProtocolManager.initProtocol(xmlProtocols) in the protocol.xml file
```
<protocols>
<module id="1" name="common">
<protocol id="100" location="com.zfoo.protocol.packet.ComplexObject"/>
<protocol id="101" location="com.zfoo.protocol.packet.NormalObject"/>
<protocol id="102" location="com.zfoo.protocol.packet.ObjectA"/>
<protocol id="103" location="com.zfoo.protocol.packet.ObjectB"/>
<protocol id="104" location="com.zfoo.protocol.packet.SimpleObject"/>
<protocol id="105" location="com.zfoo.protocol.packet.VeryBigObject"/>
<protocol id="106" location="com.zfoo.protocol.packet.EmptyObject"/>
</module>
</protocols>
```
- If you add a field for version compatibility, you need to add a Compatible annotation, and the order needs to be - If you add a field for version compatibility, you need to add a Compatible annotation, and the order needs to be
naturally increased, so as to ensure that the old and new protocols can be compatible with each other naturally increased, so as to ensure that the old and new protocols can be compatible with each other
- In order to be compatible with versions and avoid modifying field names, default uses field names to read and write - In order to be compatible with versions and avoid modifying field names, default uses field names to read and write
+15
View File
@@ -130,6 +130,21 @@ cpu: i9900k
} }
``` ```
- 第三种使用:通过ProtocolManagerinitProtocol(xmlProtocols)去注册协议,把协议号写在protocol.xml文件
```
<protocols>
<module id="1" name="common">
<protocol id="100" location="com.zfoo.protocol.packet.ComplexObject"/>
<protocol id="101" location="com.zfoo.protocol.packet.NormalObject"/>
<protocol id="102" location="com.zfoo.protocol.packet.ObjectA"/>
<protocol id="103" location="com.zfoo.protocol.packet.ObjectB"/>
<protocol id="104" location="com.zfoo.protocol.packet.SimpleObject"/>
<protocol id="105" location="com.zfoo.protocol.packet.VeryBigObject"/>
<protocol id="106" location="com.zfoo.protocol.packet.EmptyObject"/>
</module>
</protocols>
```
- 如果为了版本兼容,增加字段,需要加上Compatible注解,order需要自然增大,这样就可以保证新老协议可以互相兼容 - 如果为了版本兼容,增加字段,需要加上Compatible注解,order需要自然增大,这样就可以保证新老协议可以互相兼容
- 正式环境为了版本兼容,避免修改字段名称,内部默认使用字段的名称按照字符串的自然顺序来依次读写的(也可以自定义),所以会导致序列化出现异常 - 正式环境为了版本兼容,避免修改字段名称,内部默认使用字段的名称按照字符串的自然顺序来依次读写的(也可以自定义),所以会导致序列化出现异常
- 正式环境为了版本兼容,避免减少字段,没必要一定要删除一个不需要的字段,所以不考虑支持这种减少字段兼容协议的情况 - 正式环境为了版本兼容,避免减少字段,没必要一定要删除一个不需要的字段,所以不考虑支持这种减少字段兼容协议的情况