mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-03 18:17:17 +00:00
ref[net]: 重构net,简化了大量代码
This commit is contained in:
@@ -13,6 +13,11 @@
|
||||
|
||||
package com.zfoo.protocol.generate;
|
||||
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 创建协议文件的操作类
|
||||
*
|
||||
@@ -37,19 +42,9 @@ public class GenerateOperation {
|
||||
private String protocolParam;
|
||||
|
||||
/**
|
||||
* 生成javascript协议文件
|
||||
* 需要生成的协议文件
|
||||
*/
|
||||
private boolean generateJsProtocol;
|
||||
|
||||
/**
|
||||
* 生成C#协议文件
|
||||
*/
|
||||
private boolean generateCsharpProtocol;
|
||||
|
||||
/**
|
||||
* 生成Lua协议文件
|
||||
*/
|
||||
private boolean generateLuaProtocol;
|
||||
private Set<CodeLanguage> generateLanguages = new HashSet<>();
|
||||
|
||||
public boolean isFoldProtocol() {
|
||||
return foldProtocol;
|
||||
@@ -67,28 +62,8 @@ public class GenerateOperation {
|
||||
this.protocolParam = protocolParam;
|
||||
}
|
||||
|
||||
public boolean isGenerateJsProtocol() {
|
||||
return generateJsProtocol;
|
||||
}
|
||||
|
||||
public void setGenerateJsProtocol(boolean generateJsProtocol) {
|
||||
this.generateJsProtocol = generateJsProtocol;
|
||||
}
|
||||
|
||||
public boolean isGenerateCsharpProtocol() {
|
||||
return generateCsharpProtocol;
|
||||
}
|
||||
|
||||
public void setGenerateCsharpProtocol(boolean generateCsharpProtocol) {
|
||||
this.generateCsharpProtocol = generateCsharpProtocol;
|
||||
}
|
||||
|
||||
public boolean isGenerateLuaProtocol() {
|
||||
return generateLuaProtocol;
|
||||
}
|
||||
|
||||
public void setGenerateLuaProtocol(boolean generateLuaProtocol) {
|
||||
this.generateLuaProtocol = generateLuaProtocol;
|
||||
public Set<CodeLanguage> getGenerateLanguages() {
|
||||
return generateLanguages;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ import com.zfoo.protocol.ProtocolManager;
|
||||
import com.zfoo.protocol.registration.IProtocolRegistration;
|
||||
import com.zfoo.protocol.registration.ProtocolAnalysis;
|
||||
import com.zfoo.protocol.registration.ProtocolRegistration;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.serializer.cs.GenerateCsUtils;
|
||||
import com.zfoo.protocol.serializer.js.GenerateJsUtils;
|
||||
import com.zfoo.protocol.serializer.lua.GenerateLuaUtils;
|
||||
import com.zfoo.protocol.util.ReflectionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@@ -58,14 +58,7 @@ public abstract class GenerateProtocolFile {
|
||||
var protocols = ProtocolManager.protocols;
|
||||
|
||||
// 如果没有需要生成的协议则直接返回
|
||||
var generateProtocolFlag = Arrays.stream(generateOperation.getClass().getDeclaredFields())
|
||||
.filter(it -> it.getName().startsWith("generate"))
|
||||
.peek(it -> ReflectionUtils.makeAccessible(it))
|
||||
.map(it -> ReflectionUtils.getField(it, generateOperation))
|
||||
.filter(it -> it instanceof Boolean)
|
||||
.anyMatch(it -> ((Boolean) it).booleanValue() == true);
|
||||
|
||||
if (!generateProtocolFlag) {
|
||||
if (generateOperation.getGenerateLanguages().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -102,21 +95,22 @@ public abstract class GenerateProtocolFile {
|
||||
}
|
||||
|
||||
// 生成C#协议
|
||||
if (generateOperation.isGenerateCsharpProtocol()) {
|
||||
var generateLanguages = generateOperation.getGenerateLanguages();
|
||||
if (generateLanguages.contains(CodeLanguage.CSharp)) {
|
||||
GenerateCsUtils.init();
|
||||
GenerateCsUtils.createProtocolManager();
|
||||
allSortedGenerateProtocols.forEach(it -> GenerateCsUtils.createCsProtocolFile((ProtocolRegistration) it));
|
||||
}
|
||||
|
||||
// 生成Javascript协议
|
||||
if (generateOperation.isGenerateJsProtocol()) {
|
||||
if (generateLanguages.contains(CodeLanguage.JavaScript)) {
|
||||
GenerateJsUtils.init();
|
||||
allSortedGenerateProtocols.forEach(it -> GenerateJsUtils.createJsProtocolFile((ProtocolRegistration) it));
|
||||
GenerateJsUtils.createProtocolManager(allSortedGenerateProtocols);
|
||||
}
|
||||
|
||||
// 生成Lua协议
|
||||
if (generateOperation.isGenerateLuaProtocol()) {
|
||||
if (generateLanguages.contains(CodeLanguage.Lua)) {
|
||||
GenerateLuaUtils.init();
|
||||
GenerateLuaUtils.createProtocolManager(allSortedGenerateProtocols);
|
||||
allSortedGenerateProtocols.forEach(it -> GenerateLuaUtils.createLuaProtocolFile((ProtocolRegistration) it));
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.serializer;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @version 3.0
|
||||
*/
|
||||
public enum CodeLanguage {
|
||||
|
||||
JavaScript,
|
||||
|
||||
Lua,
|
||||
|
||||
CSharp;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user