doc[protocol]: update readme

This commit is contained in:
godotg
2023-09-09 08:22:33 +08:00
parent 2eee745f73
commit 55fa85227f
2 changed files with 4 additions and 23 deletions
+2 -13
View File
@@ -122,17 +122,6 @@ For complex objects, ZFOO package size 2216, KRYO package size 2528, and Protobu
- The protocol class must be a simple javabean, not inheriting from any other class, but can inherit an interface
- In order to prevent objects in the code and avoid some potential concurrency problems caused by the mixing of objects
in the protocol layer and the po layer, zfoo mandates that protocol classes must implement the IPacket interface
```
Now the interface of IPacket is just an identification interface, inheriting the design of IPacket is mainly to make
the code more elegant and easier to understand, and it is not a lot of work to inherit only Object
The design of inheriting IPacket also has cross-language considerations, which greatly simplifies the difficulty
of serialization and deserialization in other languages and unifies the code implementation of other languages
```
- The protocol number is defined as a short type to reduce the packet size and memory size, a packet can be reduced by 2
bytes, and the application memory of each protocol can also be reduced by 6 byte(protocols + IProtocolRegistration +
protocolIdMap)
@@ -146,7 +135,7 @@ your protocol number a little more compactly, so that your protocol number will
- The first uses annotations: @Protocol(id = protocolId)
```
@Protocol(id = 104)
public class SimpleObject implements IPacket {
public class SimpleObject {
public int c;
public boolean g;
@@ -158,7 +147,7 @@ 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
number
```
public class SimpleObject implements IPacket {
public class SimpleObject {
public int c;
+2 -10
View File
@@ -99,14 +99,6 @@ cpu i9900k
- 协议类必须是简单的javabean,不能继承任何其它的类,但是可以继承接口
- 为了防止代码里Object满天飞,避免协议层和po层混用对象造成一些潜在的并发问题,zfoo强制要求协议类必须实现IPacket接口
```
现在IPacket的接口只是一个标识接口,继承IPacket的设计主要是为了让代码更优雅,容易理解一点,改为只继承Object也并没有很大工作量
继承IPacket的设计还有跨语言层面上的考虑,极大的简化了实现其它语言的序列化和反序列化难度,统一了其它语言的代码实现
```
- 协议号定义为short类型是为了减少包体积和内存大小,一个包可以减少2个byte,每个协议的在应用内存也可以降低6byte(protocols +
IProtocolRegistration + protocolIdMap
@@ -118,7 +110,7 @@ cpu i9900k
- 第一种使用注解:@Protocol(id = protocolId)
```
@Protocol(id = 104)
public class SimpleObject implements IPacket {
public class SimpleObject {
public int c;
public boolean g;
@@ -128,7 +120,7 @@ cpu i9900k
- 第二种使用:通过ProtocolManager.initProtocolAuto()去注册协议就可以不写协议号
```
public class SimpleObject implements IPacket {
public class SimpleObject {
public int c;