mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-20 04:24:13 +00:00
ref[protobuf]: refactor protobuf generate
This commit is contained in:
@@ -77,7 +77,7 @@ public class GeneratePbUtils {
|
||||
if (options != null) {
|
||||
options.forEach(o -> protoOptions.put(o.getName(), o.getValue()));
|
||||
}
|
||||
if (CollectionUtils.isEmpty(proto.getMessages())) {
|
||||
if (CollectionUtils.isEmpty(proto.getPbMessages())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class GeneratePbUtils {
|
||||
|
||||
Map<String, String> msgComments = new HashMap<>();
|
||||
|
||||
List<PbMessage> msgs = proto.getMessages();
|
||||
List<PbMessage> msgs = proto.getPbMessages();
|
||||
for (var msg : msgs) {
|
||||
StringBuilder mc = new StringBuilder();
|
||||
if (CollectionUtils.isNotEmpty(msg.getComments())) {
|
||||
|
||||
@@ -55,105 +55,59 @@ public class Proto {
|
||||
*/
|
||||
private List<String> comments = new ArrayList<>();
|
||||
|
||||
public Proto setSyntax(Syntax syntax) {
|
||||
this.syntax = syntax;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Proto addOption(PbOption option) {
|
||||
getOptions().add(option);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Proto addImport(String value) {
|
||||
getImports().add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Proto addMsg(PbMessage msg) {
|
||||
getMessages().add(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proto描述文件的名称
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proto描述文件的名称
|
||||
*
|
||||
* @param name the name to set
|
||||
* @return
|
||||
*/
|
||||
public Proto setName(String name) {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proto的可选信息
|
||||
*
|
||||
* @return the options
|
||||
*/
|
||||
public List<PbOption> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档版本没有指定默认为proto2
|
||||
*
|
||||
* @return the syntax
|
||||
*/
|
||||
public void setOptions(List<PbOption> options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public Syntax getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
|
||||
/**
|
||||
* proto文件的包名
|
||||
*
|
||||
* @return the protoPackage
|
||||
*/
|
||||
public void setSyntax(Syntax syntax) {
|
||||
this.syntax = syntax;
|
||||
}
|
||||
|
||||
public String getProtoPackage() {
|
||||
return protoPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* proto文件的包名
|
||||
*
|
||||
* @param protoPackage the protoPackage to set
|
||||
* @return
|
||||
*/
|
||||
public Proto setProtoPackage(String protoPackage) {
|
||||
public void setProtoPackage(String protoPackage) {
|
||||
this.protoPackage = protoPackage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义的消息列表
|
||||
*
|
||||
* @return the messages
|
||||
*/
|
||||
public List<PbMessage> getMessages() {
|
||||
public List<PbMessage> getPbMessages() {
|
||||
return pbMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档导入的文件的路径列表
|
||||
*
|
||||
* @return the imports
|
||||
*/
|
||||
public void setPbMessages(List<PbMessage> pbMessages) {
|
||||
this.pbMessages = pbMessages;
|
||||
}
|
||||
|
||||
public List<String> getImports() {
|
||||
return imports;
|
||||
}
|
||||
|
||||
public void setImports(List<String> imports) {
|
||||
this.imports = imports;
|
||||
}
|
||||
|
||||
public List<String> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(List<String> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
}
|
||||
+6
-9
@@ -20,15 +20,12 @@ import com.zfoo.protocol.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* proto文件的解析器
|
||||
*
|
||||
* @date : 2019/12/2
|
||||
*/
|
||||
public class ProtoParser {
|
||||
|
||||
|
||||
/**
|
||||
* 需要解析的字符数组
|
||||
*/
|
||||
@@ -99,22 +96,22 @@ public class ProtoParser {
|
||||
readValueSeparator('=');
|
||||
ProtoValue pv = readValueUtilSemicolon();
|
||||
String optionValue = pv.getValue();
|
||||
PbOption option = new PbOption();
|
||||
option.setName(optionLabel);
|
||||
option.setValue(optionValue);
|
||||
proto.addOption(option);
|
||||
PbOption pbOption = new PbOption();
|
||||
pbOption.setName(optionLabel);
|
||||
pbOption.setValue(optionValue);
|
||||
proto.getOptions().add(pbOption);
|
||||
comments.clear();
|
||||
break;
|
||||
case "import":
|
||||
addCommentsToProto(proto);
|
||||
readValueSeparator(' ');
|
||||
ProtoValue impValue = readValueUtilSemicolon();
|
||||
proto.addImport(impValue.getValue());
|
||||
proto.getImports().add(impValue.getValue());
|
||||
comments.clear();
|
||||
break;
|
||||
case "message":
|
||||
PbMessage msg = parseMessage();
|
||||
proto.addMsg(msg);
|
||||
proto.getPbMessages().add(msg);
|
||||
comments.clear();
|
||||
break;
|
||||
case "enum":
|
||||
|
||||
Reference in New Issue
Block a user