ref[protocol]: NotEnhance move to Protocol Annotation

This commit is contained in:
godotg committed 2023-09-03 12:38:25 +08:00
1 parent 2e8c673862
commit 8cb904ba50
3 files changed
+4 -29

No files matched your search

@@ -1,26 +0,0 @@
/*
* Copyright (C) 2020 The zfoo Authors
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.protocol.anno;
import java.lang.annotation.*;
/**
* @author meiw
* @version 3.0
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface NotEnhance {
}
@@ -25,6 +25,8 @@ public @interface Protocol {
short id() default 0;
boolean enhance() default true;
String note() default "";
}
@@ -15,7 +15,6 @@ package com.zfoo.protocol.registration;
import com.zfoo.protocol.IPacket;
import com.zfoo.protocol.ProtocolManager;
import com.zfoo.protocol.anno.Compatible;
import com.zfoo.protocol.anno.NotEnhance;
import com.zfoo.protocol.anno.Protocol;
import com.zfoo.protocol.collection.ArrayUtils;
import com.zfoo.protocol.collection.CollectionUtils;
@@ -208,8 +207,8 @@ public class ProtocolAnalysis {
for (Class<?> clazz : packetClazzList) {
var protocolId = ProtocolManager.protocolId(clazz);
var registration = parseProtocolRegistration(clazz, module);
boolean isEnhance = protocolDefinitionMap.getOrDefault(clazz.getName(), true);
if (isEnhance && !clazz.isAnnotationPresent(NotEnhance.class)) {
// 优先使用Protocol注解指定的enhance决定是否要增强协议
if (clazz.isAnnotationPresent(Protocol.class) && clazz.getAnnotation(Protocol.class).enhance()) {
enhanceList.add(registration);
}
// 注册协议