Skip to content

Commit

Permalink
chore[enhance]: compatible comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Oct 12, 2023
1 parent 7f90231 commit b6b6a6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions protocol/src/main/java/com/zfoo/protocol/anno/Compatible.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
@Target({ElementType.FIELD})
public @interface Compatible {

/**
* EN: new compatible field value must be always greater than old compatible field value
* CN: 新的兼容字段值必须始终大于旧的兼容字段
*/
int value();

}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public static IProtocolRegistration createProtocolRegistration(ProtocolRegistrat
private static String writeMethodBody(ProtocolRegistration registration) {
var constructor = registration.getConstructor();
var fields = registration.getFields();
var compatible = registration.isCompatible();
var fieldRegistrations = registration.getFieldRegistrations();

var packetClazz = constructor.getDeclaringClass();
Expand All @@ -185,7 +186,7 @@ private static String writeMethodBody(ProtocolRegistration registration) {
builder.append("{");
builder.append("if ($2 == null) { $1.writeByte(0); return; }");
builder.append(StringUtils.format("{} packet = ({})$2;", packetClazz.getName(), packetClazz.getName()));
if (registration.isCompatible()) {
if (compatible) {
builder.append("int beforeWriteIndex = $1.writerIndex();");
builder.append(StringUtils.format("{}.writeInt($1, {});", byteBufUtils, registration.getPredictionLength()));
} else {
Expand All @@ -203,7 +204,7 @@ private static String writeMethodBody(ProtocolRegistration registration) {
.writeObject(builder, StringUtils.format("packet.{}()", FieldUtils.fieldToGetMethod(packetClazz, field)), field, fieldRegistration);
}
}
if (registration.isCompatible()) {
if (compatible) {
builder.append(StringUtils.format("{}.adjustPadding($1, {}, beforeWriteIndex);", byteBufUtils, registration.getPredictionLength()));
}
builder.append("}");
Expand Down

0 comments on commit b6b6a6f

Please sign in to comment.