diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/parser/ProtoParser.java b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/parser/ProtoParser.java index a3d5eadc..e271f5ca 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/parser/ProtoParser.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/parser/ProtoParser.java @@ -107,7 +107,8 @@ public class ProtoParser { ProtoValue pv = readValueUtilSemicolon(); String optionValue = pv.getValue(); Option option = new Option(); - option.setName(optionLabel).setValue(optionValue); + option.setName(optionLabel); + option.setValue(optionValue); proto.addOption(option); comments.clear(); break; @@ -176,10 +177,10 @@ public class ProtoParser { notSupportInnerMessage(); } else if (Cardinality.cardinalityOf(token) != null) { PbField field = parseField(Cardinality.cardinalityOf(token), null); - msg.addField(field); + msg.getFields().add(field); } else { PbField field = parseField(Cardinality.OPTIONAL, token); - msg.addField(field); + msg.getFields().add(field); } boolean isEnd = blockEnd(); if (isEnd) { @@ -405,14 +406,17 @@ public class ProtoParser { PbField field; if (gType != null) { 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 { field = new PbField(); } - field.setCardinality(cardinality) - .setName(fieldName) - .setTag(tag) - .setType(fieldType); + field.setCardinality(cardinality); + field.setName(fieldName); + field.setTag(tag); + field.setType(fieldType); field.getComments().addAll(comments); comments.clear(); return field; @@ -798,7 +802,8 @@ public class ProtoParser { readValueSeparator('='); String value = readOptionValue(); Option option = new Option(); - option.setName(name).setValue(value); + option.setName(name); + option.setValue(value); options.add(option); trim(); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/MapField.java b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/MapField.java index 0841dec2..7b93234e 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/MapField.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/MapField.java @@ -23,35 +23,19 @@ public class MapField extends PbField { private TypeProtobuf key; private String value; - /** - * @return the key - */ public TypeProtobuf getKey() { return key; } - /** - * @param key the key to set - * @return - */ - public MapField setKey(TypeProtobuf key) { + public void setKey(TypeProtobuf key) { this.key = key; - return this; } - /** - * @return the value - */ public String getValue() { return value; } - /** - * @param value the value to set - * @return - */ - public MapField setValue(String value) { + public void setValue(String value) { this.value = value; - return this; } } \ No newline at end of file diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/Option.java b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/Option.java index 3901a0e0..ec00e87e 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/Option.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/Option.java @@ -27,28 +27,19 @@ public class Option { */ private String value; - public Option setValue(String value) { - this.value = value; - return this; + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; } public String getValue() { return value; } - public Option setName(String name) { - this.name = name; - 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); + public void setValue(String value) { + this.value = value; } } \ No newline at end of file diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/PbField.java b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/PbField.java index 67efd1d1..6b80d8a2 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/PbField.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/PbField.java @@ -89,84 +89,36 @@ public class PbField { private List comments = new ArrayList<>(); - /** - * 消息属性的规则 - * - * @return the cardinality - */ public Cardinality getCardinality() { return cardinality; } - /** - * 消息属性的规则 - * - * @param cardinality the cardinality to set - * @return - */ - public PbField setCardinality(Cardinality cardinality) { + public void setCardinality(Cardinality cardinality) { this.cardinality = cardinality; - return this; } - /** - * 消息属性名称 - * - * @return the name - */ public String getName() { return name; } - /** - * 消息属性名称 - * - * @param name the name to set - * @return - */ - public PbField setName(String name) { + public void setName(String name) { this.name = name; - return this; } - /** - * 消息属性值的类型 - * - * @return the type - */ public String getType() { return type; } - /** - * 消息属性值的类型 - * - * @param type the type to set - * @return - */ - public PbField setType(String type) { + public void setType(String type) { this.type = type; - return this; } - /** - * 属性的顺序标记一个消息内不允许重复 - * - * @return the tag - */ public int getTag() { return tag; } - /** - * 属性的顺序标记一个消息内不允许重复 - * - * @param tag the tag to set - * @return - */ - public PbField setTag(int tag) { + public void setTag(int tag) { this.tag = tag; - return this; } public List getComments() { diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/ProtoMessage.java b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/ProtoMessage.java index c7c355ac..e7fb3e4f 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/ProtoMessage.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/ProtoMessage.java @@ -37,77 +37,29 @@ public class ProtoMessage { */ private List 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() { return name; } - /** - * 消息的名称 - * - * @param name the name to set - */ - public ProtoMessage setName(String name) { + public void setName(String name) { this.name = name; - return this; } - /** - * 消息包含的Fields列表 - * - * @return the fields - */ public List getFields() { return fields; } - /** - * 消息包含的Fields列表 - * - * @param fields the fields to set - */ - public ProtoMessage setFields(List fields) { + public void setFields(List fields) { this.fields = fields; - return this; } - /** - * 消息内嵌的Message列表 - * - * @return the messages - */ - public List getMessages() { + public List getProtoMessages() { return protoMessages; } - /** - * 消息内嵌的Message列表 - * - * @param protoMessages the messages to set - */ - public ProtoMessage setMessages(List protoMessages) { + public void setProtoMessages(List protoMessages) { this.protoMessages = protoMessages; - return this; } public List getComments() { diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/Syntax.java b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/Syntax.java index 853bfa7d..f270a6bc 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/Syntax.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/protobuf/wire/Syntax.java @@ -31,14 +31,4 @@ public enum Syntax { 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); - } - } } \ No newline at end of file