mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-19 12:16:48 +00:00
doc[protocol]: update readme
This commit is contained in:
1 parent
2eee745f73
commit
55fa85227f
2 files changed
+4
-23
No files matched your search
+2
-10
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user