mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-15 14:16:45 +00:00
perf[protobuf]: recreate get and set method
This commit is contained in:
1 parent
e76dd3ab81
commit
6624e5b053
6 files changed
+32
-158
No files matched your search
+14
-9
@@ -107,7 +107,8 @@ public class ProtoParser {
|
|||||||
ProtoValue pv = readValueUtilSemicolon();
|
ProtoValue pv = readValueUtilSemicolon();
|
||||||
String optionValue = pv.getValue();
|
String optionValue = pv.getValue();
|
||||||
Option option = new Option();
|
Option option = new Option();
|
||||||
option.setName(optionLabel).setValue(optionValue);
|
option.setName(optionLabel);
|
||||||
|
option.setValue(optionValue);
|
||||||
proto.addOption(option);
|
proto.addOption(option);
|
||||||
comments.clear();
|
comments.clear();
|
||||||
break;
|
break;
|
||||||
@@ -176,10 +177,10 @@ public class ProtoParser {
|
|||||||
notSupportInnerMessage();
|
notSupportInnerMessage();
|
||||||
} else if (Cardinality.cardinalityOf(token) != null) {
|
} else if (Cardinality.cardinalityOf(token) != null) {
|
||||||
PbField field = parseField(Cardinality.cardinalityOf(token), null);
|
PbField field = parseField(Cardinality.cardinalityOf(token), null);
|
||||||
msg.addField(field);
|
msg.getFields().add(field);
|
||||||
} else {
|
} else {
|
||||||
PbField field = parseField(Cardinality.OPTIONAL, token);
|
PbField field = parseField(Cardinality.OPTIONAL, token);
|
||||||
msg.addField(field);
|
msg.getFields().add(field);
|
||||||
}
|
}
|
||||||
boolean isEnd = blockEnd();
|
boolean isEnd = blockEnd();
|
||||||
if (isEnd) {
|
if (isEnd) {
|
||||||
@@ -405,14 +406,17 @@ public class ProtoParser {
|
|||||||
PbField field;
|
PbField field;
|
||||||
if (gType != null) {
|
if (gType != null) {
|
||||||
TypeProtobuf type = TypeProtobuf.valueOf(gType.getKeyType().toUpperCase(Locale.ENGLISH));
|
TypeProtobuf type = TypeProtobuf.valueOf(gType.getKeyType().toUpperCase(Locale.ENGLISH));
|
||||||
field = new MapField().setKey(type).setValue(gType.getValueType());
|
var mapField = new MapField();
|
||||||
|
mapField.setKey(type);
|
||||||
|
mapField.setValue(gType.getValueType());
|
||||||
|
field = mapField;
|
||||||
} else {
|
} else {
|
||||||
field = new PbField();
|
field = new PbField();
|
||||||
}
|
}
|
||||||
field.setCardinality(cardinality)
|
field.setCardinality(cardinality);
|
||||||
.setName(fieldName)
|
field.setName(fieldName);
|
||||||
.setTag(tag)
|
field.setTag(tag);
|
||||||
.setType(fieldType);
|
field.setType(fieldType);
|
||||||
field.getComments().addAll(comments);
|
field.getComments().addAll(comments);
|
||||||
comments.clear();
|
comments.clear();
|
||||||
return field;
|
return field;
|
||||||
@@ -798,7 +802,8 @@ public class ProtoParser {
|
|||||||
readValueSeparator('=');
|
readValueSeparator('=');
|
||||||
String value = readOptionValue();
|
String value = readOptionValue();
|
||||||
Option option = new Option();
|
Option option = new Option();
|
||||||
option.setName(name).setValue(value);
|
option.setName(name);
|
||||||
|
option.setValue(value);
|
||||||
options.add(option);
|
options.add(option);
|
||||||
trim();
|
trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,35 +23,19 @@ public class MapField extends PbField {
|
|||||||
private TypeProtobuf key;
|
private TypeProtobuf key;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the key
|
|
||||||
*/
|
|
||||||
public TypeProtobuf getKey() {
|
public TypeProtobuf getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setKey(TypeProtobuf key) {
|
||||||
* @param key the key to set
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public MapField setKey(TypeProtobuf key) {
|
|
||||||
this.key = key;
|
this.key = key;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the value
|
|
||||||
*/
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setValue(String value) {
|
||||||
* @param value the value to set
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public MapField setValue(String value) {
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,28 +27,19 @@ public class Option {
|
|||||||
*/
|
*/
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public Option setValue(String value) {
|
public String getName() {
|
||||||
this.value = value;
|
return name;
|
||||||
return this;
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Option setName(String name) {
|
public void setValue(String value) {
|
||||||
this.name = name;
|
this.value = value;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean getBoolean(String value) {
|
|
||||||
if (value == null || value.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return "true".equalsIgnoreCase(value) || "t".equalsIgnoreCase(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,84 +89,36 @@ public class PbField {
|
|||||||
private List<String> comments = new ArrayList<>();
|
private List<String> comments = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息属性的规则
|
|
||||||
*
|
|
||||||
* @return the cardinality
|
|
||||||
*/
|
|
||||||
public Cardinality getCardinality() {
|
public Cardinality getCardinality() {
|
||||||
return cardinality;
|
return cardinality;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setCardinality(Cardinality cardinality) {
|
||||||
* 消息属性的规则
|
|
||||||
*
|
|
||||||
* @param cardinality the cardinality to set
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public PbField setCardinality(Cardinality cardinality) {
|
|
||||||
this.cardinality = cardinality;
|
this.cardinality = cardinality;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息属性名称
|
|
||||||
*
|
|
||||||
* @return the name
|
|
||||||
*/
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setName(String name) {
|
||||||
* 消息属性名称
|
|
||||||
*
|
|
||||||
* @param name the name to set
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public PbField setName(String name) {
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息属性值的类型
|
|
||||||
*
|
|
||||||
* @return the type
|
|
||||||
*/
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setType(String type) {
|
||||||
* 消息属性值的类型
|
|
||||||
*
|
|
||||||
* @param type the type to set
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public PbField setType(String type) {
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 属性的顺序标记一个消息内不允许重复
|
|
||||||
*
|
|
||||||
* @return the tag
|
|
||||||
*/
|
|
||||||
public int getTag() {
|
public int getTag() {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setTag(int tag) {
|
||||||
* 属性的顺序标记一个消息内不允许重复
|
|
||||||
*
|
|
||||||
* @param tag the tag to set
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public PbField setTag(int tag) {
|
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getComments() {
|
public List<String> getComments() {
|
||||||
|
|||||||
+4
-52
@@ -37,77 +37,29 @@ public class ProtoMessage {
|
|||||||
*/
|
*/
|
||||||
private List<String> comments = new ArrayList<>();
|
private List<String> comments = new ArrayList<>();
|
||||||
|
|
||||||
public ProtoMessage addMessage(ProtoMessage child) {
|
|
||||||
if (child == null) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
getMessages().add(child);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProtoMessage addField(PbField field) {
|
|
||||||
if (field == null) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
getFields().add(field);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息的名称
|
|
||||||
*
|
|
||||||
* @return the name
|
|
||||||
*/
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setName(String name) {
|
||||||
* 消息的名称
|
|
||||||
*
|
|
||||||
* @param name the name to set
|
|
||||||
*/
|
|
||||||
public ProtoMessage setName(String name) {
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息包含的Fields列表
|
|
||||||
*
|
|
||||||
* @return the fields
|
|
||||||
*/
|
|
||||||
public List<PbField> getFields() {
|
public List<PbField> getFields() {
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setFields(List<PbField> fields) {
|
||||||
* 消息包含的Fields列表
|
|
||||||
*
|
|
||||||
* @param fields the fields to set
|
|
||||||
*/
|
|
||||||
public ProtoMessage setFields(List<PbField> fields) {
|
|
||||||
this.fields = fields;
|
this.fields = fields;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public List<ProtoMessage> getProtoMessages() {
|
||||||
* 消息内嵌的Message列表
|
|
||||||
*
|
|
||||||
* @return the messages
|
|
||||||
*/
|
|
||||||
public List<ProtoMessage> getMessages() {
|
|
||||||
return protoMessages;
|
return protoMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setProtoMessages(List<ProtoMessage> protoMessages) {
|
||||||
* 消息内嵌的Message列表
|
|
||||||
*
|
|
||||||
* @param protoMessages the messages to set
|
|
||||||
*/
|
|
||||||
public ProtoMessage setMessages(List<ProtoMessage> protoMessages) {
|
|
||||||
this.protoMessages = protoMessages;
|
this.protoMessages = protoMessages;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getComments() {
|
public List<String> getComments() {
|
||||||
|
|||||||
@@ -31,14 +31,4 @@ public enum Syntax {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Syntax fromValue(String value) {
|
|
||||||
switch (value) {
|
|
||||||
case "proto2":
|
|
||||||
return Syntax.PROTO_2;
|
|
||||||
case "proto3":
|
|
||||||
return Syntax.PROTO_3;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("no enum value Syntax " + value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user