pb
This commit is contained in:
@@ -70,6 +70,12 @@ public class ProtobufArrayEncoder<T> extends ArrayEncoder<ProtobufWriter, T>
|
||||
}
|
||||
}
|
||||
|
||||
// 对象是否为空
|
||||
@Override
|
||||
public boolean isEmpty(ProtobufWriter out, T[] value) {
|
||||
return value == null || value.length == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeSize(ProtobufWriter out, int tagSize, T[] value) {
|
||||
if (value == null || value.length == 0) {
|
||||
|
||||
@@ -70,6 +70,12 @@ public class ProtobufCollectionEncoder<T> extends CollectionEncoder<ProtobufWrit
|
||||
}
|
||||
}
|
||||
|
||||
// 对象是否为空
|
||||
@Override
|
||||
public boolean isEmpty(ProtobufWriter out, Collection<T> value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeSize(ProtobufWriter out, int tagSize, Collection<T> value) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
|
||||
@@ -24,8 +24,11 @@ public interface ProtobufEncodeable<W extends Writer, T> extends Encodeable<W, T
|
||||
convertTo(out, value);
|
||||
}
|
||||
|
||||
// 对象是否为空
|
||||
default boolean isEmpty(W out, T value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 计算内容长度
|
||||
public int computeSize(ProtobufWriter out, int tagSize, T value);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -87,6 +87,12 @@ public class ProtobufMapEncoder<K, V> extends MapEncoder<ProtobufWriter, K, V>
|
||||
return (keyMember.getTagSize() + keySize) + (valueMember.getTagSize() + valSize);
|
||||
}
|
||||
|
||||
// 对象是否为空
|
||||
@Override
|
||||
public boolean isEmpty(ProtobufWriter out, Map<K, V> value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeSize(ProtobufWriter out, int tagSize, Map<K, V> value) {
|
||||
if (Utility.isEmpty(value)) {
|
||||
|
||||
@@ -71,6 +71,13 @@ public class ProtobufStreamEncoder<T> extends StreamEncoder<ProtobufWriter, T>
|
||||
}
|
||||
}
|
||||
|
||||
// 对象是否为空
|
||||
@Override
|
||||
public boolean isEmpty(ProtobufWriter out, Stream<T> value) {
|
||||
Object[] array = out.putStreamArray(value);
|
||||
return array == null || array.length == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeSize(ProtobufWriter out, int tagSize, Stream<T> value) {
|
||||
Object[] array = out.putStreamArray(value);
|
||||
|
||||
@@ -1065,6 +1065,9 @@ public abstract class ProtobufWriter extends Writer {
|
||||
return;
|
||||
}
|
||||
ProtobufEncodeable encoder = (ProtobufEncodeable) member.getEncoder();
|
||||
if (encoder.isEmpty(this, value)) {
|
||||
return;
|
||||
}
|
||||
this.writeField(member);
|
||||
encoder.convertTo(this, member, value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user