Skip to content

Commit

Permalink
Merge branch 'master' of github.com:TarsCloud/TarsJava
Browse files Browse the repository at this point in the history
� Conflicts:
�	docs/tars-http-server.md
  • Loading branch information
TimmyYu committed Jul 6, 2020
2 parents f1acbde + 7aa3606 commit 1151817
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 169 deletions.
1 change: 1 addition & 0 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ If you contributed but cannot find your ID here, please submit PR and add your G
- walkertest
- woodwind
- XenoAmess
- yukkiball
69 changes: 0 additions & 69 deletions core/src/main/java/com/qq/tars/protocol/util/EncodingUtils.java

This file was deleted.

2 changes: 1 addition & 1 deletion docs-en/tars-http-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following configuration needs to be added in pom.xml:
<dependency>
<groupId>com.tencent.tars</groupId>
<artifactId>tars-spring-boot-starter</artifactId>
<version>1.7.2</version>
<version>1.7.0</version>
</dependency>
</dependencies>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public class Tars2JavaMojo extends AbstractMojo {

private AtomicInteger var = new AtomicInteger(0);

enum IsSetType {ISSET_NONE, ISSET_PRIMITIVE, ISSET_BITSET}

public void execute() throws MojoExecutionException, MojoFailureException {
// 1. check configurations
if (!tars2JavaConfig.packagePrefixName.endsWith(".")) {
Expand Down Expand Up @@ -291,27 +289,6 @@ private void genStruct(String dirPath, String packageName, String namespace, Tar
}
out.println();

// isset data
int optionals = 0;
for (TarsStructMember m : struct.memberList()) {
if (!typeCanBeNull(m.memberType(), nsMap)) {
out.println("\tprivate static final int __" + m.memberName().toUpperCase() + "_ISSET_ID = " + optionals + ";");
optionals++;
}
}
StringBuilder outprimitiveType = new StringBuilder("");
IsSetType isSetType = needIsSet(struct, outprimitiveType, nsMap);
switch (isSetType){
case ISSET_NONE:
break;
case ISSET_PRIMITIVE:
out.println("\tprivate " + outprimitiveType.toString() + " __isset_bitfield = 0;");
break;
case ISSET_BITSET:
out.println("\tprivate java.util.BitSet __isset_bit_vector = new java.util.BitSet(" + optionals + ");");
}
out.println();

// 生成 getter setter
for (TarsStructMember m : struct.memberList()) {
out.println("\tpublic " + type(m.memberType(), nsMap) + " " + fieldGetter(m.memberName(), m.memberType()) + "() {");
Expand All @@ -321,36 +298,6 @@ private void genStruct(String dirPath, String packageName, String namespace, Tar

out.println("\tpublic void " + fieldSetter(m.memberName(), m.memberType()) + "(" + type(m.memberType(), nsMap) + " " + m.memberName() + ") {");
out.println("\t\tthis." + m.memberName() + " = " + m.memberName() + ";");
if (!typeCanBeNull(m.memberType(), nsMap)) {
out.println("\t\tset" + firstUpStr(m.memberName()) + "IsSet(true);");
}
out.println("\t}");
out.println();

// isSet method
out.println("\t/** Returns true if field " + m.memberName() + " is set (has been assigned a value) and false otherwise */");
out.println("\tpublic boolean isSet" + firstUpStr(m.memberName()) + "() {");
if (typeCanBeNull(m.memberType(), nsMap)) {
out.println("\t\treturn this." + m.memberName() + " != null;");
} else if (isSetType == IsSetType.ISSET_PRIMITIVE) {
out.println("\t\treturn EncodingUtils.testBit(__isset_bitfield, __" + m.memberName().toUpperCase() + "_ISSET_ID);");
} else {
out.println("\t\treturn __isset_bit_vector.get(__" + m.memberName().toUpperCase() + "_ISSET_ID);");
}
out.println("\t}");
out.println();

// setFieldIsSet method
out.println("\tpublic void set" + firstUpStr(m.memberName()) + "IsSet(boolean value) {");
if (typeCanBeNull(m.memberType(), nsMap)) {
out.println("\t\tif (!value) {");
out.println("\t\t\tthis." + m.memberName() + " = null;");
out.println("\t\t}");
} else if (isSetType == IsSetType.ISSET_PRIMITIVE) {
out.println("\t\t__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __" + m.memberName().toUpperCase() + "_ISSET_ID, value);");
} else {
out.println("\t\t__isset_bit_vector.set(__" + m.memberName().toUpperCase() + "_ISSET_ID, value);");
}
out.println("\t}");
out.println();
}
Expand Down Expand Up @@ -451,40 +398,22 @@ private void genStruct(String dirPath, String packageName, String namespace, Tar
out.println("\t@Override");
out.println("\tpublic String toString() {");
out.println("\t\tStringBuilder sb = new StringBuilder(\"" + struct.structName() + "(\");");
out.println("\t\tboolean first = true;");
out.println();

boolean first = true;
for (TarsStructMember m : struct.memberList()) {
boolean couldBeUnSet = !m.isRequire();
if (couldBeUnSet){
out.println("\t\tif (isSet" + firstUpStr(m.memberName()) + "()) {");
}
if (!first) {
if (couldBeUnSet) out.print("\t");
out.println("\t\tif (!first) sb.append(\", \");");
out.println("\t\tsb.append(\", \");");
}
if (couldBeUnSet) out.print("\t");
out.println("\t\tsb.append(\"" + m.memberName() + ":\");");
boolean canBeNull = typeCanBeNull(m.memberType(), nsMap);
if (canBeNull) {
if (couldBeUnSet) out.print("\t");
out.println("\t\tif (this." + m.memberName() + " == null) {");
if (couldBeUnSet) out.print("\t");
out.println("\t\t\tsb.append(\"null\");");
if (couldBeUnSet) out.print("\t");
out.println("\t\t} else {");
out.print("\t");
}
if (couldBeUnSet) out.print("\t");
out.println("\t\tsb.append(this." + m.memberName() + ");");
if (canBeNull) {
if (couldBeUnSet) out.print("\t");
out.println("\t\t}");
}
if (couldBeUnSet) out.print("\t");
out.println("\t\tfirst = false;");
if (couldBeUnSet) {
out.println("\t\t}");
}
first = false;
Expand Down Expand Up @@ -862,33 +791,6 @@ private boolean typeCanBeNull(TarsType jt, Map<String, List<TarsNamespace>> nsMa
return canBeNull;
}

private IsSetType needIsSet(TarsStruct struct, StringBuilder outPrimitiveType, Map<String, List<TarsNamespace>> nsMap) {
int count = 0;
for (TarsStructMember m : struct.memberList()) {
if (!typeCanBeNull(m.memberType(), nsMap)) {
count++;
}
}
if (count == 0) {
return IsSetType.ISSET_NONE;
} else if (count <= 64){
if (outPrimitiveType != null) {
if (count <= 8) {
outPrimitiveType.append("byte");
} else if (count <= 16) {
outPrimitiveType.append("short");
} else if (count <= 32) {
outPrimitiveType.append("int");
} else if (count <= 64) {
outPrimitiveType.append("long");
}
}
return IsSetType.ISSET_PRIMITIVE;
} else {
return IsSetType.ISSET_BITSET;
}
}

private String typeInit(TarsType jt, Map<String, List<TarsNamespace>> nsMap, boolean useDefault) {
if (!useDefault) {
if (jt.isPrimitive()) {
Expand Down

0 comments on commit 1151817

Please sign in to comment.