This commit is contained in:
Redkale
2020-09-27 11:25:57 +08:00
parent 5d1805b10e
commit 95443be313
2 changed files with 14 additions and 0 deletions

View File

@@ -35,6 +35,8 @@ public final class EnMember<W extends Writer, T, F> {
protected int position; //从1开始
protected int tag; //主要给protobuf使用
public EnMember(Attribute<T, F> attribute, Encodeable<W, F> encoder) {
this.attribute = attribute;
this.encoder = encoder;
@@ -89,6 +91,10 @@ public final class EnMember<W extends Writer, T, F> {
return this.position;
}
public int getTag() {
return this.tag;
}
public int compareTo(boolean fieldSort, EnMember<W, T, F> o) {
if (o == null) return -1;
if (this.position != o.position) return (this.position == 0 ? Integer.MAX_VALUE : this.position) - (o.position == 0 ? Integer.MAX_VALUE : o.position);

View File

@@ -130,6 +130,7 @@ public class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T> {
while (pos.contains(++pidx));
member.position = pidx;
}
initForEachEnMember(factory, member);
}
Arrays.sort(this.members, (a, b) -> a.compareTo(factory.isFieldSort(), b));
@@ -144,6 +145,13 @@ public class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T> {
}
}
protected void initForEachEnMember(ConvertFactory factory, EnMember member) {
}
protected void setTag(EnMember member, int tag) {
member.tag = tag;
}
@Override
public void convertTo(W out, T value) {
if (value == null) {