mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-21 08:27:11 +00:00
feat[protocol]: 子协议会自动注册协议号protocolId,如果子协议没有指定protocolId则自动生成protocolId
This commit is contained in:
@@ -320,7 +320,7 @@ public class SpeedTest {
|
||||
// op.getGenerateLanguages().add(CodeLanguage.Protobuf);
|
||||
|
||||
// zfoo协议注册(其实就是:将Set里面的协议号和对应的类注册好,这样子就可以根据协议号知道是反序列化为哪个类)
|
||||
ProtocolManager.initProtocol(Set.of(ComplexObject.class, NormalObject.class, SimpleObject.class, ObjectA.class, ObjectB.class), op);
|
||||
ProtocolManager.initProtocolAuto(Set.of(ComplexObject.class, NormalObject.class, SimpleObject.class), op);
|
||||
|
||||
for (int i = 0; i < executors.length; i++) {
|
||||
executors[i] = Executors.newSingleThreadExecutor();
|
||||
|
||||
@@ -24,19 +24,12 @@ import java.util.Objects;
|
||||
*/
|
||||
public class ObjectA implements IPacket {
|
||||
|
||||
public static final transient short PROTOCOL_ID = 102;
|
||||
|
||||
private int a;
|
||||
|
||||
private Map<Integer, String> m;
|
||||
|
||||
private ObjectB objectB;
|
||||
|
||||
@Override
|
||||
public short protocolId() {
|
||||
return PROTOCOL_ID;
|
||||
}
|
||||
|
||||
public int getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -23,15 +23,8 @@ import java.util.Objects;
|
||||
*/
|
||||
public class ObjectB implements IPacket {
|
||||
|
||||
public static final transient short PROTOCOL_ID = 103;
|
||||
|
||||
private boolean flag;
|
||||
|
||||
@Override
|
||||
public short protocolId() {
|
||||
return PROTOCOL_ID;
|
||||
}
|
||||
|
||||
public boolean isFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user